From 00ab68201eb44d0c0a2ee889e1fdadfaa0701473 Mon Sep 17 00:00:00 2001 From: althaf shaik Date: Fri, 7 Jul 2023 12:43:39 +0000 Subject: [PATCH] [FIX] lunch: handle error of invalid time in lunch suppliers This traceback raises when user gives invalid time (hours) at the time of updating a record in lunch suppliers. To produce this issue: - Install 'Lunch' - Open Lunch/Configuration/Vendors - Open an existing record and in 'Orders' click 'Send Order By' as 'Email' - Give invalid time in 'Order Time' like -ve value or greater-than 12 - Save the record Error: 'A traceback appears': 'hour must be in 0..23' When user update a record 'write' method calls first than '_sql_constraints' and in that method '_sync_cron' method is used. Because of user giving invalid time it lead to above traceback. See: https://github.com/odoo/odoo/blob/88c1541a1646c419d37a9ca94a27f069844614db/addons/lunch/models/lunch_supplier.py#L186-L199 Sentry-4297889570 closes odoo/odoo#132143 X-original-commit: 99fb33167fb6bd332548f21c83d69fd9fe6b6c69 Signed-off-by: Sofie Gvaladze (sgv) Signed-off-by: Altaf Shaik (alsh) --- addons/lunch/models/lunch_supplier.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/lunch/models/lunch_supplier.py b/addons/lunch/models/lunch_supplier.py index 99fdc11b634..19c9b40a1e3 100644 --- a/addons/lunch/models/lunch_supplier.py +++ b/addons/lunch/models/lunch_supplier.py @@ -200,6 +200,9 @@ class LunchSupplier(models.Model): self.env['lunch.order'].search([('supplier_id', 'in', self.ids)]).write({'company_id': values['company_id']}) res = super().write(values) if not CRON_DEPENDS.isdisjoint(values): + # flush automatic_email_time field to call _sql_constraints + if 'automatic_email_time' in values: + self.flush_model(['automatic_email_time']) self._sync_cron() return res