[FIX] mail_activity: state of activity is TZ dependent
Have your user and your system in timezone Sao Paolo When it is 2200 TZ time, UTC is the day after 0100 Have a activity schedule for today Before this commit the activity was flagged as overdue. This was because we compared the date deadline of the activity (no TZ) to the date.today() in Python While date do not have TZ legitimately, the moment (and place) you create them matters Thus, we compared the date of the server (UTC -- day +1) to a date set by the user (TZ -- day -1) After this commit we make up a date according to the user's tz And the activity is not overdue, but in state 'today' as it should OPW 1827920 closes #23969
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from datetime import date, datetime, timedelta
|
||||
import pytz
|
||||
|
||||
from odoo import api, exceptions, fields, models, _
|
||||
|
||||
@@ -108,8 +109,15 @@ class MailActivity(models.Model):
|
||||
|
||||
@api.depends('date_deadline')
|
||||
def _compute_state(self):
|
||||
today = date.today()
|
||||
today_default = date.today()
|
||||
|
||||
for record in self.filtered(lambda activity: activity.date_deadline):
|
||||
today = today_default
|
||||
if record.user_id.tz:
|
||||
today_utc = pytz.UTC.localize(datetime.utcnow())
|
||||
today_tz = today_utc.astimezone(pytz.timezone(record.user_id.tz))
|
||||
today = date(year=today_tz.year, month=today_tz.month, day=today_tz.day)
|
||||
|
||||
date_deadline = fields.Date.from_string(record.date_deadline)
|
||||
diff = (date_deadline - today)
|
||||
if diff.days == 0:
|
||||
|
||||
Reference in New Issue
Block a user