From cd773e79df35c5f29a229214cf8bec9c06b9857d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Tue, 12 Mar 2019 10:59:27 +0000 Subject: [PATCH] [FIX] website_sale: prevent crash if setting qty to 0 in cart update When there is an optional product for which the quantity is set to 0 because there is no stock available, the cart update would raise because it tried to read the order line even though it was deleted above. Now we apply the logic only if the order_line actually exists. Part of task 1950712 closes odoo/odoo#31779 Signed-off-by: Lucas Perais (lpe) --- addons/website_sale/models/sale_order.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/addons/website_sale/models/sale_order.py b/addons/website_sale/models/sale_order.py index 2c643736d21..4af60574419 100644 --- a/addons/website_sale/models/sale_order.py +++ b/addons/website_sale/models/sale_order.py @@ -280,14 +280,14 @@ class SaleOrder(models.Model): order_line.write(values) - # link a product to the sales order - if kwargs.get('linked_line_id'): - linked_line = SaleOrderLineSudo.browse(kwargs['linked_line_id']) - order_line.write({ - 'linked_line_id': linked_line.id, - 'name': order_line.name + "\n" + _("Option for:") + ' ' + linked_line.product_id.display_name, - }) - linked_line.write({"name": linked_line.name + "\n" + _("Option:") + ' ' + order_line.product_id.display_name}) + # link a product to the sales order + if kwargs.get('linked_line_id'): + linked_line = SaleOrderLineSudo.browse(kwargs['linked_line_id']) + order_line.write({ + 'linked_line_id': linked_line.id, + 'name': order_line.name + "\n" + _("Option for:") + ' ' + linked_line.product_id.display_name, + }) + linked_line.write({"name": linked_line.name + "\n" + _("Option:") + ' ' + order_line.product_id.display_name}) option_lines = self.order_line.filtered(lambda l: l.linked_line_id.id == order_line.id) for option_line_id in option_lines: