From c6529befe2aa8b06129674d857f1bb46cb594530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 22 Jun 2015 16:59:25 +0200 Subject: [PATCH] Use Constraint instance in ModelSQL._sql_constraints issue4814 review15491002 --- currency.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/currency.py b/currency.py index 03803b3313..8af9352807 100644 --- a/currency.py +++ b/currency.py @@ -4,7 +4,7 @@ import datetime import json from decimal import Decimal, ROUND_HALF_EVEN -from trytond.model import ModelView, ModelSQL, fields +from trytond.model import ModelView, ModelSQL, fields, Unique, Check from trytond.tools import datetime_strftime from trytond.transaction import Transaction from trytond.pool import Pool @@ -254,10 +254,11 @@ class Rate(ModelSQL, ModelView): @classmethod def __setup__(cls): super(Rate, cls).__setup__() + t = cls.__table__() cls._sql_constraints = [ - ('date_currency_uniq', 'UNIQUE(date, currency)', + ('date_currency_uniq', Unique(t, t.date, t.currency), 'A currency can only have one rate by date.'), - ('check_currency_rate', 'CHECK(rate >= 0)', + ('check_currency_rate', Check(t, t.rate >= 0), 'The currency rate must greater than or equal to 0'), ] cls._order.insert(0, ('date', 'DESC'))