From 67d76e3f311f7673fc4e925348750a6e6af899f8 Mon Sep 17 00:00:00 2001 From: Prakash Pandey Date: Wed, 31 Dec 2014 15:35:38 +0100 Subject: [PATCH] Remove unique constraints from country issue4153 review10721002 --- CHANGELOG | 2 ++ country.py | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 79e3b214a3..5f7b58920e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Remove unique constraints from country name and code + Version 3.4.0 - 2014-10-20 * Bug fixes (see mercurial logs for details) * Add zip diff --git a/country.py b/country.py index 335cdb47ad..12fcd7d71b 100644 --- a/country.py +++ b/country.py @@ -2,6 +2,8 @@ # this repository contains the full copyright notices and license terms. from trytond.model import ModelView, ModelSQL, fields from trytond.pyson import Eval +from trytond.transaction import Transaction +from trytond import backend __all__ = ['Country', 'Subdivision', 'Zip'] @@ -20,14 +22,20 @@ class Country(ModelSQL, ModelView): @classmethod def __setup__(cls): super(Country, cls).__setup__() - cls._sql_constraints += [ - ('name_uniq', 'UNIQUE(name)', - 'The name of the country must be unique.'), - ('code_uniq', 'UNIQUE(code)', - 'The code of the country must be unique.'), - ] cls._order.insert(0, ('name', 'ASC')) + @classmethod + def __register__(cls, module_name): + TableHandler = backend.get('TableHandler') + cursor = Transaction().cursor + table = TableHandler(cursor, cls, module_name) + + super(Country, cls).__register__(module_name) + + # Migration from 3.4: drop unique constraints from name and code + table.drop_constraint('name_uniq') + table.drop_constraint('code_uniq') + @classmethod def search_rec_name(cls, name, clause): if cls.search([('code',) + tuple(clause[1:])], limit=1):