diff --git a/addons/product/i18n/product.pot b/addons/product/i18n/product.pot index c8c6136fcd8..6ca59acee1c 100644 --- a/addons/product/i18n/product.pot +++ b/addons/product/i18n/product.pot @@ -2815,17 +2815,18 @@ msgstr "" #: code:addons/product/models/product_attribute.py:0 #, python-format msgid "" -"You cannot delete the attribute %s because it is used on the following products:\n" -"%s" +"You cannot delete the attribute %(attribute)s because it is used on the following products:\n" +"%(products)s" msgstr "" #. module: product #. odoo-python -#: code:addons/product/models/product_attribute.py:0 +#: code:addons/product/models/product_attribute_value.py:0 #, python-format msgid "" -"You cannot delete the value %s because it is used on the following products:\n" -"%s" +"You cannot delete the value %(value)s because it is used on the following products:\n" +"%(products)s\n" +" If the value has been associated to a product in the past, you will not be able to delete it." msgstr "" #. module: product @@ -2847,6 +2848,13 @@ msgid "" "%s" msgstr "" +#. module: product +#. odoo-python +#: code:addons/product/models/product_attribute.py:0 +#, python-format +msgid "You cannot delete value %s because it was used in some products." +msgstr "" + #. module: product #. odoo-python #: code:addons/product/models/product_attribute.py:0 diff --git a/addons/product/models/product_attribute_value.py b/addons/product/models/product_attribute_value.py index e0b41f7ea97..b0a050a7ce9 100644 --- a/addons/product/models/product_attribute_value.py +++ b/addons/product/models/product_attribute_value.py @@ -93,10 +93,21 @@ class ProductAttributeValue(models.Model): for pav in self: if pav.is_used_on_products: raise UserError(_( - "You cannot delete the value %(value)s because it is used on the following products:\n%(products)s", + "You cannot delete the value %(value)s because it is used on the following " + "products:\n%(products)s\n If the value has been associated to a product in the" + " past, you will not be able to delete it.", value=pav.display_name, products=", ".join(pav.pav_attribute_line_ids.product_tmpl_id.mapped('display_name')), )) + linked_products = pav.env['product.template.attribute.value'].search( + [('product_attribute_value_id', '=', pav.id)] + ).with_context(active_test=False).ptav_product_variant_ids + unlinkable_products = linked_products._filter_to_unlink() + if linked_products != unlinkable_products: + raise UserError(_( + "You cannot delete value %s because it was used in some products.", + pav.display_name + )) def _without_no_variant_attributes(self): return self.filtered(lambda pav: pav.attribute_id.create_variant != 'no_variant')