From 35221a3243c9ae90cfb216a4b0fbbb7409a27712 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Thu, 28 Feb 2019 12:34:29 +0000 Subject: [PATCH] [FIX] product: exclude without attribute values With the demo data: - Go to Sale > Products > Products, search for 'Customizable Desk' - Click on 'Configure Variants' - For variant 'Legs: Steel', remove the attribute values for the 'Conference Chair' - Create a SO, add a line with 'Configure Product' - Select the 'Customizable Desk' with 'Legs: Steel', add The 'Conference Chair' is displayed in the 'Available Options', while it shouldn't. The methods `_get_own_attribute_exclusions` and `_get_parent_attribute_exclusions` compute the exclusions based on the attribute values. Since there is no values in our case, the exclusion is not taken into account. We add a specific case to search for exclusions without values. opw-1945460 --- addons/product/models/product_template.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index 429135b752f..f20e3da3dc5 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -730,6 +730,19 @@ class ProductTemplate(models.Model): self.ensure_one() if not parent_combination: return [] + + # Search for exclusions without attribute value. This means that the template is not + # compatible with the parent combination. If such an exclusion is found, it means that all + # attribute values are excluded. + if parent_combination: + exclusions = self.env['product.template.attribute.exclusion'].search([ + ('product_tmpl_id', '=', self.id), + ('value_ids', '=', False), + ('product_template_attribute_value_id', 'in', parent_combination.ids), + ], limit=1) + if exclusions: + return self.mapped('attribute_line_ids.product_template_value_ids').ids + return [ value_id for filter_line in parent_combination.mapped('exclude_for').filtered(