From 85ad73ae86ac36060f8893a8b94c8a6e14695e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 20 Sep 2013 17:28:50 +0200 Subject: [PATCH] Fix UNIQUE constraint on EmployeeCostPrice review1086003 --- company.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/company.py b/company.py index 8a80468359..4d1e3fd02f 100644 --- a/company.py +++ b/company.py @@ -6,6 +6,7 @@ from trytond.pyson import Eval from trytond.cache import Cache from trytond.transaction import Transaction from trytond.pool import Pool, PoolMeta +from trytond import backend __all__ = ['Employee', 'EmployeeCostPrice'] __metaclass__ = PoolMeta @@ -88,11 +89,22 @@ class EmployeeCostPrice(ModelSQL, ModelView): currency_digits = fields.Function(fields.Integer('Currency Digits', on_change_with=['employee']), 'on_change_with_currency_digits') + @classmethod + def __register__(cls, module_name): + TableHandler = backend.get('TableHandler') + cursor = Transaction().cursor + super(EmployeeCostPrice, cls).__register__(module_name) + table = TableHandler(cursor, cls, module_name) + + # Migration from 2.8 drop date_cost_price_uniq + table.drop_constraint('date_cost_price_uniq') + @classmethod def __setup__(cls): super(EmployeeCostPrice, cls).__setup__() cls._sql_constraints = [ - ('date_cost_price_uniq', 'UNIQUE(date, cost_price)', + ('employee_date_cost_price_uniq', + 'UNIQUE(employee, date, cost_price)', 'A employee can only have one cost price by date.'), ] cls._order.insert(0, ('date', 'DESC'))