From c9136ab84df3fc3ff821f32c518a9ced1688e464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 24 Jul 2018 22:01:08 +0200 Subject: [PATCH] Add __table_handler__ to ModelSQL issue7581 review48531002 --- address.py | 5 ++--- category.py | 6 ++---- contact_mechanism.py | 6 ++---- party.py | 9 +++------ 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/address.py b/address.py index 9bf3f48401..1e1b9ae183 100644 --- a/address.py +++ b/address.py @@ -11,7 +11,6 @@ from trytond.model import ( ModelView, ModelSQL, MatchMixin, DeactivableMixin, fields, sequence_ordered) from trytond.pyson import Eval, If -from trytond import backend from trytond.pool import Pool from trytond.transaction import Transaction from trytond.cache import Cache @@ -57,13 +56,13 @@ class Address(DeactivableMixin, sequence_ordered(), ModelSQL, ModelView): @classmethod def __register__(cls, module_name): - TableHandler = backend.get('TableHandler') cursor = Transaction().connection.cursor() - table = TableHandler(cls, module_name) sql_table = cls.__table__() super(Address, cls).__register__(module_name) + table = cls.__table_handler__(module_name) + # Migration from 2.4: drop required on sequence table.not_null_action('sequence', action='remove') diff --git a/category.py b/category.py index 20940ecde5..2972de2788 100644 --- a/category.py +++ b/category.py @@ -3,7 +3,6 @@ from sql.conditionals import Coalesce from sql.operators import Equal -from trytond import backend from trytond.model import ( ModelView, ModelSQL, DeactivableMixin, fields, Exclude, tree) from trytond.pyson import Eval @@ -42,10 +41,9 @@ class Category(DeactivableMixin, tree(separator=' / '), ModelSQL, ModelView): @classmethod def __register__(cls, module_name): - TableHandler = backend.get('TableHandler') - table_h = TableHandler(cls, module_name) - super(Category, cls).__register__(module_name) + table_h = cls.__table_handler__(module_name) + # Migration from 4.6: replace unique by exclude table_h.drop_constraint('name_parent_uniq') diff --git a/contact_mechanism.py b/contact_mechanism.py index c177484da6..0c216f5d70 100644 --- a/contact_mechanism.py +++ b/contact_mechanism.py @@ -9,7 +9,6 @@ except ImportError: from trytond.model import ( ModelView, ModelSQL, DeactivableMixin, fields, sequence_ordered) from trytond.pyson import Eval -from trytond import backend __all__ = ['ContactMechanism'] @@ -104,11 +103,10 @@ class ContactMechanism( @classmethod def __register__(cls, module_name): - TableHandler = backend.get('TableHandler') - table = TableHandler(cls, module_name) - super(ContactMechanism, cls).__register__(module_name) + table = cls.__table_handler__(module_name) + # Migration from 2.4: drop required on sequence table.not_null_action('sequence', action='remove') diff --git a/party.py b/party.py index 47f698ceef..dc2d2236ba 100644 --- a/party.py +++ b/party.py @@ -87,11 +87,9 @@ class Party(DeactivableMixin, ModelSQL, ModelView, MultiValueMixin): @classmethod def __register__(cls, module_name): - TableHandler = backend.get('TableHandler') - super(Party, cls).__register__(module_name) - table_h = TableHandler(cls, module_name) + table_h = cls.__table_handler__(module_name) # Migration from 3.8 table_h.not_null_action('name', 'remove') @@ -275,7 +273,7 @@ class PartyLang(ModelSQL, ValueMixin): super(PartyLang, cls).__register__(module_name) if not exist: - party_h = TableHandler(Party, module_name) + party_h = Party.__table_handler__(module_name) if party_h.column_exist('lang'): query = table.insert( [table.party, table.lang], @@ -330,13 +328,12 @@ class PartyIdentifier(sequence_ordered(), ModelSQL, ModelView): def __register__(cls, module_name): pool = Pool() Party = pool.get('party.party') - TableHandler = backend.get('TableHandler') cursor = Transaction().connection.cursor() party = Party.__table__() super(PartyIdentifier, cls).__register__(module_name) - party_h = TableHandler(Party, module_name) + party_h = Party.__table_handler__(module_name) if (party_h.column_exist('vat_number') and party_h.column_exist('vat_country')): identifiers = []