mirror of https://github.com/OCA/social.git
[IMP] mail_activity_done: black, isort
parent
e7f4d9db1d
commit
b26980b03c
|
@ -856,4 +856,4 @@ Public License instead of this License. But first, please read
|
||||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||||
|
|
||||||
|
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
|
|
|
@ -3,18 +3,12 @@
|
||||||
{
|
{
|
||||||
"name": "Mail Activity Done",
|
"name": "Mail Activity Done",
|
||||||
"version": "12.0.2.0.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",
|
||||||
"category": "Discuss",
|
"category": "Discuss",
|
||||||
"depends": [
|
"depends": ["mail"],
|
||||||
'mail',
|
"data": ["views/templates.xml", "views/mail_activity_views.xml"],
|
||||||
],
|
|
||||||
"data": [
|
|
||||||
'views/templates.xml',
|
|
||||||
'views/mail_activity_views.xml',
|
|
||||||
],
|
|
||||||
"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',
|
"uninstall_hook": "uninstall_hook",
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,27 @@
|
||||||
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
|
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
|
||||||
# Copyright 2018 Odoo, S.A.
|
# Copyright 2018 Odoo, S.A.
|
||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
# 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
|
from odoo import fields
|
||||||
|
|
||||||
|
from odoo.addons.mail.models.mail_activity import MailActivity
|
||||||
|
|
||||||
|
|
||||||
def pre_init_hook(cr):
|
def pre_init_hook(cr):
|
||||||
""" The objective of this hook is to default to false all values of field
|
""" The objective of this hook is to default to false all values of field
|
||||||
'done' of mail.activity
|
'done' of mail.activity
|
||||||
"""
|
"""
|
||||||
cr.execute("""SELECT column_name
|
cr.execute(
|
||||||
|
"""SELECT column_name
|
||||||
FROM information_schema.columns
|
FROM information_schema.columns
|
||||||
WHERE table_name='mail_activity' AND
|
WHERE table_name='mail_activity' AND
|
||||||
column_name='done'""")
|
column_name='done'"""
|
||||||
|
)
|
||||||
if not cr.fetchone():
|
if not cr.fetchone():
|
||||||
cr.execute(
|
cr.execute(
|
||||||
"""
|
"""
|
||||||
ALTER TABLE mail_activity ADD COLUMN done boolean;
|
ALTER TABLE mail_activity ADD COLUMN done boolean;
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
cr.execute(
|
cr.execute(
|
||||||
"""
|
"""
|
||||||
|
@ -28,12 +32,11 @@ def pre_init_hook(cr):
|
||||||
|
|
||||||
|
|
||||||
def post_load_hook():
|
def post_load_hook():
|
||||||
|
|
||||||
def new_action_feedback(self, feedback=False):
|
def new_action_feedback(self, feedback=False):
|
||||||
|
|
||||||
if 'done' not in self._fields:
|
if "done" not in self._fields:
|
||||||
return self.action_feedback_original(feedback=feedback)
|
return self.action_feedback_original(feedback=feedback)
|
||||||
message = self.env['mail.message']
|
message = self.env["mail.message"]
|
||||||
if feedback:
|
if feedback:
|
||||||
self.write(dict(feedback=feedback))
|
self.write(dict(feedback=feedback))
|
||||||
for activity in self:
|
for activity in self:
|
||||||
|
@ -42,15 +45,15 @@ def post_load_hook():
|
||||||
activity.active = False
|
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",
|
||||||
values={'activity': activity},
|
values={"activity": activity},
|
||||||
subtype_id=self.env.ref('mail.mt_activities').id,
|
subtype_id=self.env.ref("mail.mt_activities").id,
|
||||||
mail_activity_type_id=activity.activity_type_id.id,
|
mail_activity_type_id=activity.activity_type_id.id,
|
||||||
)
|
)
|
||||||
message |= record.message_ids[0]
|
message |= record.message_ids[0]
|
||||||
return message.ids and message.ids[0] or False
|
return message.ids and message.ids[0] or False
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,10 @@
|
||||||
def migrate(cr, version):
|
def migrate(cr, version):
|
||||||
if not version:
|
if not version:
|
||||||
return
|
return
|
||||||
cr.execute("""
|
cr.execute(
|
||||||
|
"""
|
||||||
UPDATE mail_activity SET
|
UPDATE mail_activity SET
|
||||||
active = False
|
active = False
|
||||||
WHERE done=True;
|
WHERE done=True;
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
|
@ -5,26 +5,23 @@ from odoo import api, fields, models
|
||||||
|
|
||||||
class MailActivity(models.Model):
|
class MailActivity(models.Model):
|
||||||
|
|
||||||
_inherit = 'mail.activity'
|
_inherit = "mail.activity"
|
||||||
|
|
||||||
active = fields.Boolean(default=True)
|
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')
|
date_done = fields.Date("Completed Date", index=True, readonly=True)
|
||||||
date_done = fields.Date(
|
|
||||||
'Completed Date', index=True, readonly=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
@api.depends('date_deadline', 'done')
|
@api.depends("date_deadline", "done")
|
||||||
def _compute_state(self):
|
def _compute_state(self):
|
||||||
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):
|
class MailActivityMixin(models.AbstractModel):
|
||||||
|
|
||||||
_inherit = 'mail.activity.mixin'
|
_inherit = "mail.activity.mixin"
|
||||||
activity_ids = fields.One2many(
|
activity_ids = fields.One2many(
|
||||||
domain=lambda self: [('res_model', '=', self._name),
|
domain=lambda self: [("res_model", "=", self._name), ("active", "=", True)]
|
||||||
('active', '=', True)])
|
)
|
||||||
|
|
|
@ -4,7 +4,7 @@ from odoo import api, fields, models, modules
|
||||||
|
|
||||||
|
|
||||||
class ResUsers(models.Model):
|
class ResUsers(models.Model):
|
||||||
_inherit = 'res.users'
|
_inherit = "res.users"
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def systray_get_activities(self):
|
def systray_get_activities(self):
|
||||||
|
@ -25,31 +25,34 @@ class ResUsers(models.Model):
|
||||||
AND act.done = False
|
AND act.done = False
|
||||||
GROUP BY m.id, states, act.res_model;
|
GROUP BY m.id, states, act.res_model;
|
||||||
"""
|
"""
|
||||||
self.env.cr.execute(query, {
|
self.env.cr.execute(
|
||||||
'today': fields.Date.context_today(self),
|
query, {"today": fields.Date.context_today(self), "user_id": self.env.uid}
|
||||||
'user_id': self.env.uid,
|
)
|
||||||
})
|
|
||||||
activity_data = self.env.cr.dictfetchall()
|
activity_data = self.env.cr.dictfetchall()
|
||||||
model_ids = [a['id'] for a in activity_data]
|
model_ids = [a["id"] for a in activity_data]
|
||||||
model_names = {n[0]: n[1] for n in self.env['ir.model'].browse(
|
model_names = {
|
||||||
model_ids).name_get()}
|
n[0]: n[1] for n in self.env["ir.model"].browse(model_ids).name_get()
|
||||||
|
}
|
||||||
|
|
||||||
user_activities = {}
|
user_activities = {}
|
||||||
for activity in activity_data:
|
for activity in activity_data:
|
||||||
if not user_activities.get(activity['model']):
|
if not user_activities.get(activity["model"]):
|
||||||
user_activities[activity['model']] = {
|
user_activities[activity["model"]] = {
|
||||||
'name': model_names[activity['id']],
|
"name": model_names[activity["id"]],
|
||||||
'model': activity['model'],
|
"model": activity["model"],
|
||||||
'icon': modules.module.get_module_icon(
|
"icon": modules.module.get_module_icon(
|
||||||
self.env[activity['model']]._original_module),
|
self.env[activity["model"]]._original_module
|
||||||
'total_count': 0, 'today_count': 0,
|
),
|
||||||
'overdue_count': 0, 'planned_count': 0,
|
"total_count": 0,
|
||||||
'type': 'activity',
|
"today_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"]
|
||||||
if activity['states'] in ('today', 'overdue'):
|
] += activity["count"]
|
||||||
user_activities[activity['model']][
|
if activity["states"] in ("today", "overdue"):
|
||||||
'total_count'] += activity['count']
|
user_activities[activity["model"]]["total_count"] += activity["count"]
|
||||||
|
|
||||||
return list(user_activities.values())
|
return list(user_activities.values())
|
||||||
|
|
|
@ -1,35 +1,41 @@
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from odoo.tests.common import TransactionCase
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
|
from odoo.tests.common import TransactionCase
|
||||||
|
|
||||||
|
|
||||||
class TestMailActivityDoneMethods(TransactionCase):
|
class TestMailActivityDoneMethods(TransactionCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestMailActivityDoneMethods, self).setUp()
|
super(TestMailActivityDoneMethods, self).setUp()
|
||||||
|
|
||||||
self.employee = self.env['res.users'].create({
|
self.employee = self.env["res.users"].create(
|
||||||
'company_id': self.env.ref("base.main_company").id,
|
{
|
||||||
'name': "Test User",
|
"company_id": self.env.ref("base.main_company").id,
|
||||||
'login': "testuser",
|
"name": "Test User",
|
||||||
'groups_id': [(6, 0, [self.env.ref('base.group_user').id])]
|
"login": "testuser",
|
||||||
})
|
"groups_id": [(6, 0, [self.env.ref("base.group_user").id])],
|
||||||
activity_type = self.env['mail.activity.type'].search(
|
}
|
||||||
[('name', '=', 'Meeting')], limit=1)
|
)
|
||||||
self.act1 = self.env['mail.activity'].create({
|
activity_type = self.env["mail.activity.type"].search(
|
||||||
'activity_type_id': activity_type.id,
|
[("name", "=", "Meeting")], limit=1
|
||||||
'res_id': self.env.ref("base.res_partner_1").id,
|
)
|
||||||
'res_model_id': self.env['ir.model']._get('res.partner').id,
|
self.act1 = self.env["mail.activity"].create(
|
||||||
'user_id': self.employee.id,
|
{
|
||||||
'date_deadline': date.today(),
|
"activity_type_id": activity_type.id,
|
||||||
})
|
"res_id": self.env.ref("base.res_partner_1").id,
|
||||||
|
"res_model_id": self.env["ir.model"]._get("res.partner").id,
|
||||||
|
"user_id": self.employee.id,
|
||||||
|
"date_deadline": date.today(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def test_mail_activity_done(self):
|
def test_mail_activity_done(self):
|
||||||
self.act1.done = True
|
self.act1.done = True
|
||||||
self.assertEquals(self.act1.state, 'done')
|
self.assertEquals(self.act1.state, "done")
|
||||||
|
|
||||||
def test_systray_get_activities(self):
|
def test_systray_get_activities(self):
|
||||||
act_count = self.employee.sudo(self.employee).systray_get_activities()
|
act_count = self.employee.sudo(self.employee).systray_get_activities()
|
||||||
self.assertEqual(len(act_count), 1,
|
self.assertEqual(
|
||||||
"Number of activities should be equal to one")
|
len(act_count), 1, "Number of activities should be equal to one"
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue