diff --git a/account.py b/account.py index f36adc9c98..2bd86bb746 100644 --- a/account.py +++ b/account.py @@ -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.'), ] diff --git a/line.py b/line.py index 18bc02fc12..4e7e966b5d 100644 --- a/line.py +++ b/line.py @@ -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({