Use Constraint instance in ModelSQL._sql_constraints

issue4814
review15491002
This commit is contained in:
Cédric Krier
2015-06-22 16:59:04 +02:00
parent f057dfae63
commit 1619092e5b
2 changed files with 7 additions and 4 deletions
+3 -2
View File
@@ -6,7 +6,7 @@ from sql.aggregate import Sum
from sql.conditionals import Coalesce
from trytond import backend
from trytond.model import ModelView, ModelSQL, fields
from trytond.model import ModelView, ModelSQL, fields, Unique
from trytond.wizard import Wizard, StateView, StateAction, Button
from trytond.pyson import Eval, PYSONEncoder
from trytond.transaction import Transaction
@@ -361,8 +361,9 @@ class AnalyticAccountEntry(ModelView, ModelSQL):
@classmethod
def __setup__(cls):
super(AnalyticAccountEntry, cls).__setup__()
t = cls.__table__()
cls._sql_constraints += [
('root_origin_uniq', 'UNIQUE(origin, root)',
('root_origin_uniq', Unique(t, t.origin, t.root),
'Only one account is allowed per analytic root and origin.'),
]
+4 -2
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 decimal import Decimal
from trytond.model import ModelView, ModelSQL, fields
from trytond.model import ModelView, ModelSQL, fields, Check
from trytond.wizard import Wizard, StateAction
from trytond import backend
from trytond.pyson import Eval, PYSONEncoder
@@ -47,9 +47,11 @@ class Line(ModelSQL, ModelView):
@classmethod
def __setup__(cls):
super(Line, cls).__setup__()
t = cls.__table__()
cls._sql_constraints += [
('credit_debit',
'CHECK((credit * debit = 0.0) AND (credit + debit >= 0.0))',
Check(t,
(t.credit * t.debit == 0) & (t.credit + t.debit >= 0)),
'Wrong credit/debit values.'),
]
cls._error_messages.update({