[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 <auon-odoo@users.noreply.github.com>
Signed-off-by: Kevin Baptiste <kba@odoo.com>
This commit is contained in:
Audric Onockx (auon)
2021-10-11 06:40:42 +00:00
parent bddb892817
commit c8a4e51b3d
+2 -5
View File
@@ -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)