Make product attribute name unique

The name of the attributes are the keys of the attributes Dict field of product
so they must be uniquely identified at least per sets.
But as an attribute can be reused on different sets, the unique constraint must
be set on the name.

Closes #13574
This commit is contained in:
Julio Alberto Bravo Montanos committed 2025-03-16 23:30:23 +01:00
1 parent 99603fd047
commit 22f151fbdc
2 files changed
+13 -1

No files matched your search

+3
View File
@@ -6,5 +6,8 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.message" id="msg_label_value">
<field name="text">%(label)s: %(value)s</field>
</record>
<record model="ir.message" id="msg_product_attribute_name_unique">
<field name="text">The name of the product attribute must be unique.</field>
</record>
</data>
</tryton>
+10 -1
View File
@@ -1,7 +1,7 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.i18n import gettext
from trytond.model import DictSchemaMixin, ModelSQL, ModelView, fields
from trytond.model import DictSchemaMixin, ModelSQL, ModelView, Unique, fields
from trytond.pool import PoolMeta
from trytond.pyson import Eval
@@ -21,6 +21,15 @@ class Attribute(DictSchemaMixin, ModelSQL, ModelView):
'attribute', 'attribute_set', 'Sets',
help="Add sets to the attribute.")
@classmethod
def __setup__(cls):
super().__setup__()
t = cls.__table__()
cls._sql_constraints += [
('name_unique', Unique(t, t.name),
'product_attribute.msg_product_attribute_name_unique'),
]
class AttributeAttributeSet(ModelSQL):
__name__ = 'product.attribute-product.attribute-set'