diff --git a/addons/sale_management/models/sale_order_line.py b/addons/sale_management/models/sale_order_line.py index f7b29ba4f6a..ac16a272390 100644 --- a/addons/sale_management/models/sale_order_line.py +++ b/addons/sale_management/models/sale_order_line.py @@ -33,8 +33,12 @@ class SaleOrderLine(models.Model): def _compute_price_unit(self): # Avoid recomputing the price with pricelist rules, use the initial price # used in the optional product line. - optional_product_lines = self.filtered('sale_order_option_ids') - super(SaleOrderLine, self - optional_product_lines)._compute_price_unit() + lines_without_price_recomputation = self._lines_without_price_recomputation() + super(SaleOrderLine, self - lines_without_price_recomputation)._compute_price_unit() + + def _lines_without_price_recomputation(self): + """ Hook to allow filtering the lines to avoid the recomputation of the price. """ + return self.filtered('sale_order_option_ids') #=== TOOLING ===# diff --git a/addons/sale_management/models/sale_order_option.py b/addons/sale_management/models/sale_order_option.py index dd428ad3fd0..0447f931236 100644 --- a/addons/sale_management/models/sale_order_option.py +++ b/addons/sale_management/models/sale_order_option.py @@ -148,3 +148,5 @@ class SaleOrderOption(models.Model): self.write({'line_id': order_line.id}) if sale_order: sale_order.add_option_to_order_with_taxcloud() + + return order_line diff --git a/addons/sale_management/models/sale_order_template_line.py b/addons/sale_management/models/sale_order_template_line.py index 850532b4956..c318e74c9a9 100644 --- a/addons/sale_management/models/sale_order_template_line.py +++ b/addons/sale_management/models/sale_order_template_line.py @@ -36,7 +36,7 @@ class SaleOrderTemplateLine(models.Model): product_id = fields.Many2one( comodel_name='product.product', check_company=True, - domain="[('sale_ok', '=', True)]") + domain=lambda self: self._product_id_domain()) name = fields.Text( string="Description", @@ -92,6 +92,11 @@ class SaleOrderTemplateLine(models.Model): #=== BUSINESS METHODS ===# + @api.model + def _product_id_domain(self): + """ Returns the domain of the products that can be added to the template. """ + return [('sale_ok', '=', True)] + def _prepare_order_line_values(self): """ Give the values to create the corresponding order line. diff --git a/addons/sale_management/models/sale_order_template_option.py b/addons/sale_management/models/sale_order_template_option.py index 102ace459b0..ffc54180bb1 100644 --- a/addons/sale_management/models/sale_order_template_option.py +++ b/addons/sale_management/models/sale_order_template_option.py @@ -21,7 +21,7 @@ class SaleOrderTemplateOption(models.Model): product_id = fields.Many2one( comodel_name='product.product', required=True, check_company=True, - domain="[('sale_ok', '=', True)]") + domain=lambda self: self._product_id_domain()) name = fields.Text( string="Description", @@ -59,6 +59,11 @@ class SaleOrderTemplateOption(models.Model): #=== BUSINESS METHODS ===# + @api.model + def _product_id_domain(self): + """Returns the domain of the products that can be added as a template option.""" + return [('sale_ok', '=', True)] + def _prepare_option_line_values(self): """ Give the values to create the corresponding option line.