[FIX] product: Improved error message for pav deletion

What are the steps to reproduce your issue?
- Create a product with more than one attribute.
- Let say color White, black and purple
- Create a 'draft' invoice for the purple product variant
- Remove the 'purple' attribute value from the product
- It will archive that variant (because the account.move linked to it)
- Try to delete the attribute value from menu Sales > Cofinfiguration > Attribute

What is the current behavior that you observe?
- technical error message

What would be your expected behavior in this case?
- non-technical message for end-users

Solution :
- Change both message to tell user he cannot delete the value if the value has been referenced somewhere else.
opw-2623583

missing forward-port of db1e52f0234f73e1bda22a411baba7b1f0994d5a

closes odoo/odoo#120495

X-original-commit: 0c8c43d50a574d73d9d5ac925eb16faf730a76ba
Signed-off-by: Morgane Demesmaeker <edm@odoo.com>
This commit is contained in:
Damhaut Florian (flda)
2023-05-04 12:15:21 +02:00
committed by Demesmaeker
parent 91a276058c
commit cee32aa16e
2 changed files with 25 additions and 6 deletions
+13 -5
View File
@@ -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
@@ -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')