From d9b40ac0d976f509dff65bdc75113bdf80bed37f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 24 Jul 2018 22:01:07 +0200 Subject: [PATCH] Add __table_handler__ to ModelSQL issue7581 review48531002 --- account.py | 7 ++----- invoice.py | 11 ++++------- payment_term.py | 5 ++--- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/account.py b/account.py index d200f688bc..2f73f2c8ac 100644 --- a/account.py +++ b/account.py @@ -11,7 +11,6 @@ from trytond.pyson import Eval, If, Bool from trytond.pool import Pool, PoolMeta from trytond.tools import grouped_slice from trytond.transaction import Transaction -from trytond import backend __all__ = ['FiscalYear', 'Period', 'Move', 'MoveLine', 'Reconciliation', 'InvoiceSequence', @@ -30,7 +29,6 @@ class FiscalYear(metaclass=PoolMeta): @classmethod def __register__(cls, module_name): - TableHandler = backend.get('TableHandler') pool = Pool() Sequence = pool.get('account.fiscalyear.invoice_sequence') sequence = Sequence.__table__() @@ -38,7 +36,7 @@ class FiscalYear(metaclass=PoolMeta): super(FiscalYear, cls).__register__(module_name) cursor = Transaction().connection.cursor() - table = TableHandler(cls, module_name) + table = cls.__table_handler__(module_name) # Migration from 4.2: Use Match pattern for sequences if (table.column_exist('in_invoice_sequence') @@ -76,7 +74,6 @@ class Period(metaclass=PoolMeta): @classmethod def __register__(cls, module_name): - TableHandler = backend.get('TableHandler') pool = Pool() Sequence = pool.get('account.fiscalyear.invoice_sequence') FiscalYear = pool.get('account.fiscalyear') @@ -86,7 +83,7 @@ class Period(metaclass=PoolMeta): super(Period, cls).__register__(module_name) cursor = Transaction().connection.cursor() - table = TableHandler(cls, module_name) + table = cls.__table_handler__(module_name) # Migration from 4.2: Use Match pattern for sequences if (table.column_exist('in_invoice_sequence') diff --git a/invoice.py b/invoice.py index 0276fed9e9..9a12c04c41 100644 --- a/invoice.py +++ b/invoice.py @@ -323,7 +323,6 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin): pool = Pool() Line = pool.get('account.invoice.line') Tax = pool.get('account.invoice.tax') - TableHandler = backend.get('TableHandler') sql_table = cls.__table__() line = Line.__table__() tax = Tax.__table__() @@ -331,7 +330,7 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin): super(Invoice, cls).__register__(module_name) transaction = Transaction() cursor = transaction.connection.cursor() - table = TableHandler(cls, module_name) + table = cls.__table_handler__(module_name) # Migration from 1.2 invoice_date is no more required table.not_null_action('invoice_date', action='remove') @@ -1756,11 +1755,10 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin): pool = Pool() Invoice = pool.get('account.invoice') invoice = Invoice.__table__() - TableHandler = backend.get('TableHandler') sql_table = cls.__table__() super(InvoiceLine, cls).__register__(module_name) cursor = Transaction().connection.cursor() - table = TableHandler(cls, module_name) + table = cls.__table_handler__(module_name) # Migration from 1.0 invoice is no more required table.not_null_action('invoice', action='remove') @@ -2243,11 +2241,10 @@ class InvoiceTax(sequence_ordered(), ModelSQL, ModelView): @classmethod def __register__(cls, module_name): - TableHandler = backend.get('TableHandler') - table = TableHandler(cls, module_name) - super(InvoiceTax, 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/payment_term.py b/payment_term.py index 1201f5c2b5..86883d67a7 100644 --- a/payment_term.py +++ b/payment_term.py @@ -140,11 +140,10 @@ class PaymentTermLine(sequence_ordered(), ModelSQL, ModelView): @classmethod def __register__(cls, module_name): - TableHandler = backend.get('TableHandler') sql_table = cls.__table__() super(PaymentTermLine, cls).__register__(module_name) cursor = Transaction().connection.cursor() - table = TableHandler(cls, module_name) + table = cls.__table_handler__(module_name) # Migration from 1.0 percent change into percentage if table.column_exist('percent'): @@ -341,7 +340,7 @@ class PaymentTermLineRelativeDelta(sequence_ordered(), ModelSQL, ModelView): super(PaymentTermLineRelativeDelta, cls).__register__(module_name) - line_table = TableHandler(Line, module_name) + line_table = Line.__table_handler__(module_name) # Migration from 3.4 fields = ['day', 'month', 'weekday', 'months', 'weeks', 'days']