diff options
| author | Christophe Simonis <chs@odoo.com> | 2018-11-16 19:30:20 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2018-11-16 19:30:20 +0100 |
| commit | 6faad524cf5e4db02855cb213277c40aee14c42a (patch) | |
| tree | 383c984dc1461a03481baa9fbdce8c156ca97e2e /addons/product/models/product.py | |
| parent | 3657dc77c2ddb4275f07d1271b93e7f25e09913a (diff) | |
| parent | bc744a1da46efda6f1eb5c341f2fa5df30c9c7ad (diff) | |
[MERGE] forward port branch 12.0 up to bc744a1da46
Diffstat (limited to 'addons/product/models/product.py')
| -rw-r--r-- | addons/product/models/product.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/addons/product/models/product.py b/addons/product/models/product.py index 0806370c998..b1b2340f16d 100644 --- a/addons/product/models/product.py +++ b/addons/product/models/product.py @@ -604,6 +604,22 @@ class ProductProduct(models.Model): return name + def _has_valid_attributes(self, valid_attributes, valid_values): + """ Check if a product has valid attributes. It is considered valid if: + - it uses ALL valid attributes + - it ONLY uses valid values + We must make sure that all attributes are used to take into account the case where + attributes would be added to the template. + + :param valid_attributes: a recordset of product.attribute + :param valid_values: a recordset of product.attribute.value + :return: True if the attibutes and values are correct, False instead + """ + self.ensure_one() + values = self.attribute_value_ids.filtered(lambda v: v.attribute_id.create_variant != 'no_variant') + attributes = values.mapped('attribute_id') + return attributes == valid_attributes and values <= valid_values + class ProductPackaging(models.Model): _name = "product.packaging" |
