Skip to content

Commit

Permalink
[FIX]mail_activity_done: Remove systray_get_activities override.
Browse files Browse the repository at this point in the history
In odoo 16 the systray_get_activities function uses the ORM, there is no need to override it.

Also fixes the activity count in kanban views.
  • Loading branch information
jesusVMayor committed Feb 13, 2025
1 parent 8b76bf4 commit 4da6a2e
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 85 deletions.
3 changes: 3 additions & 0 deletions mail_activity_done/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
"data": ["views/mail_activity_views.xml"],
"pre_init_hook": "pre_init_hook",
"uninstall_hook": "uninstall_hook",
"demo": [
"demo/mail_activity.xml",
],
}
14 changes: 14 additions & 0 deletions mail_activity_done/demo/mail_activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="activity_done_1" model="mail.activity">
<field name="activity_type_id" ref="mail.mail_activity_data_meeting" />
<field name="res_id" ref="base.res_partner_2" />
<field name="res_model">res.partner</field>
<field name="res_model_id" ref="base.model_res_partner" />
<field name="user_id" ref="base.user_demo" />
<field name="date_deadline">2024-01-01</field>
<field name="date_done">2024-01-01</field>
<field name="done" eval="True" />
<field name="active" eval="False" />
</record>
</odoo>
1 change: 0 additions & 1 deletion mail_activity_done/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from . import mail_activity
from . import res_users
44 changes: 40 additions & 4 deletions mail_activity_done/models/mail_activity.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# 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

delete_sentinel = object()

Expand Down Expand Up @@ -88,7 +87,44 @@ class MailActivityMixin(models.AbstractModel):
def _read_progress_bar(self, domain, group_by, progress_bar):
"""
Exclude completed activities from progress bar result.
Pass an extra domain to super to filter out records with only done activities.
"""
domain = expression.AND([domain, [("activity_ids.done", "=", False)]])
return super()._read_progress_bar(domain, group_by, progress_bar)
execute_org = self._cr.execute

def execute(query, params=None, log_exceptions=True):
original_where = "WHERE res_model = '{}'".format(self._name)
replace_where = (
"WHERE res_model = '{}' AND mail_activity.done = FALSE".format(
self._name
)
)
return execute_org(
query.replace(original_where, replace_where),
params=params,
log_exceptions=log_exceptions,
)

self._cr.execute = execute
try:
return super()._read_progress_bar(domain, group_by, progress_bar)
finally:
self._cr.execute = execute_org

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
59 changes: 0 additions & 59 deletions mail_activity_done/models/res_users.py

This file was deleted.

11 changes: 7 additions & 4 deletions mail_activity_done/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -426,7 +427,9 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>
Expand Down
30 changes: 13 additions & 17 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,7 +17,7 @@ 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(),
}
)
Expand All @@ -37,22 +28,27 @@ 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"
)

def test_read_progress_bar(self):
res_partner = self.env["res.partner"].browse(self.act1.res_model_id)
res_partner = self.env["res.partner"].browse(self.act1.res_id)
params = {
"domain": [],
"group_by": "id",
"progress_bar": {"field": "activity_state"},
}
result = res_partner._read_progress_bar(**params)
self.assertEqual(result[0]["__count"], 1)
self.assertEqual(len(result), 1)

self.act1._action_done()
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)
overdue_activities = self.env["res.partner"].search(
[("activity_state", "=", "overdue")]
)
self.assertEqual(len(overdue_activities), 0)

0 comments on commit 4da6a2e

Please sign in to comment.