Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.0][MIG] mail_activity_done #354

Merged
merged 2 commits into from
Mar 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
859 changes: 859 additions & 0 deletions mail_activity_done/LICENSE

Large diffs are not rendered by default.

76 changes: 76 additions & 0 deletions mail_activity_done/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
==================
Mail Activity Done
==================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github
:target: https://github.com/OCA/social/tree/12.0/mail_activity_done
:alt: OCA/social
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/social-12-0/social-12-0-mail_activity_done
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/205/12.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This module implements the capability to keep activities that have been
completed, for future reporting, by setting them with the boolean 'Done'.

The activities that have been completed will not appear in the chatter.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/social/issues/new?body=module:%20mail_activity_done%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Eficent

Contributors
~~~~~~~~~~~~

* Jordi Ballester <jordi.ballester@eficent.com> (www.eficent.com)

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/social <https://github.com/OCA/social/tree/12.0/mail_activity_done>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions mail_activity_done/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import post_load_hook, pre_init_hook
20 changes: 20 additions & 0 deletions mail_activity_done/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2018 Eficent <http://www.eficent.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
{
"name": "Mail Activity Done",
"version": "12.0.1.0.0",
"author": "Eficent,"
"Odoo Community Association (OCA)",
"license": "LGPL-3",
"category": "Discuss",
"depends": [
'mail',
],
"data": [
'views/templates.xml',
'views/mail_activity_views.xml',
],
"pre_init_hook": "pre_init_hook",
"post_load": "post_load_hook",

}
54 changes: 54 additions & 0 deletions mail_activity_done/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
# Copyright 2018 Odoo, S.A.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo.addons.mail.models.mail_activity import MailActivity
from odoo import fields


def pre_init_hook(cr):
""" The objective of this hook is to default to false all values of field
'done' of mail.activity
"""
cr.execute("""SELECT column_name
FROM information_schema.columns
WHERE table_name='mail_activity' AND
column_name='done'""")
if not cr.fetchone():
cr.execute(
"""
ALTER TABLE mail_activity ADD COLUMN done boolean;
""")

cr.execute(
"""
UPDATE mail_activity
SET done = False
"""
)


def post_load_hook():

def new_action_feedback(self, feedback=False):

if 'done' not in self._fields:
return self.action_feedback_original(feedback=feedback)
message = self.env['mail.message']
if feedback:
self.write(dict(feedback=feedback))
for activity in self:
record = self.env[activity.res_model].browse(activity.res_id)
activity.done = True
activity.date_done = fields.Date.today()
record.message_post_with_view(
'mail.message_activity_done',
values={'activity': activity},
subtype_id=self.env.ref('mail.mt_activities').id,
mail_activity_type_id=activity.activity_type_id.id,
)
message |= record.message_ids[0]
return message.ids and message.ids[0] or False

if not hasattr(MailActivity, 'action_feedback_original'):
MailActivity.action_feedback_original = MailActivity.action_feedback
MailActivity.action_feedback = new_action_feedback
2 changes: 2 additions & 0 deletions mail_activity_done/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import mail_activity
from . import res_users
21 changes: 21 additions & 0 deletions mail_activity_done/models/mail_activity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2018 Eficent <http://www.eficent.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo import api, fields, models


class MailActivity(models.Model):

_inherit = 'mail.activity'

done = fields.Boolean(default=False)
state = fields.Selection(selection_add=[
('done', 'Done')], compute='_compute_state')
date_done = fields.Date(
'Completed Date', index=True, readonly=True,
)

@api.depends('done')
def _compute_state(self):
super(MailActivity, self)._compute_state()
for record in self.filtered(lambda activity: activity.done):
record.state = 'done'
54 changes: 54 additions & 0 deletions mail_activity_done/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright 2018 Eficent <http://www.eficent.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo import api, fields, models, modules


class ResUsers(models.Model):
_inherit = 'res.users'

@api.model
def activity_user_count(self):
# Here we totally override the method. Not very nice, but
# we should perhaps ask Odoo to add a hook here.
query = """SELECT m.id, count(*), act.res_model as model,
CASE
WHEN %(today)s::date -
act.date_deadline::date = 0 Then 'today'
WHEN %(today)s::date -
act.date_deadline::date > 0 Then 'overdue'
WHEN %(today)s::date -
act.date_deadline::date < 0 Then 'planned'
END AS states
FROM mail_activity AS act
JOIN ir_model AS m ON act.res_model_id = m.id
WHERE user_id = %(user_id)s
AND act.done = False
GROUP BY m.id, states, act.res_model;
"""
self.env.cr.execute(query, {
'today': fields.Date.context_today(self),
'user_id': self.env.uid,
})
activity_data = self.env.cr.dictfetchall()
model_ids = [a['id'] for a in activity_data]
model_names = {n[0]: n[1] for n in self.env['ir.model'].browse(
model_ids).name_get()}

user_activities = {}
for activity in activity_data:
if not user_activities.get(activity['model']):
user_activities[activity['model']] = {
'name': model_names[activity['id']],
'model': activity['model'],
'icon': modules.module.get_module_icon(
self.env[activity['model']]._original_module),
'total_count': 0, 'today_count': 0,
'overdue_count': 0, 'planned_count': 0,
}
user_activities[activity['model']][
'%s_count' % activity['states']] += activity['count']
if activity['states'] in ('today', 'overdue'):
user_activities[activity['model']][
'total_count'] += activity['count']

return list(user_activities.values())
1 change: 1 addition & 0 deletions mail_activity_done/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Jordi Ballester <jordi.ballester@eficent.com> (www.eficent.com)
4 changes: 4 additions & 0 deletions mail_activity_done/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This module implements the capability to keep activities that have been
completed, for future reporting, by setting them with the boolean 'Done'.

The activities that have been completed will not appear in the chatter.
Empty file.
Binary file added mail_activity_done/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading