diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index 89b3a269d4c..102ba1ca109 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -522,8 +522,12 @@ class ProductTemplate(models.Model): if reference_product: # append the reference_product if provided product_template_attribute_values |= reference_product.product_template_attribute_value_ids - product_variants = self.product_variant_ids + if reference_product._context.get('no_variant_attribute_values'): + # Add "no_variant" attribute values' exclusions + # They are kept in the context since they are not linked to this product variant + product_template_attribute_values |= reference_product._context.get('no_variant_attribute_values') + product_variants = self.product_variant_ids for product_template_attribute_value in product_template_attribute_values: # CASE 1: The whole product is excluded when no attribute values are selected in the parent product # returns empty recordset of product.product if so. What is checked is: diff --git a/addons/sale/controllers/product_configurator.py b/addons/sale/controllers/product_configurator.py index d008362316a..b23e7ee9673 100644 --- a/addons/sale/controllers/product_configurator.py +++ b/addons/sale/controllers/product_configurator.py @@ -57,6 +57,11 @@ class ProductConfiguratorController(http.Controller): compute_currency = lambda price: from_currency._convert(price, to_currency, company, date) product = product.with_context(self._get_product_context(pricelist, **kw)) + no_variant_attribute_values = request.env['product.template.attribute.value'].browse(variant_values).filtered( + lambda product_template_attribute_value: product_template_attribute_value.attribute_id.create_variant == 'no_variant' + ) + if no_variant_attribute_values: + product = product.with_context(no_variant_attribute_values=no_variant_attribute_values) has_optional_products = False for optional_product in product.optional_product_ids: @@ -108,9 +113,15 @@ class ProductConfiguratorController(http.Controller): parent_exclusions = [] if reference_product: + parent_attribute_value_ids = reference_product.product_template_attribute_value_ids + if parent_attribute_value_ids and reference_product._context.get('no_variant_attribute_values'): + # Add "no_variant" attribute values' exclusions + # They are kept in the context since they are not linked to this product variant + parent_attribute_value_ids |= reference_product._context.get('no_variant_attribute_values') + parent_exclusions = [ value_id - for filter_line in reference_product.mapped('product_template_attribute_value_ids.exclude_for').filtered( + for filter_line in parent_attribute_value_ids.mapped('exclude_for').filtered( lambda filter_line: filter_line.product_tmpl_id == product ) for value_id in filter_line.value_ids.ids]