Use Constraint instance in ModelSQL._sql_constraints

issue4814
review15491002
This commit is contained in:
Cédric Krier
2015-06-22 16:58:27 +02:00
parent 4937cf8ec8
commit 348e5ae06f
2 changed files with 6 additions and 4 deletions
+3 -2
View File
@@ -8,7 +8,7 @@ from dateutil import rrule
from itertools import groupby
from cached_property import cached_property
from trytond.model import Workflow, ModelSQL, ModelView, fields
from trytond.model import Workflow, ModelSQL, ModelView, fields, Unique
from trytond.pyson import Eval, Bool, If
from trytond.pool import Pool
from trytond.transaction import Transaction
@@ -170,8 +170,9 @@ class Asset(Workflow, ModelSQL, ModelView):
@classmethod
def __setup__(cls):
super(Asset, cls).__setup__()
table = cls.__table__()
cls._sql_constraints = [
('invoice_line_uniq', 'UNIQUE(supplier_invoice_line)',
('invoice_line_uniq', Unique(table, table.supplier_invoice_line),
'Supplier Invoice Line can be used only once on asset.'),
]
cls._error_messages.update({
+3 -2
View File
@@ -1,6 +1,6 @@
# 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.model import fields
from trytond.model import fields, Unique
from trytond.pyson import Eval
from trytond.pool import Pool, PoolMeta
@@ -27,8 +27,9 @@ class InvoiceLine:
@classmethod
def __setup__(cls):
super(InvoiceLine, cls).__setup__()
table = cls.__table__()
cls._sql_constraints += [
('asset_uniq', 'UNIQUE(asset)',
('asset_uniq', Unique(table, table.asset),
'Asset can be used only once on invoice line!'),
]