Skip to content

Commit

Permalink
[FIX]mail_activity_done: Fix activity_state search.
Browse files Browse the repository at this point in the history
  • Loading branch information
jesusVMayor committed Nov 22, 2024
1 parent f00dd76 commit 9ab7f24
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
22 changes: 22 additions & 0 deletions mail_activity_done/models/mail_activity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Copyright 2018-22 ForgeFlow <http://www.forgeflow.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).


from odoo import api, fields, models
from odoo.osv import expression

Expand Down Expand Up @@ -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
30 changes: 19 additions & 11 deletions mail_activity_done/tests/test_mail_activity_done.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -26,18 +17,29 @@ 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()
self.assertTrue(self.act1.exists())
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"
)
Expand All @@ -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)

0 comments on commit 9ab7f24

Please sign in to comment.