[FIX] lunch: fix traceback when we product add to cart

Description of the issue:
This commit addresses a traceback error that occurred when adding a product to
the cart with an empty cart. The issue was related to accessing values for
'topping_ids_1', 'topping_ids_2', and 'topping_ids_3' without proper validation

Fix:
In this fix i have added checks to ensure that the values are present before
accessing them this prevents an 'index out of range' error and resolves the
traceback problem, additionally, the code now considers the values in
'topping_1_values', 'topping_2_values', and 'topping_3_values' to determine
 whether to access the values or fall back to default values from the order.

Desired behavior after PR is merged:
traceback will fixed and work properly

task-3511953

closes odoo/odoo#135942

Signed-off-by: Sofie Gvaladze (sgv) <sgv@odoo.com>
This commit is contained in:
rajh-odoo
2023-09-29 16:08:46 +00:00
parent dd5e3b97f0
commit ed47260648
+9 -6
View File
@@ -86,16 +86,19 @@ class LunchOrder(models.Model):
"""
If called in api.multi then it will pop topping_ids_1,2,3 from values
"""
topping_1_values = values.get('topping_ids_1', False)
topping_2_values = values.get('topping_ids_2', False)
topping_3_values = values.get('topping_ids_3', False)
if self.ids:
# TODO This is not taking into account all the toppings for each individual order, this is usually not a problem
# since in the interface you usually don't update more than one order at a time but this is a bug nonetheless
topping_1 = values.pop('topping_ids_1')[0][2] if 'topping_ids_1' in values else self[:1].topping_ids_1.ids
topping_2 = values.pop('topping_ids_2')[0][2] if 'topping_ids_2' in values else self[:1].topping_ids_2.ids
topping_3 = values.pop('topping_ids_3')[0][2] if 'topping_ids_3' in values else self[:1].topping_ids_3.ids
topping_1 = values.pop('topping_ids_1')[0][2] if topping_1_values else self[:1].topping_ids_1.ids
topping_2 = values.pop('topping_ids_2')[0][2] if topping_2_values else self[:1].topping_ids_2.ids
topping_3 = values.pop('topping_ids_3')[0][2] if topping_3_values else self[:1].topping_ids_3.ids
else:
topping_1 = values['topping_ids_1'][0][2] if 'topping_ids_1' in values else []
topping_2 = values['topping_ids_2'][0][2] if 'topping_ids_2' in values else []
topping_3 = values['topping_ids_3'][0][2] if 'topping_ids_3' in values else []
topping_1 = values['topping_ids_1'][0][2] if topping_1_values else []
topping_2 = values['topping_ids_2'][0][2] if topping_2_values else []
topping_3 = values['topping_ids_3'][0][2] if topping_3_values else []
return topping_1 + topping_2 + topping_3