From d97e69ff0241af7403eef4a01f4dcf3f4e06963e Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 17 Aug 2018 01:49:22 +0200 Subject: [FIX] mail: schedule activity with user's today The activity was incorrectly scheduled with a deadline as the now in UTC while the state was computed using "today" in the user's timezone. This made the nightly test fail (run at 23:30 UTC with the user in UTC+2). Use context_today instead of today for all activity_schedule calls To make it easier, use on the context_today default value instead of setting context_today everywhere (which is more error prone in the future) Never use datetime, only date objects add a warning to detect potential errors when passing a datetime Closes #26411 --- addons/mail/models/mail_activity.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'addons/mail/models/mail_activity.py') diff --git a/addons/mail/models/mail_activity.py b/addons/mail/models/mail_activity.py index 6d7b94ad9a3..521caa9eb6b 100644 --- a/addons/mail/models/mail_activity.py +++ b/addons/mail/models/mail_activity.py @@ -4,12 +4,15 @@ from collections import defaultdict from datetime import date, datetime from dateutil.relativedelta import relativedelta +import logging import pytz from odoo import api, exceptions, fields, models, _ from odoo.tools import pycompat +_logger = logging.getLogger(__name__) + class MailActivityType(models.Model): """ Activity Types are used to categorize activities. Each type is a different @@ -579,12 +582,17 @@ class MailActivityMixin(models.AbstractModel): xml_id of activity type instead of directly giving an activity_type_id. It is useful to avoid having various "env.ref" in the code and allow to let the mixin handle access rights. + + :param date_deadline: the day the activity must be scheduled on + the timezone of the user must be considered to set the correct deadline """ if self.env.context.get('mail_activity_automation_skip'): return False if not date_deadline: - date_deadline = fields.Date.today() + date_deadline = fields.Date.context_today(self) + if isinstance(date_deadline, datetime): + _logger.warning("Scheduled deadline should be a date (got %s)", date_deadline) if act_type_xmlid: activity_type = self.sudo().env.ref(act_type_xmlid) else: -- cgit v1.2.3