[IMP] sale_management: add hooks for template product domain and price
task-3076912 closes odoo/odoo#135811 Related: odoo/enterprise#47557 Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
@@ -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 ===#
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user