From 3b256ba487df8ed3ef28eddec25af75ce3be4677 Mon Sep 17 00:00:00 2001 From: Nans Lefebvre Date: Tue, 12 Feb 2019 15:53:53 +0000 Subject: [PATCH] [FIX] sale_margin: make sale.order.line create override handle section lines The sale.order.line model has a 'display_type' field since 762adedece1c6c2b97b2 that specify if the line is a dummy line used for presentation purposes. These dummy lines are 'section' lines or 'note' lines. If it is the case, the line does not have a product_id. The sale_margin module overrides the create method of lines to add the margin computation, assuming there are no dummy lines since that part of the code is older than the new feature. As a result the line creation would crash on a key error on dummy lines. We now skip the margin computation if the line has a display_type. opw 1939881 closes odoo/odoo#31035 --- addons/sale_margin/models/sale_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sale_margin/models/sale_order.py b/addons/sale_margin/models/sale_order.py index 866890ff822..fb79fd5f976 100644 --- a/addons/sale_margin/models/sale_order.py +++ b/addons/sale_margin/models/sale_order.py @@ -46,7 +46,7 @@ class SaleOrderLine(models.Model): # Calculation of the margin for programmatic creation of a SO line. It is therefore not # necessary to call product_id_change_margin manually - if 'purchase_price' not in vals: + if 'purchase_price' not in vals and ('display_type' not in vals or not vals['display_type']): order_id = self.env['sale.order'].browse(vals['order_id']) product_id = self.env['product.product'].browse(vals['product_id']) product_uom_id = self.env['uom.uom'].browse(vals['product_uom'])