diff --git a/mail_activity_done/models/mail_activity.py b/mail_activity_done/models/mail_activity.py index 5730f40e79..a1dc30acda 100644 --- a/mail_activity_done/models/mail_activity.py +++ b/mail_activity_done/models/mail_activity.py @@ -1,5 +1,7 @@ # Copyright 2018-22 ForgeFlow # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + + from odoo import api, fields, models from odoo.osv import expression @@ -92,3 +94,23 @@ def _read_progress_bar(self, domain, group_by, progress_bar): """ domain = expression.AND([domain, [("activity_ids.done", "=", False)]]) return super()._read_progress_bar(domain, group_by, progress_bar) + + def _search_activity_state(self, operator, value): + execute_org = self._cr.execute + + def execute(query, params=None, log_exceptions=True): + return execute_org( + query.replace( + "WHERE mail_activity.res_model = %(res_model_table)s", + "WHERE mail_activity.res_model = %(res_model_table)s AND " + "mail_activity.done = FALSE", + ), + params=params, + log_exceptions=log_exceptions, + ) + + self._cr.execute = execute + try: + return super()._search_activity_state(operator, value) + finally: + self._cr.execute = execute_org diff --git a/mail_activity_done/tests/test_mail_activity_done.py b/mail_activity_done/tests/test_mail_activity_done.py index f481de3ec8..02f5375daa 100644 --- a/mail_activity_done/tests/test_mail_activity_done.py +++ b/mail_activity_done/tests/test_mail_activity_done.py @@ -8,15 +8,6 @@ class TestMailActivityDoneMethods(TransactionCase): def setUp(self): super(TestMailActivityDoneMethods, self).setUp() - - self.employee = self.env["res.users"].create( - { - "company_id": self.env.ref("base.main_company").id, - "name": "Test User", - "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 ) @@ -26,10 +17,21 @@ def setUp(self): "res_id": self.env.ref("base.res_partner_1").id, "res_model": "res.partner", "res_model_id": self.env["ir.model"]._get("res.partner").id, - "user_id": self.employee.id, + "user_id": self.env.user.id, + "date_deadline": date.today(), + } + ) + self.act2 = self.env["mail.activity"].create( + { + "activity_type_id": activity_type.id, + "res_id": self.env.ref("base.res_partner_1").id, + "res_model": "res.partner", + "res_model_id": self.env["ir.model"]._get("res.partner").id, + "user_id": self.env.user.id, "date_deadline": date.today(), } ) + self.act2._action_done() def test_mail_activity_done(self): self.act1._action_done() @@ -37,7 +39,7 @@ def test_mail_activity_done(self): self.assertEqual(self.act1.state, "done") def test_systray_get_activities(self): - act_count = self.employee.with_user(self.employee).systray_get_activities() + act_count = self.env.user.systray_get_activities() self.assertEqual( len(act_count), 1, "Number of activities should be equal to one" ) @@ -56,3 +58,9 @@ def test_read_progress_bar(self): self.assertEqual(self.act1.state, "done") result = res_partner._read_progress_bar(**params) self.assertEqual(len(result), 0) + + def test_activity_state_search(self): + today_activities = self.env["res.partner"].search( + [("activity_state", "=", "today")] + ) + self.assertEqual(len(today_activities), 1)