Add issue9004.diff # [product] Make product code unique
This commit is contained in:
parent
646b8d235a
commit
d6264fa294
|
@ -0,0 +1,48 @@
|
|||
diff --git a/trytond/trytond/modules/product/message.xml b/trytond/trytond/modules/product/message.xml
|
||||
index d77bc0e..d8b1f2f 100644
|
||||
--- a/trytond/trytond/modules/product/message.xml
|
||||
+++ b/trytond/trytond/modules/product/message.xml
|
||||
@@ -24,5 +24,8 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<record model="ir.message" id="msg_invalid_code">
|
||||
<field name="text">The %(type)s "%(code)s" for product "%(product)s" is not valid.</field>
|
||||
</record>
|
||||
+ <record model="ir.message" id="msg_product_code_unique">
|
||||
+ <field name="text">Code of active product must be unique.</field>
|
||||
+ </record>
|
||||
</data>
|
||||
</tryton>
|
||||
diff --git a/trytond/trytond/modules/product/product.py b/trytond/trytond/modules/product/product.py
|
||||
index 7207c02..559329e 100644
|
||||
--- a/trytond/trytond/modules/product/product.py
|
||||
+++ b/trytond/trytond/modules/product/product.py
|
||||
@@ -7,12 +7,13 @@ from importlib import import_module
|
||||
|
||||
import stdnum
|
||||
import stdnum.exceptions
|
||||
-from sql import Null, Column
|
||||
+from sql import Null, Column, Literal
|
||||
+from sql.operators import Equal
|
||||
|
||||
from trytond.i18n import gettext
|
||||
from trytond.model import (
|
||||
ModelView, ModelSQL, Model, UnionMixin, DeactivableMixin, sequence_ordered,
|
||||
- fields)
|
||||
+ Exclude, fields)
|
||||
from trytond.pyson import Eval
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pool import Pool
|
||||
@@ -238,6 +239,14 @@ class Product(
|
||||
|
||||
super(Product, cls).__setup__()
|
||||
|
||||
+ t = cls.__table__()
|
||||
+ cls._sql_constraints = [
|
||||
+ ('code_exclude', Exclude(t, (t.code, Equal),
|
||||
+ where=(t.active == Literal(True))
|
||||
+ & (t.code != '')),
|
||||
+ 'product.msg_product_code_unique'),
|
||||
+ ]
|
||||
+
|
||||
for attr in dir(Template):
|
||||
tfield = getattr(Template, attr)
|
||||
if not isinstance(tfield, fields.Field):
|
4
series
4
series
|
@ -111,4 +111,6 @@ issue10845.diff # [commission] Do not reverse commission when canceling invoice
|
|||
|
||||
project_work_company_rule.diff # [project] Add company rule at project level [#048280]
|
||||
|
||||
# worker_logger.diff #[trytond] Move exception handling into transaction to keep the database name
|
||||
issue9004.diff # [product] Make product code unique
|
||||
|
||||
# worker_logger.diff #[trytond] Move exception handling into transaction to keep the database name
|
||||
|
|
Loading…
Reference in New Issue