[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) <sgv@odoo.com>
Signed-off-by: Altaf Shaik (alsh) <alsh@odoo.com>
This commit is contained in:
althaf shaik
2023-08-17 09:21:16 +02:00
parent 2088384de6
commit 00ab68201e
+3
View File
@@ -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