Skip to content

Commit f25a9af

Browse files
committed
[FIX] project_todo: use user timezone for act states
User timezone was not being used for activity states and thus the future, today, and late activities would be inaccurate. They were being computed with CURRENT_DATE through SQL which is based on the timezone that the SQL server is in. This would lead to there being a period of some hours based on the user timezone where the actual activities page that you click into and the systray showing different counts of activity states. For example, on our Odoo production database, activities that SF office members create on projects that were for tomorrow would show today after 5pm and when clicking on the today activities there would be nothing until midnight. Using the user timezone in order to compute what today is for them, then using this in the SQL query fixes this issue. This is the same behavior as the compute_state for the state field in mail.activity. opw-4893182 closes odoo#219752 X-original-commit: 65bce5b Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com> Signed-off-by: Ryan Cen (ryce) <ryce@odoo.com>
1 parent fb11a9e commit f25a9af

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

addons/project_todo/models/res_users.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import json
55

6-
from odoo import _, api, models, modules
6+
from odoo import _, api, fields, models, modules
77

88

99
class ResUsers(models.Model):
@@ -24,16 +24,17 @@ def _get_activity_groups(self):
2424
# 2. creating groups for todo and task seperately
2525
query = """SELECT BOOL(t.project_id) as is_task, count(*), act.res_model, act.res_id,
2626
CASE
27-
WHEN CURRENT_DATE - act.date_deadline::date = 0 THEN 'today'
28-
WHEN CURRENT_DATE - act.date_deadline::date > 0 THEN 'overdue'
29-
WHEN CURRENT_DATE - act.date_deadline::date < 0 THEN 'planned'
27+
WHEN %(date)s - act.date_deadline::date = 0 THEN 'today'
28+
WHEN %(date)s - act.date_deadline::date > 0 THEN 'overdue'
29+
WHEN %(date)s - act.date_deadline::date < 0 THEN 'planned'
3030
END AS states
3131
FROM mail_activity AS act
3232
JOIN project_task AS t ON act.res_id = t.id
3333
WHERE act.res_model = 'project.task' AND act.user_id = %(user_id)s AND act.active in (TRUE, %(active)s)
3434
GROUP BY is_task, states, act.res_model, act.res_id
3535
"""
3636
self.env.cr.execute(query, {
37+
'date': str(fields.Date.context_today(self)),
3738
'user_id': self.env.uid,
3839
'active': self._context.get('active_test', True),
3940
})

0 commit comments

Comments
 (0)