Browse Source

Merge pull request #380 from Eficent/12.0-fix-mail_activity_done

[12.0][FIX] mail_activity_done module
pull/342/merge
Jordi Ballester Alomar 6 years ago
committed by GitHub
parent
commit
5f39e514e2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      mail_activity_done/__init__.py
  2. 4
      mail_activity_done/__manifest__.py
  3. 13
      mail_activity_done/hooks.py
  4. 12
      mail_activity_done/migrations/12.0.2.0.0/post-migration.py
  5. 9
      mail_activity_done/models/mail_activity.py
  6. 1
      mail_activity_done/models/res_users.py
  7. 34
      mail_activity_done/views/mail_activity_views.xml

2
mail_activity_done/__init__.py

@ -1,2 +1,2 @@
from . import models from . import models
from .hooks import post_load_hook, pre_init_hook
from .hooks import post_load_hook, pre_init_hook, uninstall_hook

4
mail_activity_done/__manifest__.py

@ -2,7 +2,7 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
{ {
"name": "Mail Activity Done", "name": "Mail Activity Done",
"version": "12.0.1.1.0",
"version": "12.0.2.0.0",
"author": "Eficent," "author": "Eficent,"
"Odoo Community Association (OCA)", "Odoo Community Association (OCA)",
"license": "LGPL-3", "license": "LGPL-3",
@ -16,5 +16,5 @@
], ],
"pre_init_hook": "pre_init_hook", "pre_init_hook": "pre_init_hook",
"post_load": "post_load_hook", "post_load": "post_load_hook",
'uninstall_hook': 'uninstall_hook',
} }

13
mail_activity_done/hooks.py

@ -39,6 +39,7 @@ def post_load_hook():
for activity in self: for activity in self:
record = self.env[activity.res_model].browse(activity.res_id) record = self.env[activity.res_model].browse(activity.res_id)
activity.done = True activity.done = True
activity.active = False
activity.date_done = fields.Date.today() activity.date_done = fields.Date.today()
record.message_post_with_view( record.message_post_with_view(
'mail.message_activity_done', 'mail.message_activity_done',
@ -52,3 +53,15 @@ def post_load_hook():
if not hasattr(MailActivity, 'action_feedback_original'): if not hasattr(MailActivity, 'action_feedback_original'):
MailActivity.action_feedback_original = MailActivity.action_feedback MailActivity.action_feedback_original = MailActivity.action_feedback
MailActivity.action_feedback = new_action_feedback MailActivity.action_feedback = new_action_feedback
def uninstall_hook(cr, registry):
""" The objective of this hook is to remove all activities that are done
upon module uninstall
"""
cr.execute(
"""
DELETE FROM mail_activity
WHERE done=True
"""
)

12
mail_activity_done/migrations/12.0.2.0.0/post-migration.py

@ -0,0 +1,12 @@
# Copyright 2019 Eficent <http://www.eficent.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
def migrate(cr, version):
if not version:
return
cr.execute("""
UPDATE mail_activity SET
active = False
WHERE done=True;
""")

9
mail_activity_done/models/mail_activity.py

@ -7,6 +7,7 @@ class MailActivity(models.Model):
_inherit = 'mail.activity' _inherit = 'mail.activity'
active = fields.Boolean(default=True)
done = fields.Boolean(default=False) done = fields.Boolean(default=False)
state = fields.Selection(selection_add=[ state = fields.Selection(selection_add=[
('done', 'Done')], compute='_compute_state') ('done', 'Done')], compute='_compute_state')
@ -19,3 +20,11 @@ class MailActivity(models.Model):
super(MailActivity, self)._compute_state() super(MailActivity, self)._compute_state()
for record in self.filtered(lambda activity: activity.done): for record in self.filtered(lambda activity: activity.done):
record.state = 'done' record.state = 'done'
class MailActivityMixin(models.AbstractModel):
_inherit = 'mail.activity.mixin'
activity_ids = fields.One2many(
domain=lambda self: [('res_model', '=', self._name),
('active', '=', True)])

1
mail_activity_done/models/res_users.py

@ -44,6 +44,7 @@ class ResUsers(models.Model):
self.env[activity['model']]._original_module), self.env[activity['model']]._original_module),
'total_count': 0, 'today_count': 0, 'total_count': 0, 'today_count': 0,
'overdue_count': 0, 'planned_count': 0, 'overdue_count': 0, 'planned_count': 0,
'type': 'activity',
} }
user_activities[activity['model']][ user_activities[activity['model']][
'%s_count' % activity['states']] += activity['count'] '%s_count' % activity['states']] += activity['count']

34
mail_activity_done/views/mail_activity_views.xml

@ -27,19 +27,41 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="res_model_id" position="after"> <field name="res_model_id" position="after">
<field name="done"/> <field name="done"/>
<filter string="Open Activities" name="activities_open"
domain="[('done', '!=', True)]"/>
<field name="active"/>
<filter string="Completed Activities" name="activities_completed" <filter string="Completed Activities" name="activities_completed"
domain="[('done', '=', True)]"/>
domain="[('active', '=', False), ('state', '=', 'done')]"/>
</field>
<filter name="activities_overdue" position="attributes">
<attribute name="domain">[('date_deadline', '&lt;', context_today().strftime('%Y-%m-%d'))]</attribute>
</filter>
<filter name="activities_today" position="attributes">
<attribute name="domain">[('date_deadline', '=', context_today().strftime('%Y-%m-%d'))]</attribute>
</filter>
<filter name="activities_upcoming_all" position="attributes">
<attribute name="domain">[('date_deadline', '&gt;', context_today().strftime('%Y-%m-%d'))]</attribute>
</filter>
</field> </field>
</record>
<record id="res_partner_view_search_inherit_mail" model="ir.ui.view">
<field name="name">res.partner.view.search.inherit.mail</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="mail.res_partner_view_search_inherit_mail"/>
<field name="arch" type="xml">
<filter name="activities_my" position="after">
<filter string="Open Activities" name="activities_open"
domain="[('activity_ids.active', '=', True)]"/>
<filter string="Completed Activities" name="activities_completed"
domain="[('activity_ids.active', '=', False), ('activity_ids.state', '=', 'done')]"/>
</filter>
<filter name="activities_overdue" position="attributes"> <filter name="activities_overdue" position="attributes">
<attribute name="domain">[('date_deadline', '&lt;', context_today().strftime('%Y-%m-%d')), ('done', '!=', True)]</attribute>
<attribute name="domain">[('activity_ids.date_deadline', '&lt;', context_today().strftime('%Y-%m-%d'))]</attribute>
</filter> </filter>
<filter name="activities_today" position="attributes"> <filter name="activities_today" position="attributes">
<attribute name="domain">[('date_deadline', '=', context_today().strftime('%Y-%m-%d')), ('done', '!=', True)]</attribute>
<attribute name="domain">[('activity_ids.date_deadline', '=', context_today().strftime('%Y-%m-%d'))]</attribute>
</filter> </filter>
<filter name="activities_upcoming_all" position="attributes"> <filter name="activities_upcoming_all" position="attributes">
<attribute name="domain">[('date_deadline', '&gt;', context_today().strftime('%Y-%m-%d')), ('done', '!=', True)]</attribute>
<attribute name="domain">[('activity_ids.date_deadline', '&gt;', context_today().strftime('%Y-%m-%d'))]</attribute>
</filter> </filter>
</field> </field>
</record> </record>

Loading…
Cancel
Save