From c8a4e51b3d333da4aa58ec390b777b2f740086a9 Mon Sep 17 00:00:00 2001 From: "Audric Onockx (auon)" Date: Mon, 23 Aug 2021 08:57:47 +0000 Subject: [PATCH] [FIX] lunch: Fixed e-mail sent at wrong time Steps: - Set a supplier's 'Timezone' at a different timezone from utc. - Set 'Send Order By: Email' and set any 'Order Time'. Result: E-mail will be sent at wrong time. Explanation: According to pytz, using tzinfo arg in the standard datetime constructor "does not work" in combination with pytz. Yet lunch_supplier.float_to_time() calls time.replace() which calls this constructor. Solution: Don't allow lunch_supplier.float_to_time() to modify tzinfo and use pytz.localize() in _auto_email_send() to specify the right tzinfo. opw-2541132 closes odoo/odoo#78091 X-original-commit: 6b92fd80c4fc3471a4419369f0c6843fe18bad51 Signed-off-by: Audric Onockx Signed-off-by: Kevin Baptiste --- addons/lunch/models/lunch_supplier.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/addons/lunch/models/lunch_supplier.py b/addons/lunch/models/lunch_supplier.py index 57e2660ef18..7eabec19d5c 100644 --- a/addons/lunch/models/lunch_supplier.py +++ b/addons/lunch/models/lunch_supplier.py @@ -16,17 +16,14 @@ from odoo.addons.base.models.res_partner import _tz_get WEEKDAY_TO_NAME = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'] CRON_DEPENDS = {'name', 'active', 'send_by', 'automatic_email_time', 'moment', 'tz'} -def float_to_time(hours, moment='am', tz=None): +def float_to_time(hours, moment='am'): """ Convert a number of hours into a time object. """ if hours == 12.0 and moment == 'pm': return time.max fractional, integral = math.modf(hours) if moment == 'pm': integral += 12 - res = time(int(integral), int(float_round(60 * fractional, precision_digits=0)), 0) - if tz: - res = res.replace(tzinfo=pytz.timezone(tz)) - return res + return time(int(integral), int(float_round(60 * fractional, precision_digits=0)), 0) def time_to_float(t): return float_round(t.hour + t.minute/60 + t.second/3600, precision_digits=2)