From a6f2dc07e5abded193a5f0808408314043e940f9 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 12 Jul 2017 09:28:02 +0200 Subject: [PATCH] [FIX] sale: traceback when choosing a product with warning as order.line If a user chooses a product that has a blocking error message, the product is set to False. This is good, but we do not want the following to happen: The other onchange triggers are called and "product_uom_change" generates an error because there is no product. (In fact it is "_compute_price_rule" on "product.pricelist" who raise) The onchange update the values of the other fields related to the product (eg for the "name" field where the name of the product that is canceled by the warning is assigned). --- addons/sale/models/sale.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index f73235bc361..d512037e445 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -878,6 +878,21 @@ class SaleOrderLine(models.Model): uom=self.product_uom.id ) + result = {'domain': domain} + + title = False + message = False + warning = {} + if product.sale_line_warn != 'no-message': + title = _("Warning for %s") % product.name + message = product.sale_line_warn_msg + warning['title'] = title + warning['message'] = message + result = {'warning': warning} + if product.sale_line_warn == 'block': + self.product_id = False + return result + name = product.name_get()[0][1] if product.description_sale: name += '\n' + product.description_sale @@ -889,22 +904,11 @@ class SaleOrderLine(models.Model): vals['price_unit'] = self.env['account.tax']._fix_tax_included_price(self._get_display_price(product), product.taxes_id, self.tax_id) self.update(vals) - title = False - message = False - warning = {} - if product.sale_line_warn != 'no-message': - title = _("Warning for %s") % product.name - message = product.sale_line_warn_msg - warning['title'] = title - warning['message'] = message - if product.sale_line_warn == 'block': - self.product_id = False - return {'warning': warning} - return {'domain': domain} + return result @api.onchange('product_uom', 'product_uom_qty') def product_uom_change(self): - if not self.product_uom: + if not self.product_uom or not self.product_id: self.price_unit = 0.0 return if self.order_id.pricelist_id and self.order_id.partner_id: