[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
This commit is contained in:
Nicolas Lempereur
2018-05-05 00:38:35 +13:00
parent c3ddef161e
commit 2b0d68bc41
2 changed files with 9 additions and 6 deletions
+1 -1
View File
@@ -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',
+8 -5
View File
@@ -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()}