From 2b0d68bc41e91fa726258ee189b8aa8021e3a209 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Fri, 4 May 2018 01:11:42 +1100 Subject: [PATCH] [FIX] mail: activity in date tz but counts are not When creating an activity, the date saved will be the choosen one in the tought in the client timezone. But when displaying the counts of activities Late/Today/Future, the date is tought out as the one in the server timezone. Thus we would have activity today/future/late not corresponding with the date in the current timezone. This is solved in this change and follow what was done in 72254129. A second change is made so the default "Due date" is today in the timezone and not today in UTC date. opw-1837894 closes #24554 --- addons/mail/models/mail_activity.py | 2 +- addons/mail/models/res_users.py | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/addons/mail/models/mail_activity.py b/addons/mail/models/mail_activity.py index 42c44223a7c..921e06f7d47 100644 --- a/addons/mail/models/mail_activity.py +++ b/addons/mail/models/mail_activity.py @@ -78,7 +78,7 @@ class MailActivity(models.Model): summary = fields.Char('Summary') note = fields.Html('Note') feedback = fields.Html('Feedback') - date_deadline = fields.Date('Due Date', index=True, required=True, default=fields.Date.today) + date_deadline = fields.Date('Due Date', index=True, required=True, default=fields.Date.context_today) # description user_id = fields.Many2one( 'res.users', 'Assigned to', diff --git a/addons/mail/models/res_users.py b/addons/mail/models/res_users.py index 36acb6895bc..1709fa63488 100644 --- a/addons/mail/models/res_users.py +++ b/addons/mail/models/res_users.py @@ -129,16 +129,19 @@ class Users(models.Model): def activity_user_count(self): query = """SELECT m.id, count(*), act.res_model as model, CASE - WHEN now()::date - act.date_deadline::date = 0 Then 'today' - WHEN now()::date - act.date_deadline::date > 0 Then 'overdue' - WHEN now()::date - act.date_deadline::date < 0 Then 'planned' + WHEN %(today)s::date - act.date_deadline::date = 0 Then 'today' + WHEN %(today)s::date - act.date_deadline::date > 0 Then 'overdue' + WHEN %(today)s::date - act.date_deadline::date < 0 Then 'planned' END AS states FROM mail_activity AS act JOIN ir_model AS m ON act.res_model_id = m.id - WHERE user_id = %s + WHERE user_id = %(user_id)s GROUP BY m.id, states, act.res_model; """ - self.env.cr.execute(query, [self.env.uid]) + self.env.cr.execute(query, { + 'today': fields.Date.context_today(self), + 'user_id': self.env.uid, + }) activity_data = self.env.cr.dictfetchall() model_ids = [a['id'] for a in activity_data] model_names = {n[0]:n[1] for n in self.env['ir.model'].browse(model_ids).name_get()}