diff --git a/modules/account/configuration.py b/modules/account/configuration.py index b01289c207..f1bc33bf86 100644 --- a/modules/account/configuration.py +++ b/modules/account/configuration.py @@ -5,7 +5,6 @@ from trytond.modules.company.model import ( CompanyMultiValueMixin, CompanyValueMixin) from trytond.pool import Pool from trytond.pyson import Eval, Id -from trytond.transaction import Transaction tax_roundings = [ ('document', 'Per Document'), @@ -174,21 +173,6 @@ class ConfigurationTaxRounding(ModelSQL, CompanyValueMixin): depends={'company'}) tax_rounding = fields.Selection(tax_roundings, 'Method', required=True) - @classmethod - def __register__(cls, module_name): - sql_table = cls.__table__() - cursor = Transaction().connection.cursor() - - super(ConfigurationTaxRounding, cls).__register__(module_name) - - table = cls.__table_handler__(module_name) - - # Migration from 4.2: rename method into tax_rounding - if table.column_exist('method'): - cursor.execute(*sql_table.update( - [sql_table.tax_rounding], [sql_table.method])) - table.drop_column('method') - @classmethod def default_tax_rounding(cls): return 'document' diff --git a/modules/account/journal.py b/modules/account/journal.py index 99f54dfb28..0db8da9845 100644 --- a/modules/account/journal.py +++ b/modules/account/journal.py @@ -4,7 +4,6 @@ from decimal import Decimal from sql.aggregate import Sum -from trytond import backend from trytond.i18n import gettext from trytond.model import ( DeactivableMixin, MatchMixin, ModelSQL, ModelView, Unique, Workflow, @@ -17,7 +16,6 @@ from trytond.pool import Pool from trytond.pyson import Bool, Eval, Id from trytond.tools import ( grouped_slice, is_full_text, lstrip_wildcard, reduce_ids) -from trytond.tools.multivalue import migrate_property from trytond.transaction import Transaction STATES = { @@ -200,24 +198,6 @@ class JournalSequence(ModelSQL, CompanyValueMixin): ], depends={'company'}) - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(JournalSequence, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('sequence') - value_names.append('sequence') - fields.append('company') - migrate_property( - 'account.journal', field_names, cls, value_names, - parent='journal', fields=fields) - @classmethod def default_sequence(cls): pool = Pool() @@ -278,14 +258,6 @@ class JournalPeriod( }) cls.active.states = STATES - @classmethod - def __register__(cls, module_name): - super(JournalPeriod, cls).__register__(module_name) - - table = cls.__table_handler__(cls, module_name) - # Migration from 4.2: remove name column - table.drop_column('name') - @staticmethod def default_state(): return 'open' diff --git a/modules/account/move.py b/modules/account/move.py index 73300b82fa..d81d7f6072 100644 --- a/modules/account/move.py +++ b/modules/account/move.py @@ -6,12 +6,11 @@ from itertools import chain, combinations, groupby, islice from dateutil.relativedelta import relativedelta from sql import Literal, Null, Window -from sql.aggregate import Max, Sum +from sql.aggregate import Sum from sql.conditionals import Case, Coalesce from sql.functions import Abs, CharLength, Round from sql.operators import Exists -from trytond import backend from trytond.config import config from trytond.i18n import gettext from trytond.model import ( @@ -114,30 +113,6 @@ class Move(ModelSQL, ModelView): (t.period, Index.Equality())), }) - @classmethod - def __register__(cls, module_name): - cursor = Transaction().connection.cursor() - table = cls.__table_handler__(module_name) - sql_table = cls.__table__() - pool = Pool() - Period = pool.get('account.period') - period = Period.__table__() - FiscalYear = pool.get('account.fiscalyear') - fiscalyear = FiscalYear.__table__() - - created_company = not table.column_exist('company') - - super(Move, cls).__register__(module_name) - - # Migration from 3.4: new company field - if created_company: - # Don't use UPDATE FROM because SQLite nor MySQL support it. - value = period.join(fiscalyear, - condition=period.fiscalyear == fiscalyear.id).select( - fiscalyear.company, - where=period.id == sql_table.period) - cursor.execute(*sql_table.update([sql_table.company], [value])) - @classmethod def order_number(cls, tables): table, _ = tables[None] @@ -535,7 +510,6 @@ class Reconciliation(ModelSQL, ModelView): line = Line.__table__() line_h = Line.__table_handler__(module_name) - date_exist = table.column_exist('date') company_exist = table.column_exist('company') # Migration from 6.6: rename name to number @@ -544,18 +518,6 @@ class Reconciliation(ModelSQL, ModelView): super(Reconciliation, cls).__register__(module_name) - # Migration from 3.8: new date field - if (not date_exist - and backend.TableHandler.table_exist(Line._table) - and Line.__table_handler__().column_exist('move')): - cursor.execute(*sql_table.update( - [sql_table.date], - line.join(move, - condition=move.id == line.move - ).select(Max(move.date), - where=line.reconciliation == sql_table.id, - group_by=line.reconciliation))) - # Migration from 5.8: add company field if not company_exist and line_h.column_exist('reconciliation'): value = (line diff --git a/modules/account/move_template.py b/modules/account/move_template.py index 9699caa7ea..5dbe4c547a 100644 --- a/modules/account/move_template.py +++ b/modules/account/move_template.py @@ -282,15 +282,6 @@ class TaxLineTemplate(ModelSQL, ModelView): super().__setup__() cls.__access__.add('line') - @classmethod - def __register__(cls, module_name): - super(TaxLineTemplate, cls).__register__(module_name) - - table_h = cls.__table_handler__(module_name) - - # Migration from 4.6: remove code - table_h.drop_column('code') - def get_line(self, values): 'Return the tax line for the keyword values' pool = Pool() diff --git a/modules/account/party.py b/modules/account/party.py index 7410554b77..40bb0edec5 100644 --- a/modules/account/party.py +++ b/modules/account/party.py @@ -6,7 +6,6 @@ from sql import Literal, Null from sql.aggregate import Sum from sql.conditionals import Coalesce -from trytond import backend from trytond.i18n import gettext from trytond.model import ModelSQL, fields from trytond.modules.company.model import ( @@ -16,7 +15,6 @@ from trytond.modules.party.exceptions import EraseError from trytond.pool import Pool, PoolMeta from trytond.pyson import Eval, If from trytond.tools import grouped_slice, reduce_ids -from trytond.tools.multivalue import migrate_property from trytond.transaction import Transaction from .exceptions import AccountMissing @@ -328,24 +326,6 @@ class PartyAccount(ModelSQL, CompanyValueMixin): ], ondelete='RESTRICT') - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(PartyAccount, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.extend(account_names) - value_names.extend(account_names) - fields.append('company') - migrate_property( - 'party.party', field_names, cls, value_names, - parent='party', fields=fields) - class PartyReplace(metaclass=PoolMeta): __name__ = 'party.replace' diff --git a/modules/account_asset/account.py b/modules/account_asset/account.py index 68771e493a..76070db89b 100644 --- a/modules/account_asset/account.py +++ b/modules/account_asset/account.py @@ -1,13 +1,11 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond import backend from trytond.i18n import gettext from trytond.model import ModelSQL, fields from trytond.model.exceptions import AccessError from trytond.modules.company.model import CompanyValueMixin from trytond.pool import Pool, PoolMeta from trytond.pyson import Bool, Eval, Id, If -from trytond.tools.multivalue import migrate_property asset_bymonthday = fields.Selection([ ('1', "First"), @@ -96,24 +94,6 @@ class ConfigurationAssetSequence(ModelSQL, CompanyValueMixin): Id('account_asset', 'sequence_type_asset')), ]) - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(ConfigurationAssetSequence, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('asset_sequence') - value_names.append('asset_sequence') - fields.append('company') - migrate_property( - 'account.configuration', field_names, cls, value_names, - fields=fields) - @classmethod def default_asset_sequence(cls): pool = Pool() diff --git a/modules/account_asset/asset.py b/modules/account_asset/asset.py index dad0d9151c..01dc9b6e47 100644 --- a/modules/account_asset/asset.py +++ b/modules/account_asset/asset.py @@ -241,15 +241,6 @@ class Asset(Workflow, ModelSQL, ModelView): }, }) - @classmethod - def __register__(cls, module_name): - table_h = cls.__table_handler__(module_name) - - # Migration from 3.8: rename reference into number - if table_h.column_exist('reference'): - table_h.column_rename('reference', 'number') - super(Asset, cls).__register__(module_name) - @classmethod def order_number(cls, tables): table, _ = tables[None] diff --git a/modules/account_asset/product.py b/modules/account_asset/product.py index 026064c1bb..a58a7d4e2c 100644 --- a/modules/account_asset/product.py +++ b/modules/account_asset/product.py @@ -1,6 +1,5 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of this # repository contains the full copyright notices and license terms. -from trytond import backend from trytond.model import fields from trytond.modules.account_product.product import ( account_used, template_property) @@ -75,27 +74,6 @@ class CategoryAccount(metaclass=PoolMeta): ('company', '=', Eval('company', -1)), ]) - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - if exist: - table = cls.__table_handler__(module_name) - exist &= (table.column_exist('account_depreciation') - and table.column_exist('account_asset')) - - super(CategoryAccount, cls).__register__(module_name) - - if not exist: - # Re-migration - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.extend(['account_depreciation', 'account_asset']) - value_names.extend(['account_depreciation', 'account_asset']) - super(CategoryAccount, cls)._migrate_property( - field_names, value_names, fields) - class Template(metaclass=PoolMeta): __name__ = 'product.template' diff --git a/modules/account_be/__init__.py b/modules/account_be/__init__.py index 63c5e9a6a4..41de9915a6 100644 --- a/modules/account_be/__init__.py +++ b/modules/account_be/__init__.py @@ -8,7 +8,6 @@ from . import account def register(): Pool.register( - account.AccountTemplate, account.BEVATCustomer, account.BEVATCustomerContext, module='account_be', type_='model') diff --git a/modules/account_be/account.py b/modules/account_be/account.py index a4b089c472..92e07d6bb2 100644 --- a/modules/account_be/account.py +++ b/modules/account_be/account.py @@ -2,8 +2,6 @@ # this repository contains the full copyright notices and license terms. from sql import Literal from sql.aggregate import Max, Min, Sum -from sql.functions import Position -from sql.operators import Concat from trytond.model import ModelSQL, ModelView, fields from trytond.modules.account.exceptions import FiscalYearNotFoundError @@ -13,30 +11,6 @@ from trytond.pyson import Eval from trytond.transaction import Transaction -class AccountTemplate(metaclass=PoolMeta): - __name__ = 'account.account.template' - - @classmethod - def __register__(cls, module_name): - pool = Pool() - ModelData = pool.get('ir.model.data') - cursor = Transaction().connection.cursor() - model_data = ModelData.__table__() - - # Migration from 3.4: translation of the account chart - cursor.execute(*model_data.select(model_data.id, - where=((model_data.fs_id == 'be') - & (model_data.module == 'account_be')))) - if cursor.fetchone(): - cursor.execute(*model_data.update( - columns=[model_data.fs_id], - values=[Concat(model_data.fs_id, '_fr')], - where=((Position('_fr', model_data.fs_id) == 0) - & (model_data.module == 'account_be')))) - - super(AccountTemplate, cls).__register__(module_name) - - class CreateChart(metaclass=PoolMeta): __name__ = 'account.create_chart' diff --git a/modules/account_credit_limit/party.py b/modules/account_credit_limit/party.py index ebadd2a3df..3697ae4dc7 100644 --- a/modules/account_credit_limit/party.py +++ b/modules/account_credit_limit/party.py @@ -1,12 +1,10 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond import backend from trytond.i18n import gettext from trytond.model import ModelSQL, fields from trytond.modules.company.model import CompanyValueMixin from trytond.pool import Pool, PoolMeta from trytond.pyson import Eval -from trytond.tools.multivalue import migrate_property from trytond.transaction import Transaction from .exceptions import CreditLimitError, CreditLimitWarning @@ -142,24 +140,6 @@ class PartyCreditLimitAmount(ModelSQL, CompanyValueMixin): credit_limit_digits = fields.Function(fields.Integer('Currency Digits'), 'on_change_with_credit_limit_digits') - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(PartyCreditLimitAmount, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('credit_limit_amount') - value_names.append('credit_limit_amount') - fields.append('company') - migrate_property( - 'party.party', field_names, cls, value_names, - parent='party', fields=fields) - @fields.depends('company') def on_change_with_credit_limit_digits(self, name=None): if self.company: diff --git a/modules/account_dunning/dunning.py b/modules/account_dunning/dunning.py index e3806a81d0..17c7f18895 100644 --- a/modules/account_dunning/dunning.py +++ b/modules/account_dunning/dunning.py @@ -1,10 +1,9 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import datetime from collections import defaultdict from itertools import groupby -from sql import Literal, Null +from sql import Literal from trytond.model import ( Index, Model, ModelSQL, ModelView, Unique, fields, sequence_ordered) @@ -37,28 +36,6 @@ class Level(sequence_ordered(), ModelSQL, ModelView): overdue = fields.TimeDelta('Overdue', help="When the level should be applied.") - @classmethod - def __register__(cls, module_name): - transaction = Transaction() - cursor = transaction.connection.cursor() - update = transaction.connection.cursor() - table = cls.__table_handler__(module_name) - sql_table = cls.__table__() - - super(Level, cls).__register__(module_name) - - # Migration from 4.0: change days into timedelta overdue - if table.column_exist('days'): - cursor.execute(*sql_table.select(sql_table.id, sql_table.days, - where=sql_table.days != Null)) - for id_, days in cursor: - overdue = datetime.timedelta(days) - update.execute(*sql_table.update( - [sql_table.overdue], - [overdue], - where=sql_table.id == id_)) - table.drop_column('days') - def get_rec_name(self, name): return '%s@%s' % (self.procedure.levels.index(self), self.procedure.rec_name) @@ -164,17 +141,6 @@ class Dunning(ModelSQL, ModelView): }, }) - @classmethod - def __register__(cls, module): - dunning = cls.__table__() - super().__register__(module) - cursor = Transaction().connection.cursor() - - # Migration from 4.8: rename done state into waiting - cursor.execute(*dunning.update( - [dunning.state], ['waiting'], - where=dunning.state == 'done')) - @staticmethod def default_company(): return Transaction().context.get('company') diff --git a/modules/account_dunning/party.py b/modules/account_dunning/party.py index 618edb0a0b..7d4ff5c00e 100644 --- a/modules/account_dunning/party.py +++ b/modules/account_dunning/party.py @@ -1,9 +1,7 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond import backend from trytond.model import ModelSQL, ValueMixin, fields from trytond.pool import Pool, PoolMeta -from trytond.tools.multivalue import migrate_property dunning_procedure = fields.Many2One( 'account.dunning.procedure', "Dunning Procedure") @@ -31,20 +29,3 @@ class PartyDunningProcedure(ModelSQL, ValueMixin): party = fields.Many2One( 'party.party', "Party", ondelete='CASCADE') dunning_procedure = dunning_procedure - - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(PartyDunningProcedure, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('dunning_procedure') - value_names.append('dunning_procedure') - migrate_property( - 'party.party', field_names, cls, value_names, - parent='party', fields=fields) diff --git a/modules/account_fr/__init__.py b/modules/account_fr/__init__.py index 8f779a96ce..0e6bff07fd 100644 --- a/modules/account_fr/__init__.py +++ b/modules/account_fr/__init__.py @@ -9,8 +9,6 @@ from . import account def register(): Pool.register( account.AccountTemplate, - account.TaxTemplate, - account.TaxRuleTemplate, account.FrFECStart, account.FrFECResult, module='account_fr', type_='model') diff --git a/modules/account_fr/account.py b/modules/account_fr/account.py index 43f5f39a1f..c19f0e38d1 100644 --- a/modules/account_fr/account.py +++ b/modules/account_fr/account.py @@ -50,42 +50,6 @@ class AccountTemplate(metaclass=PoolMeta): super().__register__(module_name) -class TaxTemplate(metaclass=PoolMeta): - __name__ = 'account.tax.template' - - @classmethod - def __register__(cls, module_name): - cursor = Transaction().connection.cursor() - model_data = Table('ir_model_data') - - # Migration from 3.0: new tax rates - if module_name == 'account_fr': - for old_id, new_id in ( - ('tva_vente_19_6', 'tva_vente_taux_normal'), - ('tva_vente_7', 'tva_vente_taux_intermediaire'), - ('tva_vente_intracommunautaire_19_6', - 'tva_vente_intracommunautaire_taux_normal'), - ('tva_vente_intracommunautaire_7', - 'tva_vente_intracommunautaire_taux_intermediaire'), - ('tva_achat_19_6', 'tva_achat_taux_normal'), - ('tva_achat_7', 'tva_achat_taux_intermediaire'), - ('tva_achat_intracommunautaire_19_6', - 'tva_achat_intracommunautaire_taux_normal'), - ): - cursor.execute(*model_data.select(model_data.id, - where=(model_data.fs_id == new_id) - & (model_data.module == module_name))) - if cursor.fetchone(): - continue - cursor.execute(*model_data.update( - columns=[model_data.fs_id], - values=[new_id], - where=(model_data.fs_id == old_id) - & (model_data.module == module_name))) - - super(TaxTemplate, cls).__register__(module_name) - - class CreateChart(metaclass=PoolMeta): __name__ = 'account.create_chart' @@ -102,31 +66,6 @@ class CreateChart(metaclass=PoolMeta): return defaults -class TaxRuleTemplate(metaclass=PoolMeta): - __name__ = 'account.tax.rule.template' - - @classmethod - def __register__(cls, module_name): - cursor = Transaction().connection.cursor() - model_data = Table('ir_model_data') - - if module_name == 'account_fr': - for old_id, new_id in ( - ('tax_rule_ventes_intracommunautaires_19_6', - 'tax_rule_ventes_intracommunautaires_taux_normal'), - ('tax_rule_ventes_intracommunautaires_7', - 'tax_rule_ventes_intracommunautaires_taux' - '_intermediaire'), - ): - cursor.execute(*model_data.update( - columns=[model_data.fs_id], - values=[new_id], - where=(model_data.fs_id == old_id) - & (model_data.module == module_name))) - - super(TaxRuleTemplate, cls).__register__(module_name) - - class FrFEC(Wizard): 'Generate FEC' __name__ = 'account.fr.fec' diff --git a/modules/account_invoice/account.py b/modules/account_invoice/account.py index baf3d367cc..a2306813d4 100644 --- a/modules/account_invoice/account.py +++ b/modules/account_invoice/account.py @@ -3,9 +3,6 @@ from collections import OrderedDict from itertools import islice -from sql import Literal -from sql.conditionals import Coalesce - from trytond.i18n import gettext from trytond.model import ( MatchMixin, ModelSQL, ModelView, Workflow, fields, sequence_ordered) @@ -51,41 +48,6 @@ class FiscalYear(metaclass=PoolMeta): ('company', '=', Eval('company', -1)), ]) - @classmethod - def __register__(cls, module_name): - pool = Pool() - Sequence = pool.get('account.fiscalyear.invoice_sequence') - sequence = Sequence.__table__() - sql_table = cls.__table__() - - super(FiscalYear, cls).__register__(module_name) - cursor = Transaction().connection.cursor() - table = cls.__table_handler__(module_name) - - # Migration from 4.2: Use Match pattern for sequences - if (table.column_exist('in_invoice_sequence') - and table.column_exist('in_credit_note_sequence') - and table.column_exist('out_invoice_sequence') - and table.column_exist('out_credit_note_sequence')): - cursor.execute(*sequence.insert(columns=[ - sequence.sequence, sequence.fiscalyear, - sequence.company, - sequence.out_invoice_sequence, - sequence.out_credit_note_sequence, - sequence.in_invoice_sequence, - sequence.in_credit_note_sequence], - values=sql_table.select( - Literal(20), sql_table.id, - sql_table.company, - sql_table.out_invoice_sequence, - sql_table.out_credit_note_sequence, - sql_table.in_invoice_sequence, - sql_table.in_credit_note_sequence))) - table.drop_column('out_invoice_sequence') - table.drop_column('out_credit_note_sequence') - table.drop_column('in_invoice_sequence') - table.drop_column('in_credit_note_sequence') - @staticmethod def default_invoice_sequences(): if Transaction().user == 0: @@ -96,49 +58,6 @@ class FiscalYear(metaclass=PoolMeta): class Period(metaclass=PoolMeta): __name__ = 'account.period' - @classmethod - def __register__(cls, module_name): - pool = Pool() - Sequence = pool.get('account.fiscalyear.invoice_sequence') - FiscalYear = pool.get('account.fiscalyear') - sequence = Sequence.__table__() - fiscalyear = FiscalYear.__table__() - sql_table = cls.__table__() - - super(Period, cls).__register__(module_name) - cursor = Transaction().connection.cursor() - table = cls.__table_handler__(module_name) - - # Migration from 4.2: Use Match pattern for sequences - if (table.column_exist('in_invoice_sequence') - and table.column_exist('in_credit_note_sequence') - and table.column_exist('out_invoice_sequence') - and table.column_exist('out_credit_note_sequence')): - cursor.execute(*sequence.insert(columns=[ - sequence.sequence, sequence.fiscalyear, - sequence.company, sequence.period, - sequence.out_invoice_sequence, - sequence.out_credit_note_sequence, - sequence.in_invoice_sequence, - sequence.in_credit_note_sequence], - values=sql_table.join(fiscalyear, - condition=(fiscalyear.id == sql_table.fiscalyear) - ).select( - Literal(10), sql_table.fiscalyear, - fiscalyear.company, sql_table.id, - Coalesce(sql_table.out_invoice_sequence, - fiscalyear.out_invoice_sequence), - Coalesce(sql_table.out_credit_note_sequence, - fiscalyear.out_credit_note_sequence), - Coalesce(sql_table.in_invoice_sequence, - fiscalyear.in_invoice_sequence), - Coalesce(sql_table.in_credit_note_sequence, - fiscalyear.in_credit_note_sequence)))) - table.drop_column('out_invoice_sequence') - table.drop_column('out_credit_note_sequence') - table.drop_column('in_invoice_sequence') - table.drop_column('in_credit_note_sequence') - @classmethod @ModelView.button @Workflow.transition('close') diff --git a/modules/account_invoice/invoice.py b/modules/account_invoice/invoice.py index a8714011b1..e3390c6c94 100644 --- a/modules/account_invoice/invoice.py +++ b/modules/account_invoice/invoice.py @@ -5,7 +5,6 @@ from collections import defaultdict, namedtuple from decimal import Decimal from itertools import chain, combinations, groupby -from sql import Null from sql.aggregate import Sum from sql.conditionals import Case, Coalesce from sql.functions import CharLength, Round @@ -390,63 +389,13 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin): @classmethod def __register__(cls, module_name): - pool = Pool() - Line = pool.get('account.invoice.line') - Tax = pool.get('account.invoice.tax') sql_table = cls.__table__() - line = Line.__table__() - tax = Tax.__table__() super(Invoice, cls).__register__(module_name) transaction = Transaction() cursor = transaction.connection.cursor() table = cls.__table_handler__(module_name) - # Migration from 3.8: remove invoice/credit note type - cursor.execute(*sql_table.select(sql_table.id, - where=sql_table.type.like('%_invoice') - | sql_table.type.like('%_credit_note'), - limit=1)) - if cursor.fetchone(): - for type_ in ['out', 'in']: - cursor.execute(*sql_table.update( - columns=[sql_table.type], - values=[type_], - where=sql_table.type == '%s_invoice' % type_)) - cursor.execute(*line.update( - columns=[line.invoice_type], - values=[type_], - where=line.invoice_type == '%s_invoice' % type_)) - - cursor.execute(*line.update( - columns=[line.quantity, line.invoice_type], - values=[-line.quantity, type_], - where=(line.invoice_type == '%s_credit_note' % type_) - & (line.invoice == Null) - )) - # Don't use UPDATE FROM because SQLite nor MySQL support it - cursor.execute(*line.update( - columns=[line.quantity, line.invoice_type], - values=[-line.quantity, type_], - where=line.invoice.in_(sql_table.select(sql_table.id, - where=( - sql_table.type == '%s_credit_note' % type_) - )))) - cursor.execute(*tax.update( - columns=[tax.base, tax.amount, tax.base_sign], - values=[-tax.base, -tax.amount, -tax.base_sign], - where=tax.invoice.in_(sql_table.select(sql_table.id, - where=( - sql_table.type == '%s_credit_note' % type_) - )))) - cursor.execute(*sql_table.update( - columns=[sql_table.type], - values=[type_], - where=sql_table.type == '%s_credit_note' % type_)) - - # Migration from 4.0: Drop not null on payment_term - table.not_null_action('payment_term', 'remove') - # Migration from 5.6: rename state cancel to cancelled cursor.execute(*sql_table.update( [sql_table.state], ['cancelled'], @@ -2180,28 +2129,8 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin): @classmethod def __register__(cls, module_name): - pool = Pool() - Invoice = pool.get('account.invoice') - invoice = Invoice.__table__() - sql_table = cls.__table__() - transaction = Transaction() - cursor = transaction.connection.cursor() - update = transaction.connection.cursor() super(InvoiceLine, cls).__register__(module_name) table = cls.__table_handler__(module_name) - - # Migration from 3.4: company is required - cursor.execute(*sql_table.join(invoice, - condition=sql_table.invoice == invoice.id - ).select(sql_table.id, invoice.company, - where=sql_table.company == Null)) - for line_id, company_id in cursor: - update.execute(*sql_table.update([sql_table.company], [company_id], - where=sql_table.id == line_id)) - - # Migration from 4.6: drop required on description - table.not_null_action('description', action='remove') - # Migration from 5.0: remove check constraints table.drop_constraint('type_account') table.drop_constraint('type_invoice') @@ -2807,16 +2736,6 @@ class InvoiceTax(sequence_ordered(), ModelSQL, ModelView): super().__setup__() cls.__access__.add('invoice') - @classmethod - def __register__(cls, module_name): - super(InvoiceTax, cls).__register__(module_name) - - table = cls.__table_handler__(module_name) - - # Migration from 4.6: drop base_sign and tax_sign - table.not_null_action('base_sign', action='remove') - table.not_null_action('tax_sign', action='remove') - @staticmethod def default_base(): return Decimal('0.0') diff --git a/modules/account_invoice/party.py b/modules/account_invoice/party.py index c0e01e88bc..fa33a71203 100644 --- a/modules/account_invoice/party.py +++ b/modules/account_invoice/party.py @@ -1,11 +1,9 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond import backend from trytond.i18n import gettext from trytond.model import ModelSQL, ValueMixin, fields from trytond.modules.party.exceptions import EraseError from trytond.pool import Pool, PoolMeta -from trytond.tools.multivalue import migrate_property customer_payment_term = fields.Many2One( 'account.invoice.payment_term', "Customer Payment Term") @@ -62,23 +60,6 @@ class PartyPaymentTerm(ModelSQL, ValueMixin): customer_payment_term = customer_payment_term supplier_payment_term = supplier_payment_term - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(PartyPaymentTerm, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.extend(['customer_payment_term', 'supplier_payment_term']) - value_names.extend(['customer_payment_term', 'supplier_payment_term']) - migrate_property( - 'party.party', field_names, cls, value_names, - parent='party', fields=fields) - class Replace(metaclass=PoolMeta): __name__ = 'party.replace' diff --git a/modules/account_invoice/payment_term.py b/modules/account_invoice/payment_term.py index f9d402187e..feda4f05d6 100644 --- a/modules/account_invoice/payment_term.py +++ b/modules/account_invoice/payment_term.py @@ -3,10 +3,8 @@ from decimal import Decimal from dateutil.relativedelta import relativedelta -from sql import Column from trytond import backend -from trytond.config import config from trytond.i18n import gettext from trytond.model import ( DeactivableMixin, ModelSQL, ModelView, fields, sequence_ordered) @@ -122,20 +120,6 @@ class PaymentTermLine(sequence_ordered(), ModelSQL, ModelView): super().__setup__() cls.__access__.add('payment') - @classmethod - def __register__(cls, module_name): - sql_table = cls.__table__() - super(PaymentTermLine, cls).__register__(module_name) - cursor = Transaction().connection.cursor() - table = cls.__table_handler__(module_name) - - # Migration from 3.8: rename percentage into ratio - if table.column_exist('percentage'): - cursor.execute(*sql_table.update( - columns=[sql_table.ratio], - values=[sql_table.percentage / 100])) - table.drop_column('percentage') - @staticmethod def default_type(): return 'remainder' @@ -248,22 +232,13 @@ class PaymentTermLineRelativeDelta(sequence_ordered(), ModelSQL, ModelView): transaction = Transaction() cursor = transaction.connection.cursor() pool = Pool() - Line = pool.get('account.invoice.payment_term.line') Month = pool.get('ir.calendar.month') Day = pool.get('ir.calendar.day') sql_table = cls.__table__() - line = Line.__table__() month = Month.__table__() day = Day.__table__() table_h = cls.__table_handler__(module_name) - # Migration from 4.0: rename long table - old_model_name = 'account.invoice.payment_term.line.relativedelta' - old_table = config.get( - 'table', old_model_name, default=old_model_name.replace('.', '_')) - if backend.TableHandler.table_exist(old_table): - backend.TableHandler.table_rename(old_table, cls._table) - # Migration from 5.0: use ir.calendar migrate_calendar = False if (backend.TableHandler.table_exist(cls._table) @@ -279,19 +254,6 @@ class PaymentTermLineRelativeDelta(sequence_ordered(), ModelSQL, ModelView): super(PaymentTermLineRelativeDelta, cls).__register__(module_name) table_h = cls.__table_handler__(module_name) - line_table = Line.__table_handler__(module_name) - - # Migration from 3.4 - fields = ['day', 'month', 'weekday', 'months', 'weeks', 'days'] - if any(line_table.column_exist(f) for f in fields): - columns = ([line.id.as_('line')] - + [Column(line, f) for f in fields]) - cursor.execute(*sql_table.insert( - columns=[sql_table.line] - + [Column(sql_table, f) for f in fields], - values=line.select(*columns))) - for field in fields: - line_table.drop_column(field) # Migration from 5.0: use ir.calendar if migrate_calendar: diff --git a/modules/account_payment/account.py b/modules/account_payment/account.py index 801a0e674e..9a0929d556 100644 --- a/modules/account_payment/account.py +++ b/modules/account_payment/account.py @@ -8,14 +8,12 @@ from sql.aggregate import Sum from sql.conditionals import Case, Coalesce from sql.functions import Abs -from trytond import backend from trytond.i18n import gettext from trytond.model import ModelSQL, ModelView, fields from trytond.modules.company.model import CompanyValueMixin from trytond.modules.currency.fields import Monetary from trytond.pool import Pool, PoolMeta from trytond.pyson import Bool, Eval, Id, If -from trytond.tools.multivalue import migrate_property from trytond.transaction import Transaction, check_access from trytond.wizard import ( Button, StateAction, StateTransition, StateView, Wizard) @@ -476,24 +474,6 @@ class ConfigurationPaymentGroupSequence(ModelSQL, CompanyValueMixin): Id('account_payment', 'sequence_type_account_payment_group')), ]) - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(ConfigurationPaymentGroupSequence, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('payment_group_sequence') - value_names.append('payment_group_sequence') - fields.append('company') - migrate_property( - 'account.configuration', field_names, cls, value_names, - fields=fields) - @classmethod def default_payment_group_sequence(cls): pool = Pool() diff --git a/modules/account_payment/payment.py b/modules/account_payment/payment.py index 31eb5079b4..57a6725cb4 100644 --- a/modules/account_payment/payment.py +++ b/modules/account_payment/payment.py @@ -111,15 +111,6 @@ class Group(ModelSQL, ModelView): }, ) - @classmethod - def __register__(cls, module_name): - table_h = cls.__table_handler__(module_name) - - # Migration from 3.8: rename reference into number - if table_h.column_exist('reference'): - table_h.column_rename('reference', 'number') - super(Group, cls).__register__(module_name) - @classmethod def order_number(cls, tables): table, _ = tables[None] diff --git a/modules/account_payment_sepa/account.py b/modules/account_payment_sepa/account.py index 4d1d9b1ac7..74ef0465d8 100644 --- a/modules/account_payment_sepa/account.py +++ b/modules/account_payment_sepa/account.py @@ -1,11 +1,9 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond import backend from trytond.model import ModelSQL, fields from trytond.modules.company.model import CompanyValueMixin from trytond.pool import PoolMeta from trytond.pyson import Eval, Id -from trytond.tools.multivalue import migrate_property class Configuration(metaclass=PoolMeta): @@ -30,21 +28,3 @@ class ConfigurationSepaMandateSequence(ModelSQL, CompanyValueMixin): 'account_payment_sepa', 'sequence_type_mandate')), ('company', 'in', [Eval('company', -1), None]), ]) - - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(ConfigurationSepaMandateSequence, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('sepa_mandate_sequence') - value_names.append('sepa_mandate_sequence') - fields.append('company') - migrate_property( - 'account.configuration', field_names, cls, value_names, - fields=fields) diff --git a/modules/account_payment_sepa/party.py b/modules/account_payment_sepa/party.py index fcc97d3d0b..30c16ee676 100644 --- a/modules/account_payment_sepa/party.py +++ b/modules/account_payment_sepa/party.py @@ -1,8 +1,5 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from sql import Literal, Null -from sql.functions import CurrentTimestamp - from trytond.i18n import gettext from trytond.model import fields from trytond.pool import Pool, PoolMeta @@ -20,28 +17,6 @@ class Party(metaclass=PoolMeta): sepa_mandates = fields.One2Many('account.payment.sepa.mandate', 'party', 'SEPA Mandates') - @classmethod - def __register__(cls, module_name): - Identifier = Pool().get('party.identifier') - cursor = Transaction().connection.cursor() - sql_table = cls.__table__() - identifier = Identifier.__table__() - super(Party, cls).__register__(module_name) - table = cls.__table_handler__(module_name) - - # Migration from 4.0: Move sepa_creditor_identifier to identifier - if table.column_exist('sepa_creditor_identifier'): - select = sql_table.select(Literal(0), CurrentTimestamp(), - sql_table.id, Literal('sepa'), - sql_table.sepa_creditor_identifier, - where=((sql_table.sepa_creditor_identifier != Null) - & (sql_table.sepa_creditor_identifier != ""))) - cursor.execute(*identifier.insert( - columns=[identifier.create_uid, identifier.create_date, - identifier.party, identifier.type, identifier.code], - values=select)) - table.drop_column('sepa_creditor_identifier') - @classmethod def copy(cls, parties, default=None): if default is None: diff --git a/modules/account_payment_sepa/payment.py b/modules/account_payment_sepa/payment.py index d0cf49a5f4..11b44bee5c 100644 --- a/modules/account_payment_sepa/payment.py +++ b/modules/account_payment_sepa/payment.py @@ -14,7 +14,6 @@ from genshi.template.astutil import ASTCodeGenerator, ASTTransformer from lxml import etree from sql import Literal, Null -from trytond import backend from trytond.config import config from trytond.i18n import gettext from trytond.model import ( @@ -855,32 +854,12 @@ class Message(Workflow, ModelSQL, ModelView): @classmethod def __register__(cls, module_name): - pool = Pool() - Group = pool.get('account.payment.group') transaction = Transaction() cursor = transaction.connection.cursor() - update = transaction.connection.cursor() table = cls.__table__() super(Message, cls).__register__(module_name) - # Migration from 3.2 - if backend.TableHandler.table_exist(Group._table): - group_table = Group.__table_handler__(module_name) - if group_table.column_exist('sepa_message'): - group = Group.__table__() - cursor.execute(*group.select( - group.id, group.sepa_message, group.company)) - for group_id, message, company_id in cursor: - update.execute(*table.insert( - [table.message, table.type, table.company, - table.origin, table.state], - [[ - message, 'out', company_id, - 'account.payment.group,%s' % group_id, - 'done']])) - group_table.drop_column('sepa_message') - # Migration from 5.6: rename state canceled to cancelled cursor.execute(*table.update( [table.state], ['cancelled'], diff --git a/modules/account_payment_stripe/payment.py b/modules/account_payment_stripe/payment.py index 997bb47ec5..26450313e8 100644 --- a/modules/account_payment_stripe/payment.py +++ b/modules/account_payment_stripe/payment.py @@ -251,20 +251,6 @@ class Payment(StripeCustomerMethodMixin, CheckoutMixin, metaclass=PoolMeta): }, }) - @classmethod - def __register__(cls, module_name): - cursor = Transaction().connection.cursor() - sql_table = cls.__table__() - table = cls.__table_handler__(module_name) - idempotency_key_exist = table.column_exist('stripe_idempotency_key') - - super(Payment, cls).__register__(module_name) - - # Migration from 4.6: do not set the same key to all existing payments - if not idempotency_key_exist: - cursor.execute(*sql_table.update( - [sql_table.stripe_idempotency_key], [None])) - @classmethod def default_stripe_capture(cls): return True diff --git a/modules/account_product/product.py b/modules/account_product/product.py index db3d1e8a94..3d99b7fcb9 100644 --- a/modules/account_product/product.py +++ b/modules/account_product/product.py @@ -4,14 +4,12 @@ from functools import wraps from sql import Null -from trytond import backend from trytond.i18n import gettext from trytond.model import ModelSQL, fields from trytond.modules.company.model import ( CompanyMultiValueMixin, CompanyValueMixin) from trytond.pool import Pool, PoolMeta from trytond.pyson import Bool, Eval, Or -from trytond.tools.multivalue import migrate_property from trytond.transaction import Transaction from .exceptions import AccountError, TaxError @@ -277,24 +275,6 @@ class CategoryAccount(ModelSQL, CompanyValueMixin): ('company', '=', Eval('company', -1)), ]) - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(CategoryAccount, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.extend(['account_expense', 'account_revenue']) - value_names.extend(['account_expense', 'account_revenue']) - fields.append('company') - migrate_property( - 'product.category', field_names, cls, value_names, - parent='category', fields=fields) - class CategoryCustomerTax(ModelSQL): 'Category - Customer Tax' diff --git a/modules/account_statement/account.py b/modules/account_statement/account.py index ef4ebcaa79..b066657b0a 100644 --- a/modules/account_statement/account.py +++ b/modules/account_statement/account.py @@ -1,16 +1,9 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from itertools import groupby -from operator import itemgetter - -from sql.operators import Concat - from trytond.i18n import gettext from trytond.model import ModelView from trytond.modules.account.exceptions import PostError from trytond.pool import Pool, PoolMeta -from trytond.tools import grouped_slice, reduce_ids -from trytond.transaction import Transaction class Journal(metaclass=PoolMeta): @@ -25,34 +18,6 @@ class Journal(metaclass=PoolMeta): class Move(metaclass=PoolMeta): __name__ = 'account.move' - @classmethod - def __register__(cls, module_name): - pool = Pool() - StatementLine = pool.get('account.statement.line') - cursor = Transaction().connection.cursor() - sql_table = cls.__table__() - - super(Move, cls).__register__(module_name) - - # Migration from 3.4: - # account.statement.line origin changed to account.statement - statement_line = StatementLine.__table__() - cursor.execute(*sql_table.join(statement_line, - condition=( - Concat(StatementLine.__name__ + ',', statement_line.id) - == sql_table.origin - ) - ).select(sql_table.id, statement_line.statement, - order_by=(sql_table.id, statement_line.statement))) - for statement_id, values in groupby(cursor, itemgetter(1)): - ids = [x[0] for x in values] - for sub_ids in grouped_slice(ids): - red_sql = reduce_ids(sql_table.id, sub_ids) - cursor.execute(*sql_table.update( - columns=[sql_table.origin], - values=['account.statement,%s' % statement_id], - where=red_sql)) - @classmethod def _get_origin(cls): return super(Move, cls)._get_origin() + ['account.statement'] diff --git a/modules/account_statement/journal.py b/modules/account_statement/journal.py index 5a3227b620..da4c70c826 100644 --- a/modules/account_statement/journal.py +++ b/modules/account_statement/journal.py @@ -1,7 +1,5 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from sql import Table - from trytond.model import DeactivableMixin, ModelSQL, ModelView, Unique, fields from trytond.pool import Pool from trytond.pyson import Eval @@ -59,26 +57,6 @@ class Journal(DeactivableMixin, ModelSQL, ModelView): 'account_statement.msg_journal_bank_account_unique'), ] - @classmethod - def __register__(cls, module_name): - cursor = Transaction().connection.cursor() - table = cls.__table_handler__(module_name) - sql_table = cls.__table__() - journal_account = Table('account_journal_account') - - created_account = not table.column_exist('account') - - super(Journal, cls).__register__(module_name) - - # Migration from 4.8: new account field - if created_account and table.table_exist('account_journal_account'): - value = journal_account.select(journal_account.credit_account, - where=((journal_account.journal == sql_table.journal) - & (journal_account.credit_account - == journal_account.debit_account))) - # Don't use UPDATE FROM because SQLite does not support it. - cursor.execute(*sql_table.update([sql_table.account], [value])) - @staticmethod def default_currency(): if Transaction().context.get('company'): diff --git a/modules/account_statement/statement.py b/modules/account_statement/statement.py index d3227e77a5..b0f04b9f27 100644 --- a/modules/account_statement/statement.py +++ b/modules/account_statement/statement.py @@ -183,16 +183,6 @@ class Statement(Workflow, ModelSQL, ModelView): sql_table = cls.__table__() super(Statement, cls).__register__(module_name) - table = cls.__table_handler__(module_name) - - # Migration from 3.2: remove required on start/end balance - table.not_null_action('start_balance', action='remove') - table.not_null_action('end_balance', action='remove') - - # Migration from 3.2: add required name - cursor.execute(*sql_table.update([sql_table.name], - [sql_table.id.cast(cls.name.sql_type().base)], - where=sql_table.name == Null)) # Migration from 5.6: rename state cancel to cancelled cursor.execute(*sql_table.update( diff --git a/modules/account_stock_anglo_saxon/product.py b/modules/account_stock_anglo_saxon/product.py index 47bbbe552f..497b2f5435 100644 --- a/modules/account_stock_anglo_saxon/product.py +++ b/modules/account_stock_anglo_saxon/product.py @@ -1,6 +1,5 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond import backend from trytond.model import fields from trytond.modules.account_product.product import ( account_used, template_property) @@ -51,26 +50,6 @@ class CategoryAccount(metaclass=PoolMeta): ('company', '=', Eval('company', -1)), ]) - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - if exist: - table = cls.__table_handler__(module_name) - exist &= table.column_exist('account_cogs') - - super(CategoryAccount, cls).__register__(module_name) - - if not exist: - # Re-migration - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('account_cogs') - value_names.append('account_cogs') - super(CategoryAccount, cls)._migrate_property( - field_names, value_names, fields) - @classmethod def get_account_stock_type_statements(cls): return super().get_account_stock_type_statements() + ['balance'] diff --git a/modules/account_stock_continental/product.py b/modules/account_stock_continental/product.py index ccb29711e6..5cb9002646 100644 --- a/modules/account_stock_continental/product.py +++ b/modules/account_stock_continental/product.py @@ -2,7 +2,6 @@ # this repository contains the full copyright notices and license terms. from decimal import Decimal -from trytond import backend from trytond.model import fields from trytond.modules.account_product.product import ( account_used, template_property) @@ -133,33 +132,6 @@ class CategoryAccount(metaclass=PoolMeta): cls.get_account_stock_type_statements()), ] - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - if exist: - table = cls.__table_handler__(module_name) - exist &= all(table.column_exist(c) for c in account_names) - - # Migration from 5.4: rename account_stock_{supplier,customer} - for old, new in [ - ('account_stock_supplier', 'account_stock_in'), - ('account_stock_customer', 'account_stock_out')]: - if table.column_exist(old): - table.column_rename(old, new) - - super(CategoryAccount, cls).__register__(module_name) - - if not exist: - # Re-migration - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.extend(account_names) - value_names.extend(account_names) - super(CategoryAccount, cls)._migrate_property( - field_names, value_names, fields) - @classmethod def get_account_stock_type_statements(cls): return ['income'] diff --git a/modules/account_stock_landed_cost/account.py b/modules/account_stock_landed_cost/account.py index 46f4dc8be0..821575efc3 100644 --- a/modules/account_stock_landed_cost/account.py +++ b/modules/account_stock_landed_cost/account.py @@ -6,7 +6,6 @@ from operator import itemgetter from sql.functions import CharLength -from trytond import backend from trytond.i18n import gettext from trytond.model import ( Index, MatchMixin, ModelSQL, ModelView, Workflow, fields) @@ -14,7 +13,6 @@ from trytond.modules.company.model import CompanyValueMixin from trytond.modules.product import price_digits, round_price from trytond.pool import Pool, PoolMeta from trytond.pyson import Eval, Id -from trytond.tools.multivalue import migrate_property from trytond.transaction import Transaction from trytond.wizard import Button, StateTransition, StateView, Wizard @@ -57,24 +55,6 @@ class ConfigurationLandedCostSequence(ModelSQL, CompanyValueMixin): Id('account_stock_landed_cost', 'sequence_type_landed_cost')), ]) - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(ConfigurationLandedCostSequence, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('landed_cost_sequence') - value_names.append('landed_cost_sequence') - fields.append('company') - migrate_property( - 'account.configuration', field_names, cls, value_names, - fields=fields) - @classmethod def default_landed_cost_sequence(cls, **pattern): pool = Pool() @@ -189,13 +169,8 @@ class LandedCost(Workflow, ModelSQL, ModelView, MatchMixin): @classmethod def __register__(cls, module_name): cursor = Transaction().connection.cursor() - table_h = cls.__table_handler__(module_name) sql_table = cls.__table__() - # Migration from 3.8: rename code into number - if table_h.column_exist('code'): - table_h.column_rename('code', 'number') - super(LandedCost, cls).__register__(module_name) # Migration from 5.6: rename state cancel to cancelled diff --git a/modules/analytic_account/account.py b/modules/analytic_account/account.py index e3d08e757b..2f38b3adee 100644 --- a/modules/analytic_account/account.py +++ b/modules/analytic_account/account.py @@ -3,11 +3,10 @@ from collections import defaultdict from decimal import Decimal -from sql import Column, Literal, Null +from sql import Column, Literal from sql.aggregate import Sum from sql.conditionals import Coalesce -from trytond import backend from trytond.i18n import gettext from trytond.model import ( DeactivableMixin, Index, ModelSQL, ModelView, Unique, fields, tree) @@ -107,9 +106,6 @@ class Account( super(Account, cls).__register__(module_name) table = cls.__table_handler__(module_name) - # Migration from 4.0: remove currency - table.not_null_action('currency', action='remove') - # Migration from 5.0: remove display_balance table.drop_column('display_balance') @@ -381,40 +377,6 @@ class AnalyticAccountEntry(ModelView, ModelSQL): company = fields.Function(fields.Many2One('company.company', 'Company'), 'on_change_with_company', searcher='search_company') - @classmethod - def __register__(cls, module_name): - pool = Pool() - Account = pool.get('analytic_account.account') - transaction = Transaction() - cursor = transaction.connection.cursor() - update = transaction.connection.cursor() - - # Migration from 3.4: use origin as the key for One2Many - migration_3_4 = False - old_table = 'analytic_account_account_selection_rel' - if backend.TableHandler.table_exist(old_table): - backend.TableHandler.table_rename(old_table, cls._table) - migration_3_4 = True - - # Don't create table before renaming - table = cls.__table_handler__(module_name) - - super(AnalyticAccountEntry, cls).__register__(module_name) - - # Migration from 3.4: set root value and remove required - if migration_3_4: - account = Account.__table__() - cursor.execute(*account.select(account.id, account.root, - where=account.type != 'root')) - entry = cls.__table__() - for account_id, root_id in cursor: - update.execute(*entry.update( - columns=[entry.root], - values=[root_id], - where=entry.account == account_id)) - table.not_null_action('selection', action='remove') - table.not_null_action('account', action='remove') - @classmethod def __setup__(cls): super(AnalyticAccountEntry, cls).__setup__() @@ -468,30 +430,6 @@ class AnalyticMixin(object): analytic_accounts_size = fields.Function(fields.Integer( 'Analytic Accounts Size'), 'get_analytic_accounts_size') - @classmethod - def __register__(cls, module_name): - pool = Pool() - AccountEntry = pool.get('analytic.account.entry') - transaction = Transaction() - cursor = transaction.connection.cursor() - update = transaction.connection.cursor() - - super(AnalyticMixin, cls).__register__(module_name) - - handler = cls.__table_handler__(module_name) - # Migration from 3.4: analytic accounting changed to reference field - if handler.column_exist('analytic_accounts'): - entry = AccountEntry.__table__() - table = cls.__table__() - cursor.execute(*table.select(table.id, table.analytic_accounts, - where=table.analytic_accounts != Null)) - for line_id, selection_id in cursor: - update.execute(*entry.update( - columns=[entry.origin], - values=['%s,%s' % (cls.__name__, line_id)], - where=entry.selection == selection_id)) - handler.drop_column('analytic_accounts') - @classmethod def analytic_accounts_domain(cls): context = Transaction().context.copy() diff --git a/modules/analytic_account/line.py b/modules/analytic_account/line.py index bdaeef86fc..cc67b2fa0b 100644 --- a/modules/analytic_account/line.py +++ b/modules/analytic_account/line.py @@ -59,10 +59,6 @@ class Line(ModelSQL, ModelView): super(Line, cls).__register__(module_name) table = cls.__table_handler__(module_name) - # Migration from 4.0: remove name and journal - for field_name in ['name', 'journal']: - table.not_null_action(field_name, action='remove') - # Migration from 5.0: replace credit_debit constraint by credit_debit_ table.drop_constraint('credit_debit') @@ -193,21 +189,6 @@ class MoveLine(metaclass=PoolMeta): }) cls._check_modify_exclude |= {'analytic_lines', 'analytic_state'} - @classmethod - def __register__(cls, module_name): - table = cls.__table_handler__(module_name) - cursor = Transaction().connection.cursor() - sql_table = cls.__table__() - - state_exist = table.column_exist('analytic_state') - - super(MoveLine, cls).__register__(module_name) - - # Migration from 4.0: add analytic_state - if not state_exist: - cursor.execute( - *sql_table.update([sql_table.analytic_state], ['valid'])) - @classmethod def default_analytic_state(cls): return 'draft' diff --git a/modules/company/party.py b/modules/company/party.py index 2eb4ca3319..dbffb4104f 100644 --- a/modules/company/party.py +++ b/modules/company/party.py @@ -1,10 +1,8 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond import backend from trytond.pool import Pool, PoolMeta from trytond.pyson import Eval from trytond.report import Report -from trytond.tools.multivalue import migrate_property from trytond.transaction import Transaction from .model import CompanyMultiValueMixin, CompanyValueMixin @@ -17,21 +15,6 @@ class Configuration(CompanyMultiValueMixin, metaclass=PoolMeta): class ConfigurationLang(CompanyValueMixin, metaclass=PoolMeta): __name__ = 'party.configuration.party_lang' - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - if exist: - table = cls.__table_handler__(module_name) - exist &= table.column_exist('company') - - super().__register__(module_name) - - if not exist: - # Re-migrate with company - migrate_property( - 'party.configuration', cls._configuration_value_field, - cls, cls._configuration_value_field, fields=['company']) - class Party(CompanyMultiValueMixin, metaclass=PoolMeta): __name__ = 'party.party' @@ -46,25 +29,6 @@ class PartyLang(CompanyValueMixin, metaclass=PoolMeta): cls.party.context['company'] = Eval('company', -1) cls.party.depends.add('company') - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - if exist: - table = cls.__table_handler__(module_name) - exist &= table.column_exist('company') - - super(PartyLang, cls).__register__(module_name) - - if not exist: - # Re-migrate with company - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - fields.append('company') - super(PartyLang, cls)._migrate_property( - field_names, value_names, fields) - class Replace(metaclass=PoolMeta): __name__ = 'party.replace' diff --git a/modules/country/country.py b/modules/country/country.py index e9cbd3e6be..d53598fa40 100644 --- a/modules/country/country.py +++ b/modules/country/country.py @@ -183,15 +183,6 @@ class Country(DeactivableMixin, ModelSQL, ModelView): super(Country, cls).__register__(module_name) - table = cls.__table_handler__(module_name) - - # Migration from 3.4: drop unique constraints from name and code - table.drop_constraint('name_uniq') - table.drop_constraint('code_uniq') - - # Migration from 3.8: remove required on code - table.not_null_action('code', 'remove') - # Migration from 5.2: remove country data cursor.execute(*data.delete(where=(data.module == 'country') & (data.model == cls.__name__))) diff --git a/modules/currency/currency.py b/modules/currency/currency.py index cfd4f7e549..b66680bb04 100644 --- a/modules/currency/currency.py +++ b/modules/currency/currency.py @@ -79,12 +79,6 @@ class Currency( table_h = cls.__table_handler__(module_name) - # Migration from 4.6: removal of monetary - for col in [ - 'mon_grouping', 'mon_decimal_point', - 'p_sign_posn', 'n_sign_posn']: - table_h.not_null_action(col, 'remove') - # Migration from 5.2: remove country data cursor.execute(*data.delete(where=(data.module == 'currency') & (data.model == cls.__name__))) diff --git a/modules/customs/product.py b/modules/customs/product.py index 5396ead115..2dd235d04b 100644 --- a/modules/customs/product.py +++ b/modules/customs/product.py @@ -4,7 +4,6 @@ from trytond.model import ModelSQL, ModelView, fields, sequence_ordered from trytond.pool import Pool, PoolMeta from trytond.pyson import Bool, Eval, Or from trytond.tools import grouped_slice -from trytond.transaction import Transaction class Category(metaclass=PoolMeta): @@ -111,27 +110,6 @@ class Template(metaclass=PoolMeta): }, help="The country of origin of the product.") - @classmethod - def __register__(cls, module_name): - cursor = Transaction().connection.cursor() - pool = Pool() - Category = pool.get('product.category') - sql_table = cls.__table__() - category = Category.__table__() - - table = cls.__table_handler__(module_name) - category_exists = table.column_exist('category') - - super(Template, cls).__register__(module_name) - - # Migration from 3.8: duplicate category into account_category - if category_exists: - # Only accounting category until now - cursor.execute(*category.update([category.customs], [True])) - cursor.execute(*sql_table.update( - [sql_table.customs_category], - [sql_table.category])) - @classmethod def default_tariff_codes_category(cls): return False diff --git a/modules/party/address.py b/modules/party/address.py index 0e56c3abe9..dd6390fd1e 100644 --- a/modules/party/address.py +++ b/modules/party/address.py @@ -4,9 +4,8 @@ from string import Template from sql import Literal -from sql.conditionals import Coalesce from sql.functions import Substring -from sql.operators import Concat, Equal +from sql.operators import Equal from trytond.cache import Cache from trytond.i18n import gettext @@ -83,8 +82,6 @@ class Address( @classmethod def __register__(cls, module_name): - cursor = Transaction().connection.cursor() - sql_table = cls.__table__() table = cls.__table_handler__(module_name) # Migration from 5.8: rename zip to postal code @@ -92,18 +89,6 @@ class Address( super(Address, cls).__register__(module_name) - table = cls.__table_handler__(module_name) - - # Migration from 4.0: remove streetbis - if table.column_exist('streetbis'): - value = Concat( - Coalesce(sql_table.street, ''), - Concat('\n', Coalesce(sql_table.streetbis, ''))) - cursor.execute(*sql_table.update( - [sql_table.street], - [value])) - table.drop_column('streetbis') - @fields.depends('street') def on_change_with_street_single_line(self, name=None): if self.street: diff --git a/modules/party/category.py b/modules/party/category.py index 13ece424af..d05366379d 100644 --- a/modules/party/category.py +++ b/modules/party/category.py @@ -30,12 +30,3 @@ class Category(DeactivableMixin, tree(separator=' / '), ModelSQL, ModelView): 'party.msg_category_name_unique'), ] cls._order.insert(0, ('name', 'ASC')) - - @classmethod - def __register__(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/modules/party/configuration.py b/modules/party/configuration.py index f5c9337db8..0dd7874777 100644 --- a/modules/party/configuration.py +++ b/modules/party/configuration.py @@ -1,13 +1,11 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond import backend from trytond.i18n import gettext from trytond.model import ( ModelSingleton, ModelSQL, ModelView, MultiValueMixin, ValueMixin, fields) from trytond.model.exceptions import AccessError from trytond.pool import Pool from trytond.pyson import Id -from trytond.tools.multivalue import migrate_property from .party import IDENTIFIER_TYPES @@ -91,41 +89,17 @@ class Configuration(ModelSingleton, ModelSQL, ModelView, MultiValueMixin): )) -class _ConfigurationValue(ModelSQL): - - _configuration_value_field = None - - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(_ConfigurationValue, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append(cls._configuration_value_field) - value_names.append(cls._configuration_value_field) - migrate_property( - 'party.configuration', field_names, cls, value_names, - fields=fields) - - -class ConfigurationSequence(_ConfigurationValue, ModelSQL, ValueMixin): +class ConfigurationSequence(ModelSQL, ValueMixin): 'Party Configuration Sequence' __name__ = 'party.configuration.party_sequence' party_sequence = party_sequence - _configuration_value_field = 'party_sequence' @classmethod def check_xml_record(cls, records, values): pass -class ConfigurationLang(_ConfigurationValue, ModelSQL, ValueMixin): +class ConfigurationLang(ModelSQL, ValueMixin): 'Party Configuration Lang' __name__ = 'party.configuration.party_lang' party_lang = party_lang - _configuration_value_field = 'party_lang' diff --git a/modules/party/party.py b/modules/party/party.py index d629bd9169..fb60046e11 100644 --- a/modules/party/party.py +++ b/modules/party/party.py @@ -1,12 +1,11 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. import stdnum.exceptions -from sql import Column, Literal, Null +from sql import Column, Literal from sql.aggregate import Min from sql.functions import CharLength from stdnum import get_cc_module -from trytond import backend from trytond.i18n import gettext from trytond.model import ( DeactivableMixin, Index, ModelSQL, ModelView, MultiValueMixin, Unique, @@ -15,7 +14,6 @@ from trytond.model.exceptions import AccessError from trytond.pool import Pool from trytond.pyson import Bool, Eval from trytond.tools import is_full_text, lstrip_wildcard -from trytond.tools.multivalue import migrate_property from trytond.transaction import Transaction, inactive_records from trytond.wizard import Button, StateTransition, StateView, Wizard @@ -106,15 +104,6 @@ class Party( 'readonly': Bool(Eval('replaced_by')), }) - @classmethod - def __register__(cls, module_name): - super(Party, cls).__register__(module_name) - - table_h = cls.__table_handler__(module_name) - - # Migration from 3.8 - table_h.not_null_action('name', 'remove') - @staticmethod def order_code(tables): table, _ = tables[None] @@ -341,36 +330,6 @@ class PartyLang(ModelSQL, ValueMixin): 'party.party', "Party", ondelete='CASCADE') lang = fields.Many2One('ir.lang', "Language") - @classmethod - def __register__(cls, module_name): - pool = Pool() - Party = pool.get('party.party') - cursor = Transaction().connection.cursor() - exist = backend.TableHandler.table_exist(cls._table) - table = cls.__table__() - party = Party.__table__() - - super(PartyLang, cls).__register__(module_name) - - if not exist: - party_h = Party.__table_handler__(module_name) - if party_h.column_exist('lang'): - query = table.insert( - [table.party, table.lang], - party.select(party.id, party.lang)) - cursor.execute(*query) - party_h.drop_column('lang') - else: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('lang') - value_names.append('lang') - migrate_property( - 'party.party', field_names, cls, value_names, - parent='party', fields=fields) - class PartyCategory(ModelSQL): 'Party - Category' @@ -623,38 +582,11 @@ class Identifier(sequence_ordered(), DeactivableMixin, ModelSQL, ModelView): @classmethod def __register__(cls, module_name): - pool = Pool() - Party = pool.get('party.party') cursor = Transaction().connection.cursor() - party = Party.__table__() table = cls.__table__() super().__register__(module_name) - party_h = Party.__table_handler__(module_name) - if (party_h.column_exist('vat_number') - and party_h.column_exist('vat_country')): - identifiers = [] - cursor.execute(*party.select( - party.id, party.vat_number, party.vat_country, - where=(party.vat_number != Null) - | (party.vat_country != Null))) - for party_id, number, country in cursor: - code = (country or '') + (number or '') - if not code: - continue - for type in Party.tax_identifier_types(): - module = get_cc_module(*type.split('_', 1)) - if module.is_valid(code): - break - else: - type = None - identifiers.append( - cls(party=party_id, code=code, type=type)) - cls.save(identifiers) - party_h.drop_column('vat_number') - party_h.drop_column('vat_country') - # Migration from 5.8: Rename cn_rit into cn_ric cursor.execute(*table.update([table.type], ['cn_ric'], where=(table.type == 'cn_rit'))) diff --git a/modules/product/configuration.py b/modules/product/configuration.py index a35634e42a..df9c6166ab 100644 --- a/modules/product/configuration.py +++ b/modules/product/configuration.py @@ -1,11 +1,9 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond import backend from trytond.model import ( ModelSingleton, ModelSQL, ModelView, MultiValueMixin, ValueMixin, fields) from trytond.pool import Pool from trytond.pyson import Id -from trytond.tools.multivalue import migrate_property default_cost_price_method = fields.Selection( 'get_cost_price_methods', "Default Cost Method", @@ -50,24 +48,6 @@ class ConfigurationDefaultCostPriceMethod(ModelSQL, ValueMixin): default_cost_price_method = default_cost_price_method get_cost_price_methods = get_cost_price_methods - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(ConfigurationDefaultCostPriceMethod, cls).__register__( - module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('default_cost_price_method') - value_names.append('default_cost_price_method') - migrate_property( - 'product.configuration', field_names, cls, value_names, - fields=fields) - @classmethod def default_default_cost_price_method(cls): return 'fixed' diff --git a/modules/product/product.py b/modules/product/product.py index e46f608dcb..44bd19e30e 100644 --- a/modules/product/product.py +++ b/modules/product/product.py @@ -7,11 +7,10 @@ from importlib import import_module import stdnum import stdnum.exceptions -from sql import Column, Literal, Null +from sql import Literal from sql.functions import CharLength from sql.operators import Equal -from trytond import backend from trytond.i18n import gettext from trytond.model import ( DeactivableMixin, Exclude, Index, Model, ModelSQL, ModelView, UnionMixin, @@ -21,7 +20,6 @@ from trytond.modules.company.model import ( from trytond.pool import Pool from trytond.pyson import Eval, Get, If from trytond.tools import is_full_text, lstrip_wildcard -from trytond.tools.multivalue import migrate_property from trytond.transaction import Transaction try: @@ -120,18 +118,6 @@ class Template( ], help="The different variants the product comes in.") - @classmethod - def __register__(cls, module_name): - super(Template, cls).__register__(module_name) - - table = cls.__table_handler__(module_name) - - # Migration from 3.8: rename category into categories - if table.column_exist('category'): - logger.warning( - 'The column "category" on table "%s" must be dropped manually', - cls._table) - @classmethod def __setup__(cls): cls.code.search_unaccented = False @@ -690,24 +676,6 @@ class ProductListPrice(ModelSQL, CompanyValueMixin): super().__setup__() cls.company.required = True - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(ProductListPrice, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('list_price') - value_names.append('list_price') - fields.append('company') - migrate_property( - 'product.template', field_names, cls, value_names, - parent='template', fields=fields) - class ProductCostPriceMethod(ModelSQL, CompanyValueMixin): "Product Cost Price Method" @@ -721,43 +689,6 @@ class ProductCostPriceMethod(ModelSQL, CompanyValueMixin): cost_price_method = fields.Selection( 'get_cost_price_methods', "Cost Price Method") - @classmethod - def __register__(cls, module_name): - pool = Pool() - ProductCostPrice = pool.get('product.cost_price') - sql_table = cls.__table__() - cost_price = ProductCostPrice.__table__() - cursor = Transaction().connection.cursor() - - exist = backend.TableHandler.table_exist(cls._table) - cost_price_exist = backend.TableHandler.table_exist( - ProductCostPrice._table) - - super(ProductCostPriceMethod, cls).__register__(module_name) - - # Migrate from 4.4: move cost_price_method from ProductCostPrice - if not exist and not cost_price_exist: - cls._migrate_property([], [], []) - elif not exist and cost_price_exist: - cost_price_table = ProductCostPrice.__table_handler__(module_name) - if cost_price_table.column_exist('template'): - columns = ['create_uid', 'create_date', - 'write_uid', 'write_date', - 'template', 'cost_price_method'] - cursor.execute(*sql_table.insert( - columns=[Column(sql_table, c) for c in columns], - values=cost_price.select( - *[Column(cost_price, c) for c in columns]))) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('cost_price_method') - value_names.append('cost_price_method') - fields.append('company') - migrate_property( - 'product.template', field_names, cls, value_names, - parent='template', fields=fields) - @classmethod def get_cost_price_methods(cls): pool = Pool() @@ -785,52 +716,6 @@ class ProductCostPrice(ModelSQL, CompanyValueMixin): super().__setup__() cls.company.required = True - @classmethod - def __register__(cls, module_name): - pool = Pool() - Product = pool.get('product.product') - sql_table = cls.__table__() - product = Product.__table__() - cursor = Transaction().connection.cursor() - - exist = backend.TableHandler.table_exist(cls._table) - - super(ProductCostPrice, cls).__register__(module_name) - - table = cls.__table_handler__(module_name) - if not exist: - # Create template column for property migration - table.add_column('template', 'INTEGER') - cls._migrate_property([], [], []) - - # Migration from 4.4: replace template by product - if table.column_exist('template'): - columns = ['create_uid', 'create_date', - 'write_uid', 'write_date', 'cost_price'] - cursor.execute(*sql_table.insert( - columns=[Column(sql_table, c) for c in columns] - + [sql_table.product], - values=sql_table.join(product, - condition=sql_table.template == product.template - ).select( - *[Column(sql_table, c) for c in columns] - + [product.id], - where=(sql_table.template != Null) - & (sql_table.product == Null)))) - cursor.execute(*sql_table.delete( - where=(sql_table.template != Null) - & (sql_table.product == Null))) - table.drop_column('template') - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('cost_price') - value_names.append('cost_price') - fields.append('company') - migrate_property( - 'product.template', field_names, cls, value_names, - parent='template', fields=fields) - class TemplateCategory(ModelSQL): 'Template - Category' diff --git a/modules/production/configuration.py b/modules/production/configuration.py index fbe23b0765..0363756890 100644 --- a/modules/production/configuration.py +++ b/modules/production/configuration.py @@ -1,12 +1,10 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond import backend from trytond.model import ModelSingleton, ModelSQL, ModelView, fields from trytond.modules.company.model import ( CompanyMultiValueMixin, CompanyValueMixin) from trytond.pool import Pool from trytond.pyson import Eval, Id -from trytond.tools.multivalue import migrate_property class Configuration( @@ -40,24 +38,6 @@ class ConfigurationProductionSequence(ModelSQL, CompanyValueMixin): Id('production', 'sequence_type_production')), ]) - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(ConfigurationProductionSequence, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('production_sequence') - value_names.append('production_sequence') - fields.append('company') - migrate_property( - 'production.configuration', field_names, cls, value_names, - fields=fields) - @classmethod def default_production_sequence(cls): pool = Pool() diff --git a/modules/production/production.py b/modules/production/production.py index 4fba9d280a..e4c92b3687 100644 --- a/modules/production/production.py +++ b/modules/production/production.py @@ -5,7 +5,6 @@ from datetime import timedelta from decimal import Decimal from itertools import chain, groupby -from sql import Null from sql.conditionals import Coalesce from sql.functions import CharLength @@ -261,22 +260,10 @@ class Production(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): @classmethod def __register__(cls, module_name): - table_h = cls.__table_handler__(module_name) - table = cls.__table__() - - # Migration from 3.8: rename code into number - if table_h.column_exist('code'): - table_h.column_rename('code', 'number') - super(Production, cls).__register__(module_name) - # Migration from 4.0: fill planned_start_date + table = cls.__table__() cursor = Transaction().connection.cursor() - cursor.execute(*table.update( - [table.planned_start_date], - [table.planned_date], - where=(table.planned_start_date == Null) - & (table.planned_date != Null))) # Migration from 5.6: rename state cancel to cancelled cursor.execute(*table.update( diff --git a/modules/project/work.py b/modules/project/work.py index e2874a724e..8519f2a306 100644 --- a/modules/project/work.py +++ b/modules/project/work.py @@ -3,8 +3,6 @@ import datetime -from sql import Null - from trytond.cache import Cache from trytond.i18n import gettext from trytond.model import ( @@ -230,84 +228,10 @@ class Work(sequence_ordered(), tree(separator='\\'), ModelSQL, ModelView): @classmethod def __register__(cls, module_name): - TimesheetWork = Pool().get('timesheet.work') - transaction = Transaction() - cursor = transaction.connection.cursor() - update = transaction.connection.cursor() table_project_work = cls.__table_handler__(module_name) - project = cls.__table__() - timesheet = TimesheetWork.__table__() - - work_exist = table_project_work.column_exist('work') - add_parent = (not table_project_work.column_exist('parent') - and work_exist) - add_company = (not table_project_work.column_exist('company') - and work_exist) - add_name = (not table_project_work.column_exist('name') - and work_exist) super(Work, cls).__register__(module_name) - # Migration from 3.4: change effort into timedelta effort_duration - if table_project_work.column_exist('effort'): - cursor.execute(*project.select(project.id, project.effort, - where=project.effort != Null)) - for id_, effort in cursor: - duration = datetime.timedelta(hours=effort) - update.execute(*project.update( - [project.effort_duration], - [duration], - where=project.id == id_)) - table_project_work.drop_column('effort') - - # Migration from 3.6: add parent, company, drop required on work, - # fill name - if add_parent: - second_project = cls.__table__() - query = project.join(timesheet, - condition=project.work == timesheet.id - ).join(second_project, - condition=timesheet.parent == second_project.work - ).select(project.id, second_project.id) - cursor.execute(*query) - for id_, parent in cursor: - update.execute(*project.update( - [project.parent], - [parent], - where=project.id == id_)) - cls._rebuild_tree('parent', None, 0) - if add_company: - cursor.execute(*project.join(timesheet, - condition=project.work == timesheet.id - ).select(project.id, timesheet.company)) - for id_, company in cursor: - update.execute(*project.update( - [project.company], - [company], - where=project.id == id_)) - table_project_work.not_null_action('work', action='remove') - if add_name: - cursor.execute(*project.join(timesheet, - condition=project.work == timesheet.id - ).select(project.id, timesheet.name)) - for id_, name in cursor: - update.execute(*project.update( - [project.name], - [name], - where=project.id == id_)) - - # Migration from 4.0: remove work - if work_exist: - table_project_work.drop_constraint('work_uniq') - cursor.execute(*project.select(project.id, project.work, - where=project.work != Null)) - for project_id, work_id in cursor: - update.execute(*timesheet.update( - [timesheet.origin, timesheet.name], - ['%s,%s' % (cls.__name__, project_id), Null], - where=timesheet.id == work_id)) - table_project_work.drop_column('work') - # Migration from 5.4: replace state by status table_project_work.not_null_action('state', action='remove') diff --git a/modules/project_plan/allocation.py b/modules/project_plan/allocation.py index 29ed0d18f2..667a943474 100644 --- a/modules/project_plan/allocation.py +++ b/modules/project_plan/allocation.py @@ -14,15 +14,6 @@ class Allocation(ModelSQL, ModelView): percentage = fields.Float('Percentage', digits=(16, 2), required=True, domain=[('percentage', '>', 0.0)]) - @classmethod - def __register__(cls, module_name): - super(Allocation, cls).__register__(module_name) - - table = cls.__table_handler__(module_name) - - # Migration from 3.2: - table.drop_constraint('percentage_positive') - @staticmethod def default_percentage(): return 100 diff --git a/modules/purchase/configuration.py b/modules/purchase/configuration.py index 8edf3f596d..3d946bf1a8 100644 --- a/modules/purchase/configuration.py +++ b/modules/purchase/configuration.py @@ -1,13 +1,11 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond import backend from trytond.model import ( ModelSingleton, ModelSQL, ModelView, ValueMixin, fields) from trytond.modules.company.model import ( CompanyMultiValueMixin, CompanyValueMixin) from trytond.pool import Pool from trytond.pyson import Eval, Id, TimeDelta -from trytond.tools.multivalue import migrate_property purchase_invoice_method = fields.Selection( 'get_purchase_invoice_method', "Invoice Method") @@ -77,24 +75,6 @@ class ConfigurationSequence(ModelSQL, CompanyValueMixin): Id('purchase', 'sequence_type_purchase')), ]) - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(ConfigurationSequence, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('purchase_sequence') - value_names.append('purchase_sequence') - fields.append('company') - migrate_property( - 'purchase.configuration', field_names, cls, value_names, - fields=fields) - @classmethod def default_purchase_sequence(cls): pool = Pool() @@ -111,23 +91,6 @@ class ConfigurationPurchaseMethod(ModelSQL, ValueMixin): purchase_invoice_method = purchase_invoice_method get_purchase_invoice_method = get_purchase_methods('invoice_method') - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(ConfigurationPurchaseMethod, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('purchase_invoice_method') - value_names.append('purchase_invoice_method') - migrate_property( - 'purchase.configuration', field_names, cls, value_names, - fields=fields) - @classmethod def default_purchase_invoice_method(cls): return 'order' diff --git a/modules/purchase/product.py b/modules/purchase/product.py index 8367f014bd..10cd55e4d7 100644 --- a/modules/purchase/product.py +++ b/modules/purchase/product.py @@ -311,10 +311,7 @@ class ProductSupplier( @classmethod def __register__(cls, module_name): - transaction = Transaction() - cursor = transaction.connection.cursor() table = cls.__table_handler__(module_name) - sql_table = cls.__table__() # Migration from 5.0: add product/template if (table.column_exist('product') @@ -323,20 +320,6 @@ class ProductSupplier( super(ProductSupplier, cls).__register__(module_name) - # Migration from 3.8: change delivery_time inte timedelta lead_time - if table.column_exist('delivery_time'): - cursor.execute(*sql_table.select( - sql_table.id, sql_table.delivery_time)) - for id_, delivery_time in cursor: - if delivery_time is None: - continue - lead_time = datetime.timedelta(days=delivery_time) - cursor.execute(*sql_table.update( - [sql_table.lead_time], - [lead_time], - where=sql_table.id == id_)) - table.drop_column('delivery_time') - @staticmethod def default_company(): return Transaction().context.get('company') @@ -483,21 +466,6 @@ class ProductSupplierPrice( super().__setup__() cls.__access__.add('product_supplier') - @classmethod - def __register__(cls, module_name): - cursor = Transaction().connection.cursor() - table = cls.__table_handler__(module_name) - sql_table = cls.__table__() - - fill_sequence = not table.column_exist('sequence') - - super(ProductSupplierPrice, cls).__register__(module_name) - - # Migration from 3.2: replace quantity by sequence for order - if fill_sequence: - cursor.execute(*sql_table.update( - [sql_table.sequence], [sql_table.quantity])) - @staticmethod def default_quantity(): return 0.0 diff --git a/modules/purchase/purchase.py b/modules/purchase/purchase.py index 2de16fab92..81a2b96cc3 100644 --- a/modules/purchase/purchase.py +++ b/modules/purchase/purchase.py @@ -5,12 +5,10 @@ from collections import defaultdict from decimal import Decimal from itertools import chain, groupby -from sql import Literal, Null +from sql import Literal from sql.aggregate import Count from sql.functions import CharLength -from sql.operators import Concat -from trytond import backend from trytond.i18n import gettext from trytond.ir.attachment import AttachmentCopyMixin from trytond.ir.note import NoteCopyMixin @@ -329,51 +327,10 @@ class Purchase( @classmethod def __register__(cls, module_name): - pool = Pool() - PurchaseLine = pool.get('purchase.line') - Move = pool.get('stock.move') - InvoiceLine = pool.get('account.invoice.line') cursor = Transaction().connection.cursor() sql_table = cls.__table__() - table = cls.__table_handler__(module_name) - - # Migration from 3.8: - if table.column_exist('supplier_reference'): - table.column_rename('reference', 'number') - table.column_rename('supplier_reference', 'reference') - super(Purchase, cls).__register__(module_name) - table = cls.__table_handler__(module_name) - - # Migration from 3.2 - # state confirmed splitted into confirmed and processing - if (backend.TableHandler.table_exist(PurchaseLine._table) - and backend.TableHandler.table_exist(Move._table) - and backend.TableHandler.table_exist(InvoiceLine._table)): - purchase_line = PurchaseLine.__table__() - move = Move.__table__() - invoice_line = InvoiceLine.__table__() - # Wrap subquery inside an other inner subquery because MySQL syntax - # doesn't allow update a table and select from the same table in a - # subquery. - sub_query = sql_table.join(purchase_line, - condition=purchase_line.purchase == sql_table.id - ).join(invoice_line, 'LEFT', - condition=(invoice_line.origin - == Concat( - PurchaseLine.__name__ + ',', purchase_line.id)) - ).join(move, 'LEFT', - condition=(move.origin == Concat( - PurchaseLine.__name__ + ',', purchase_line.id)) - ).select(sql_table.id, - where=((sql_table.state == 'confirmed') - & ((invoice_line.id != Null) - | (move.id != Null)))) - cursor.execute(*sql_table.update( - columns=[sql_table.state], - values=['processing'], - where=sql_table.id.in_(sub_query.select(sub_query.id)))) # Migration from 5.6: rename state cancel to cancelled cursor.execute(*sql_table.update( @@ -1308,14 +1265,6 @@ class Line(sequence_ordered(), ModelSQL, ModelView): cls._order.insert(0, ('purchase.purchase_date', 'DESC NULLS FIRST')) cls._order.insert(1, ('purchase.id', 'DESC')) - @classmethod - def __register__(cls, module_name): - super().__register__(module_name) - table = cls.__table_handler__(module_name) - - # Migration from 4.6: drop required on description - table.not_null_action('description', action='remove') - @staticmethod def default_type(): return 'line' diff --git a/modules/purchase/stock.py b/modules/purchase/stock.py index 86cafce348..93d02e39b7 100644 --- a/modules/purchase/stock.py +++ b/modules/purchase/stock.py @@ -2,10 +2,6 @@ # this repository contains the full copyright notices and license terms. from functools import wraps -from sql import Null -from sql.aggregate import Max -from sql.operators import Concat - from trytond.i18n import gettext from trytond.model import ModelView, Workflow, fields from trytond.model.exceptions import AccessError @@ -85,35 +81,6 @@ class ShipmentIn(metaclass=PoolMeta): class ShipmentInReturn(metaclass=PoolMeta): __name__ = 'stock.shipment.in.return' - @classmethod - def __register__(cls, module_name): - pool = Pool() - Move = pool.get('stock.move') - PurchaseLine = pool.get('purchase.line') - Purchase = pool.get('purchase.purchase') - cursor = Transaction().connection.cursor() - sql_table = cls.__table__() - move = Move.__table__() - line = PurchaseLine.__table__() - purchase = Purchase.__table__() - - # Migration from 3.8: New supplier field - cursor.execute(*sql_table.select(sql_table.supplier, - where=sql_table.supplier == Null, limit=1)) - if cursor.fetchone(): - value = sql_table.join(move, condition=( - Concat(cls.__name__ + ',', sql_table.id) == move.shipment) - ).join(line, condition=( - Concat(PurchaseLine.__name__ + ',', line.id) - == move.origin) - ).join(purchase, - condition=(purchase.id == line.purchase) - ).select(Max(purchase.party)) - cursor.execute(*sql_table.update( - columns=[sql_table.supplier], - values=[value])) - super(ShipmentInReturn, cls).__register__(module_name) - @classmethod @ModelView.button @Workflow.transition('draft') diff --git a/modules/purchase_request/purchase_request.py b/modules/purchase_request/purchase_request.py index 6372fc4247..0192fe5dea 100644 --- a/modules/purchase_request/purchase_request.py +++ b/modules/purchase_request/purchase_request.py @@ -122,63 +122,11 @@ class PurchaseRequest(ModelSQL, ModelView): @classmethod def __register__(cls, module_name): - pool = Pool() - ModelData = pool.get('ir.model.data') - Purchase = pool.get('purchase.purchase') - PurchaseLine = pool.get('purchase.line') - model_data = ModelData.__table__() - purchase = Purchase.__table__() - purchase_line = PurchaseLine.__table__() request = cls.__table__() - tablehandler = cls.__table_handler__(module_name) - state_exist = tablehandler.column_exist('state') - super(PurchaseRequest, cls).__register__(module_name) - # Migration from 3.6: removing the constraint on the quantity - tablehandler = cls.__table_handler__(module_name) - tablehandler.drop_constraint('check_purchase_request_quantity') - - # Migration from 3.8: renaming module of Purchase Request group entry cursor = Transaction().connection.cursor() - cursor.execute(*model_data.update( - columns=[model_data.module], - values=['purchase_request'], - where=((model_data.fs_id == 'group_purchase_request') - & (model_data.module == 'stock_supply')))) - - # Migration from 4.0: remove required on product and uom - tablehandler.not_null_action('product', action='remove') - tablehandler.not_null_action('uom', action='remove') - - # Migration from 4.2: add state - if not state_exist: - cursor = Transaction().connection.cursor() - update = Transaction().connection.cursor() - query = request.join(purchase_line, type_='INNER', - condition=request.purchase_line == purchase_line.id - ).join(purchase, type_='INNER', - condition=purchase_line.purchase == purchase.id - ).select( - request.id, purchase.state, request.exception_ignored) - cursor.execute(*query) - for request_id, purchase_state, exception_ignored in cursor: - if purchase_state == 'cancel' and not exception_ignored: - state = 'exception' - elif purchase_state == 'cancel': - state = 'cancel' - elif purchase_state == 'done': - state = 'done' - else: - state = 'purchased' - update.execute(*request.update( - [request.state], - [state], - where=request.id == request_id)) - - # Migration from 4.4: remove required on origin - tablehandler.not_null_action('origin', action='remove') # Migration from 5.6: rename state cancel to cancelled cursor.execute(*request.update( diff --git a/modules/purchase_requisition/purchase.py b/modules/purchase_requisition/purchase.py index 2dc23d153b..e9bf7f5591 100644 --- a/modules/purchase_requisition/purchase.py +++ b/modules/purchase_requisition/purchase.py @@ -5,7 +5,6 @@ from itertools import chain from sql.functions import CharLength -from trytond import backend from trytond.i18n import gettext from trytond.model import ( Index, ModelSQL, ModelView, Workflow, fields, sequence_ordered) @@ -57,25 +56,6 @@ class ConfigurationSequence(metaclass=PoolMeta): 'sequence_type_purchase_requisition')), ]) - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - if exist: - table = cls.__table_handler__(module_name) - exist &= table.column_exist('purchase_requisition_sequence') - - super(ConfigurationSequence, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('purchase_requisition_sequence') - value_names.append('purchase_requisition_sequence') - super(ConfigurationSequence, cls)._migrate_property( - field_names, value_names, fields) - @classmethod def default_purchase_requisition_sequence(cls): pool = Pool() diff --git a/modules/sale/configuration.py b/modules/sale/configuration.py index 3a1f68445d..14c01e8e97 100644 --- a/modules/sale/configuration.py +++ b/modules/sale/configuration.py @@ -1,13 +1,11 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond import backend from trytond.model import ( ModelSingleton, ModelSQL, ModelView, ValueMixin, fields) from trytond.modules.company.model import ( CompanyMultiValueMixin, CompanyValueMixin) from trytond.pool import Pool from trytond.pyson import Eval, Id, TimeDelta -from trytond.tools.multivalue import migrate_property sale_invoice_method = fields.Selection( 'get_sale_invoice_methods', "Sale Invoice Method") @@ -82,24 +80,6 @@ class ConfigurationSequence(ModelSQL, CompanyValueMixin): ('sequence_type', '=', Id('sale', 'sequence_type_sale')), ]) - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(ConfigurationSequence, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('sale_sequence') - value_names.append('sale_sequence') - fields.append('company') - migrate_property( - 'sale.configuration', field_names, cls, value_names, - fields=fields) - @classmethod def default_sale_sequence(cls): pool = Pool() @@ -118,23 +98,6 @@ class ConfigurationSaleMethod(ModelSQL, ValueMixin): sale_shipment_method = sale_shipment_method get_sale_shipment_methods = get_sale_methods('shipment_method') - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(ConfigurationSaleMethod, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.extend(['sale_invoice_method', 'sale_shipment_method']) - value_names.extend(['sale_invoice_method', 'sale_shipment_method']) - migrate_property( - 'sale.configuration', field_names, cls, value_names, - fields=fields) - @classmethod def default_sale_invoice_method(cls): return 'order' diff --git a/modules/sale/product.py b/modules/sale/product.py index 283ca99615..9c1f122225 100644 --- a/modules/sale/product.py +++ b/modules/sale/product.py @@ -61,30 +61,6 @@ class Template(metaclass=PoolMeta): lead_times = fields.One2Many( 'product.lead_time', 'template', "Lead Times") - @classmethod - def __register__(cls, module_name): - transaction = Transaction() - cursor = transaction.connection.cursor() - update = transaction.connection.cursor() - table = cls.__table_handler__(module_name) - sql_table = cls.__table__() - - super(Template, cls).__register__(module_name) - - # Migration from 3.8: change delivery_time into timedelta lead_time - if table.column_exist('delivery_time'): - cursor.execute(*sql_table.select( - sql_table.id, sql_table.delivery_time)) - for id_, delivery_time in cursor: - if delivery_time is None: - continue - lead_time = datetime.timedelta(days=delivery_time) - update.execute(*sql_table.update( - [sql_table.lead_time], - [lead_time], - where=sql_table.id == id_)) - table.drop_column('delivery_time') - @classmethod def multivalue_model(cls, field): pool = Pool() diff --git a/modules/sale/sale.py b/modules/sale/sale.py index 92704e5ba4..5c16a29598 100644 --- a/modules/sale/sale.py +++ b/modules/sale/sale.py @@ -361,19 +361,9 @@ class Sale( @classmethod def __register__(cls, module_name): cursor = Transaction().connection.cursor() - table = cls.__table_handler__(module_name) sql_table = cls.__table__() - # Migration from 3.8: rename reference into number - if (table.column_exist('reference') - and not table.column_exist('number')): - table.column_rename('reference', 'number') - super(Sale, cls).__register__(module_name) - table = cls.__table_handler__(module_name) - - # Migration from 4.0: Drop not null on payment_term - table.not_null_action('payment_term', 'remove') # Migration from 5.6: rename state cancel to cancelled cursor.execute(*sql_table.update( @@ -1347,14 +1337,6 @@ class SaleLine(TaxableMixin, sequence_ordered(), ModelSQL, ModelView): cls._order.insert(0, ('sale.sale_date', 'DESC NULLS FIRST')) cls._order.insert(1, ('sale.id', 'DESC')) - @classmethod - def __register__(cls, module_name): - super(SaleLine, cls).__register__(module_name) - table = cls.__table_handler__(module_name) - - # Migration from 4.6: drop required on description - table.not_null_action('description', action='remove') - @staticmethod def default_type(): return 'line' diff --git a/modules/sale_complaint/complaint.py b/modules/sale_complaint/complaint.py index ad40491f7d..bea78e13b3 100644 --- a/modules/sale_complaint/complaint.py +++ b/modules/sale_complaint/complaint.py @@ -195,11 +195,6 @@ class Complaint(Workflow, ModelSQL, ModelView): def __register__(cls, module_name): table_h = cls.__table_handler__(module_name) - # Migration from 3.8: rename reference into number - if (table_h.column_exist('reference') - and not table_h.column_exist('number')): - table_h.column_rename('reference', 'number') - # Migration from 6.4: rename employee into submitted_by if (table_h.column_exist('employee') and not table_h.column_exist('submitted_by')): diff --git a/modules/sale_complaint/sale.py b/modules/sale_complaint/sale.py index 7ab362f70a..c539a42dc1 100644 --- a/modules/sale_complaint/sale.py +++ b/modules/sale_complaint/sale.py @@ -1,7 +1,6 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond import backend from trytond.model import fields from trytond.pool import Pool, PoolMeta from trytond.pyson import Eval, Id @@ -42,25 +41,6 @@ class ConfigurationSequence(metaclass=PoolMeta): ('company', 'in', [Eval('company', -1), None]), ]) - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - if exist: - table = cls.__table_handler__(module_name) - exist &= table.column_exist('complaint_sequence') - - super(ConfigurationSequence, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('complaint_sequence') - value_names.append('complaint_sequence') - super(ConfigurationSequence, cls)._migrate_property( - field_names, value_names, fields) - @classmethod def default_complaint_sequence(cls): pool = Pool() diff --git a/modules/sale_extra/sale.py b/modules/sale_extra/sale.py index 0263ae17ad..dfc5b74f92 100644 --- a/modules/sale_extra/sale.py +++ b/modules/sale_extra/sale.py @@ -3,8 +3,6 @@ import datetime from decimal import Decimal -from sql import Null - from trytond.model import ( DeactivableMixin, MatchMixin, ModelSQL, ModelView, Workflow, fields, sequence_ordered) @@ -100,31 +98,6 @@ class Extra(DeactivableMixin, ModelSQL, ModelView, MatchMixin): 'on_change_with_currency') lines = fields.One2Many('sale.extra.line', 'extra', 'Lines') - @classmethod - def __register__(cls, module_name): - pool = Pool() - PriceList = pool.get('product.price_list') - transaction = Transaction() - cursor = transaction.connection.cursor() - update = transaction.connection.cursor() - sql_table = cls.__table__() - price_list = PriceList.__table__() - - super().__register__(module_name) - - table = cls.__table_handler__(module_name) - # Migration from 3.6: price_list not required and new company - table.not_null_action('price_list', 'remove') - query = sql_table.join(price_list, - condition=sql_table.price_list == price_list.id - ).select(sql_table.id, price_list.company, - where=sql_table.company == Null) - cursor.execute(*query) - for extra_id, company_id in cursor: - query = sql_table.update([sql_table.company], [company_id], - where=sql_table.id == extra_id) - update.execute(*query) - @staticmethod def default_company(): return Transaction().context.get('company') diff --git a/modules/sale_invoice_grouping/party.py b/modules/sale_invoice_grouping/party.py index 7b22e657d6..5080435792 100644 --- a/modules/sale_invoice_grouping/party.py +++ b/modules/sale_invoice_grouping/party.py @@ -1,9 +1,7 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of this # repository contains the full copyright notices and license terms. -from trytond import backend from trytond.model import ModelSQL, ValueMixin, fields from trytond.pool import Pool, PoolMeta -from trytond.tools.multivalue import migrate_property class Party(metaclass=PoolMeta): @@ -34,23 +32,6 @@ class PartySaleInvoiceGroupingMethod(ModelSQL, ValueMixin): sale_invoice_grouping_method = fields.Selection( 'get_sale_invoice_grouping_methods', "Sale Invoice Grouping Method") - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(PartySaleInvoiceGroupingMethod, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('sale_invoice_grouping_method') - value_names.append('sale_invoice_grouping_method') - migrate_property( - 'party.party', field_names, cls, value_names, - parent='party', fields=fields) - @classmethod def get_sale_invoice_grouping_methods(cls): pool = Pool() diff --git a/modules/sale_opportunity/configuration.py b/modules/sale_opportunity/configuration.py index d4c51df144..64ed7ea0a5 100644 --- a/modules/sale_opportunity/configuration.py +++ b/modules/sale_opportunity/configuration.py @@ -1,6 +1,5 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond import backend from trytond.model import fields from trytond.pool import Pool, PoolMeta from trytond.pyson import Eval, Id @@ -41,25 +40,6 @@ class ConfigurationSequence(metaclass=PoolMeta): Id('sale_opportunity', 'sequence_type_sale_opportunity')), ]) - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - if exist: - table = cls.__table_handler__(module_name) - exist &= table.column_exist('sale_opportunity_sequence') - - super(ConfigurationSequence, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('sale_opportunity_sequence') - value_names.append('sale_opportunity_sequence') - super(ConfigurationSequence, cls)._migrate_property( - field_names, value_names, fields) - @classmethod def default_sale_opportunity_sequence(cls): pool = Pool() diff --git a/modules/sale_opportunity/opportunity.py b/modules/sale_opportunity/opportunity.py index b195e4f2ba..1af82b4706 100644 --- a/modules/sale_opportunity/opportunity.py +++ b/modules/sale_opportunity/opportunity.py @@ -4,7 +4,6 @@ import datetime from itertools import groupby -from sql import Null from sql.functions import CharLength from trytond.i18n import gettext @@ -127,48 +126,15 @@ class SaleOpportunity( def __register__(cls, module_name): pool = Pool() Company = pool.get('company.company') - Sale = pool.get('sale.sale') transaction = Transaction() cursor = transaction.connection.cursor() - update = transaction.connection.cursor() sql_table = cls.__table__() company = Company.__table__() - sale = Sale.__table__() table = cls.__table_handler__(module_name) - number_exists = table.column_exist('number') currency_exists = table.column_exist('currency') - # Migration from 3.8: rename reference into number - if table.column_exist('reference') and not number_exists: - table.column_rename('reference', 'number') - number_exists = True - super(SaleOpportunity, cls).__register__(module_name) - table = cls.__table_handler__(module_name) - - # Migration from 3.4: replace sale by origin - if table.column_exist('sale'): - cursor.execute(*sql_table.select( - sql_table.id, sql_table.sale, - where=sql_table.sale != Null)) - for id_, sale_id in cursor: - update.execute(*sale.update( - columns=[sale.origin], - values=['%s,%s' % (cls.__name__, id_)], - where=sale.id == sale_id)) - table.drop_column('sale') - - # Migration from 4.0: change probability into conversion probability - if table.column_exist('probability'): - cursor.execute(*sql_table.update( - [sql_table.conversion_probability], - [sql_table.probability / 100.0])) - table.drop_constraint('check_percentage') - table.drop_column('probability') - - # Migration from 4.2: make employee not required - table.not_null_action('employee', action='remove') # Migration from 5.0: drop required on description table.not_null_action('description', action='remove') diff --git a/modules/sale_price_list/party.py b/modules/sale_price_list/party.py index 9a47b8ecfd..471abce368 100644 --- a/modules/sale_price_list/party.py +++ b/modules/sale_price_list/party.py @@ -1,12 +1,10 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond import backend from trytond.model import ModelSQL, fields from trytond.modules.company.model import ( CompanyMultiValueMixin, CompanyValueMixin) from trytond.pool import Pool, PoolMeta from trytond.pyson import Eval -from trytond.tools.multivalue import migrate_property from trytond.transaction import Transaction @@ -57,21 +55,3 @@ class PartySalePriceList(ModelSQL, CompanyValueMixin): domain=[ ('company', '=', Eval('company', -1)), ]) - - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(PartySalePriceList, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('sale_price_list') - value_names.append('sale_price_list') - fields.append('company') - migrate_property( - 'party.party', field_names, cls, value_names, - parent='party', fields=fields) diff --git a/modules/sale_shipment_cost/sale.py b/modules/sale_shipment_cost/sale.py index 6098988426..abf775e619 100644 --- a/modules/sale_shipment_cost/sale.py +++ b/modules/sale_shipment_cost/sale.py @@ -2,7 +2,6 @@ # this repository contains the full copyright notices and license terms. from decimal import Decimal -from trytond import backend from trytond.i18n import gettext from trytond.model import ModelView, Workflow, fields from trytond.modules.product import price_digits, round_price @@ -48,25 +47,6 @@ class ConfigurationSaleMethod(metaclass=PoolMeta): sale_shipment_cost_method = sale_shipment_cost_method get_sale_shipment_cost_methods = get_sale_methods('shipment_cost_method') - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - if exist: - table = cls.__table_handler__(module_name) - exist &= table.column_exist('sale_shipment_cost_method') - - super(ConfigurationSaleMethod, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('sale_shipment_cost_method') - value_names.append('sale_shipment_cost_method') - super(ConfigurationSaleMethod, cls)._migrate_property( - field_names, value_names, fields) - @classmethod def default_sale_shipment_cost_method(cls): return 'order' diff --git a/modules/sale_shipment_grouping/party.py b/modules/sale_shipment_grouping/party.py index 064498b541..0b42084937 100644 --- a/modules/sale_shipment_grouping/party.py +++ b/modules/sale_shipment_grouping/party.py @@ -1,9 +1,7 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of this # repository contains the full copyright notices and license terms. -from trytond import backend from trytond.model import ModelSQL, ValueMixin, fields from trytond.pool import Pool, PoolMeta -from trytond.tools.multivalue import migrate_property class Party(metaclass=PoolMeta): @@ -34,23 +32,6 @@ class PartySaleShipmentGroupingMethod(ModelSQL, ValueMixin): sale_shipment_grouping_method = fields.Selection( 'get_sale_shipment_grouping_methods', "Sale Shipment Grouping Method") - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(PartySaleShipmentGroupingMethod, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('sale_shipment_grouping_method') - value_names.append('sale_shipment_grouping_method') - migrate_property( - 'party.party', field_names, cls, value_names, - parent='party', fields=fields) - @classmethod def get_sale_shipment_grouping_methods(cls): pool = Pool() diff --git a/modules/sale_subscription/subscription.py b/modules/sale_subscription/subscription.py index 51919f4ca8..ea81b900e3 100644 --- a/modules/sale_subscription/subscription.py +++ b/modules/sale_subscription/subscription.py @@ -7,7 +7,6 @@ from sql import Literal, Null, operators from sql.conditionals import Case, Coalesce from sql.functions import CharLength -from trytond import backend from trytond.i18n import gettext from trytond.model import ( Index, ModelSQL, ModelView, Workflow, fields, sequence_ordered) @@ -610,30 +609,13 @@ class Line(sequence_ordered(), ModelSQL, ModelView): @classmethod def __register__(cls, module): - pool = Pool() - Subscription = pool.get('sale.subscription') transaction = Transaction() cursor = transaction.connection.cursor() table = cls.__table__() - subscription = Subscription.__table__() - - # Migration from 4.8: start_date required - if backend.TableHandler.table_exist(cls._table): - table_h = cls.__table_handler__(module) - if table_h.column_exist('start_date'): - cursor.execute(*table.update( - [table.start_date], - subscription.select( - subscription.start_date, - where=subscription.id == table.subscription), - where=table.start_date == Null)) super(Line, cls).__register__(module) table_h = cls.__table_handler__(module) - # Migration from 4.8: drop required on description - table_h.not_null_action('description', action='remove') - # Migration from 5.2: replace consumed by consumed_until if table_h.column_exist('consumed'): cursor.execute(*table.update( diff --git a/modules/sale_supply_drop_shipment/purchase.py b/modules/sale_supply_drop_shipment/purchase.py index 7ba0e8c2ae..3f02aa5762 100644 --- a/modules/sale_supply_drop_shipment/purchase.py +++ b/modules/sale_supply_drop_shipment/purchase.py @@ -1,6 +1,5 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond import backend from trytond.i18n import gettext from trytond.model import ModelSQL, ValueMixin, fields from trytond.model.exceptions import RequiredValidationError @@ -9,7 +8,6 @@ from trytond.modules.purchase.purchase import ( get_shipments_returns, search_shipments_returns) from trytond.pool import Pool, PoolMeta from trytond.pyson import Eval -from trytond.tools.multivalue import migrate_property from trytond.transaction import Transaction purchase_drop_location = fields.Many2One( @@ -51,23 +49,6 @@ class ConfigurationPurchaseDropLocation(ModelSQL, ValueMixin): __name__ = 'purchase.configuration.purchase_drop_location' purchase_drop_location = purchase_drop_location - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super().__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('purchase_drop_location') - value_names.append('purchase_drop_location') - migrate_property( - 'purchase.configuration', field_names, cls, value_names, - fields=fields) - @classmethod def default_purchase_drop_location(cls): pool = Pool() diff --git a/modules/sale_supply_drop_shipment/sale.py b/modules/sale_supply_drop_shipment/sale.py index 23c7bc3b2d..d987e5f2c9 100644 --- a/modules/sale_supply_drop_shipment/sale.py +++ b/modules/sale_supply_drop_shipment/sale.py @@ -1,12 +1,10 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond import backend from trytond.model import ModelSQL, ValueMixin, fields from trytond.modules.sale.sale import ( get_shipments_returns, search_shipments_returns) from trytond.pool import Pool, PoolMeta from trytond.pyson import Eval -from trytond.tools.multivalue import migrate_property sale_drop_location = fields.Many2One( 'stock.location', "Sale Drop Location", domain=[('type', '=', 'drop')]) @@ -28,23 +26,6 @@ class ConfigurationSaleDropLocation(ModelSQL, ValueMixin): __name__ = 'sale.configuration.sale_drop_location' sale_drop_location = sale_drop_location - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super().__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('sale_drop_location') - value_names.append('sale_drop_location') - migrate_property( - 'sale.configuration', field_names, cls, value_names, - fields=fields) - @classmethod def default_sale_drop_location(cls): pool = Pool() diff --git a/modules/sale_supply_drop_shipment/stock.py b/modules/sale_supply_drop_shipment/stock.py index 72d493b787..10952cd277 100644 --- a/modules/sale_supply_drop_shipment/stock.py +++ b/modules/sale_supply_drop_shipment/stock.py @@ -4,13 +4,9 @@ from collections import defaultdict from decimal import Decimal from itertools import groupby -from sql import Column -from sql.aggregate import Count from sql.conditionals import Coalesce from sql.functions import CharLength -from sql.operators import Concat -from trytond import backend from trytond.i18n import gettext from trytond.model import Index, ModelSQL, ModelView, Workflow, fields from trytond.model.exceptions import AccessError @@ -19,7 +15,7 @@ from trytond.modules.purchase.stock import process_purchase from trytond.modules.sale.stock import process_sale from trytond.pool import Pool, PoolMeta from trytond.pyson import Eval, Id, If -from trytond.tools import cursor_dict, grouped_slice +from trytond.tools import grouped_slice from trytond.transaction import Transaction @@ -60,25 +56,6 @@ class ConfigurationSequence(metaclass=PoolMeta): 'sequence_type_shipment_drop')), ]) - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - if exist: - table = cls.__table_handler__(module_name) - exist &= table.column_exist('shipment_drop_sequence') - - super(ConfigurationSequence, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('shipment_drop_sequence') - value_names.append('shipment_drop_sequence') - super(ConfigurationSequence, cls)._migrate_property( - field_names, value_names, fields) - @classmethod def default_shipment_drop_sequence(cls): pool = Pool() @@ -185,18 +162,7 @@ class ShipmentDrop(Workflow, ModelSQL, ModelView): @classmethod def __register__(cls, module_name): - pool = Pool() - Move = pool.get('stock.move') - PurchaseLine = pool.get('purchase.line') - PurchaseRequest = pool.get('purchase.request') - SaleLine = pool.get('sale.line') - Location = pool.get('stock.location') table = cls.__table__() - move = Move.__table__() - purchase_line = PurchaseLine.__table__() - purchase_request = PurchaseRequest.__table__() - sale_line = SaleLine.__table__() - location = Location.__table__() cursor = Transaction().connection.cursor() table_h = cls.__table_handler__(module_name) @@ -206,56 +172,6 @@ class ShipmentDrop(Workflow, ModelSQL, ModelView): super(ShipmentDrop, cls).__register__(module_name) - # Migration from 3.6 - cursor.execute(*location.select(Count(location.id), - where=(location.type == 'drop'))) - has_drop_shipment, = cursor.fetchone() - - if not has_drop_shipment: - drop_shipment = Location(name='Migration Drop Shipment', - type='drop', active=False) - drop_shipment.save() - drop_shipment_location = drop_shipment.id - - move_sale_query = move.join(purchase_line, - condition=move.origin == Concat('purchase.line,', - purchase_line.id) - ).join(purchase_request, - condition=purchase_request.purchase_line == purchase_line.id - ).join(sale_line, - condition=sale_line.purchase_request == purchase_request.id - ).select( - move.id, move.to_location, sale_line.id, - where=move.shipment.like('stock.shipment.drop,%')) - cursor.execute(*move_sale_query) - move_sales = cursor.fetchall() - - for sub_move in grouped_slice(move_sales): - sub_ids = [s[0] for s in sub_move] - cursor.execute(*move.update( - columns=[move.to_location], - values=[drop_shipment_location], - where=move.id.in_(sub_ids))) - - cursor.execute(*move.select(limit=1)) - moves = list(cursor_dict(cursor)) - if moves: - move_columns = moves[0].keys() - columns = [Column(move, c) for c in move_columns if c != 'id'] - create_move = move.insert( - columns=columns, values=move.select( - *columns, - where=move.shipment.like('stock.shipment.drop,%'))) - cursor.execute(*create_move) - - for move_id, customer_location, line_id in move_sales: - cursor.execute(*move.update( - columns=[move.origin, move.from_location, - move.to_location], - values=[Concat('sale.line,', str(line_id)), - drop_shipment_location, customer_location], - where=(move.id == move_id))) - # Migration from 5.6: rename state cancel to cancelled cursor.execute(*table.update( [table.state], ['cancelled'], diff --git a/modules/stock/configuration.py b/modules/stock/configuration.py index 3ed92cf479..ae9a2efd9b 100644 --- a/modules/stock/configuration.py +++ b/modules/stock/configuration.py @@ -1,13 +1,11 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond import backend from trytond.model import ( ModelSingleton, ModelSQL, ModelView, ValueMixin, fields) from trytond.modules.company.model import ( CompanyMultiValueMixin, CompanyValueMixin) from trytond.pool import Pool from trytond.pyson import Eval, Id -from trytond.tools.multivalue import migrate_property sequences = ['shipment_in_sequence', 'shipment_in_return_sequence', 'shipment_out_sequence', 'shipment_out_return_sequence', @@ -175,24 +173,6 @@ class ConfigurationSequence(ModelSQL, CompanyValueMixin): Id('stock', 'sequence_type_inventory')), ]) - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(ConfigurationSequence, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.extend(sequences) - value_names.extend(sequences) - fields.append('company') - migrate_property( - 'stock.configuration', field_names, cls, value_names, - fields=fields) - default_shipment_in_sequence = default_sequence('sequence_shipment_in') default_shipment_in_return_sequence = default_sequence( 'sequence_shipment_in_return') @@ -209,23 +189,6 @@ class ConfigurationLocation(ModelSQL, ValueMixin): __name__ = 'stock.configuration.location' shipment_internal_transit = shipment_internal_transit - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super(ConfigurationLocation, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('shipment_internal_transit') - value_names.append('shipment_internal_transit') - migrate_property( - 'stock.configuration', field_names, cls, value_names, - fields=fields) - @classmethod def default_shipment_internal_transit(cls): pool = Pool() diff --git a/modules/stock/inventory.py b/modules/stock/inventory.py index 869cd09a07..daa7f334e6 100644 --- a/modules/stock/inventory.py +++ b/modules/stock/inventory.py @@ -2,8 +2,6 @@ # this repository contains the full copyright notices and license terms. from collections import defaultdict -from sql import Null - from trytond.i18n import gettext from trytond.model import ( Check, Index, Model, ModelSQL, ModelView, Workflow, fields) @@ -373,34 +371,6 @@ class InventoryLine(ModelSQL, ModelView): ] cls._order.insert(0, ('product', 'ASC')) - @classmethod - def __register__(cls, module_name): - transaction = Transaction() - cursor = transaction.connection.cursor() - update = transaction.connection.cursor() - pool = Pool() - Move = pool.get('stock.move') - sql_table = cls.__table__() - move_table = Move.__table__() - - super(InventoryLine, cls).__register__(module_name) - - table = cls.__table_handler__(module_name) - - # Migration from 3.0: use Move origin - if table.column_exist('move'): - cursor.execute(*sql_table.select(sql_table.id, sql_table.move, - where=sql_table.move != Null)) - for line_id, move_id in cursor: - update.execute(*move_table.update( - columns=[move_table.origin], - values=['%s,%s' % (cls.__name__, line_id)], - where=move_table.id == move_id)) - table.drop_column('move') - - # Migration from 4.6: drop required on quantity - table.not_null_action('quantity', action='remove') - @staticmethod def default_expected_quantity(): return 0. diff --git a/modules/stock/party.py b/modules/stock/party.py index d0bbc151dd..012e1bcb6e 100644 --- a/modules/stock/party.py +++ b/modules/stock/party.py @@ -1,11 +1,9 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond import backend from trytond.i18n import gettext from trytond.model import ModelSQL, ValueMixin, fields from trytond.modules.party.exceptions import EraseError from trytond.pool import Pool, PoolMeta -from trytond.tools.multivalue import migrate_property from trytond.transaction import Transaction supplier_location = fields.Many2One( @@ -70,23 +68,6 @@ class PartyLocation(ModelSQL, ValueMixin): supplier_location = supplier_location customer_location = customer_location - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - - super().__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.extend(['supplier_location', 'customer_location']) - value_names.extend(['supplier_location', 'customer_location']) - migrate_property( - 'party.party', field_names, cls, value_names, - parent='party', fields=fields) - @classmethod def default_supplier_location(cls): pool = Pool() diff --git a/modules/stock/shipment.py b/modules/stock/shipment.py index 26d47feb36..dfdf96ea1c 100644 --- a/modules/stock/shipment.py +++ b/modules/stock/shipment.py @@ -328,14 +328,9 @@ class ShipmentIn(ShipmentMixin, Workflow, ModelSQL, ModelView): pool = Pool() Location = pool.get('stock.location') cursor = Transaction().connection.cursor() - table = cls.__table_handler__(module_name) sql_table = cls.__table__() location = Location.__table__() - # Migration from 3.8: rename code into number - if table.column_exist('code'): - table.column_rename('code', 'number') - super(ShipmentIn, cls).__register__(module_name) # Migration from 5.6: rename state cancel to cancelled @@ -779,13 +774,8 @@ class ShipmentInReturn(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): @classmethod def __register__(cls, module_name): cursor = Transaction().connection.cursor() - table = cls.__table_handler__(module_name) sql_table = cls.__table__() - # Migration from 3.8: rename code into number - if table.column_exist('code'): - table.column_rename('code', 'number') - super(ShipmentInReturn, cls).__register__(module_name) # Migration from 5.6: rename state cancel to cancelled @@ -1274,10 +1264,6 @@ class ShipmentOut(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): sql_table = cls.__table__() location = Location.__table__() - # Migration from 3.8: rename code into number - if table.column_exist('code'): - table.column_rename('code', 'number') - # Migration from 5.6: rename assigned_by into picked_by if table.column_exist('assigned_by'): table.column_rename('assigned_by', 'picked_by') @@ -1935,10 +1921,6 @@ class ShipmentOutReturn(ShipmentMixin, Workflow, ModelSQL, ModelView): sql_table = cls.__table__() location = Location.__table__() - # Migration from 3.8: rename code into number - if table.column_exist('code'): - table.column_rename('code', 'number') - # Migration from 6.4: rename delivery_address to contact_address table.column_rename('delivery_address', 'contact_address') @@ -2478,22 +2460,8 @@ class ShipmentInternal(ShipmentAssignMixin, Workflow, ModelSQL, ModelView): def __register__(cls, module_name): cursor = Transaction().connection.cursor() sql_table = cls.__table__() - table = cls.__table_handler__(module_name) - - # Migration from 3.8: - if table.column_exist('code'): - table.column_rename('code', 'number') super(ShipmentInternal, cls).__register__(module_name) - - # Migration from 4.0: fill planned_start_date - cursor = Transaction().connection.cursor() - cursor.execute(*sql_table.update( - [sql_table.planned_start_date], - [sql_table.planned_date], - where=(sql_table.planned_start_date == Null) - & (sql_table.planned_date != Null))) - # Migration from 5.6: rename state cancel to cancelled cursor.execute(*sql_table.update( [sql_table.state], ['cancelled'], diff --git a/modules/stock_package/stock.py b/modules/stock_package/stock.py index 4dd9fc476d..d8a709c0a7 100644 --- a/modules/stock_package/stock.py +++ b/modules/stock_package/stock.py @@ -3,7 +3,6 @@ from sql import Cast, Literal from sql.functions import CharLength, Position, Substring -from trytond import backend from trytond.i18n import gettext from trytond.model import ( DeactivableMixin, ModelSQL, ModelView, Workflow, fields, tree) @@ -48,25 +47,6 @@ class ConfigurationSequence(metaclass=PoolMeta): Id('stock_package', 'sequence_type_package')), ]) - @classmethod - def __register__(cls, module_name): - exist = backend.TableHandler.table_exist(cls._table) - if exist: - table = cls.__table_handler__(module_name) - exist &= table.column_exist('package_sequence') - - super(ConfigurationSequence, cls).__register__(module_name) - - if not exist: - cls._migrate_property([], [], []) - - @classmethod - def _migrate_property(cls, field_names, value_names, fields): - field_names.append('package_sequence') - value_names.append('package_sequence') - super(ConfigurationSequence, cls)._migrate_property( - field_names, value_names, fields) - @classmethod def default_package_sequence(cls): pool = Pool() diff --git a/modules/stock_package_shipping/stock.py b/modules/stock_package_shipping/stock.py index 010dd0350e..cf1977d528 100644 --- a/modules/stock_package_shipping/stock.py +++ b/modules/stock_package_shipping/stock.py @@ -209,23 +209,6 @@ class ShippingMixin: class ShipmentOut(ShippingMixin, metaclass=PoolMeta): __name__ = 'stock.shipment.out' - @classmethod - def __register__(cls, module): - pool = Pool() - ModelData = pool.get('ir.model.data') - model_data = ModelData.__table__() - cursor = Transaction().connection.cursor() - super(ShipmentOut, cls).__register__(module) - - # Migration from 4.6: rename create_shipping xml id - if module == 'stock_package_shipping': - cursor.execute(*model_data.update( - [model_data.fs_id], - ['shipment_out_create_shipping_button'], - where=(model_data.module == module) - & (model_data.model == 'ir.model.button') - & (model_data.fs_id == 'create_shipping_button'))) - @classmethod @Workflow.transition('packed') def pack(cls, shipments): diff --git a/modules/stock_supply/order_point.py b/modules/stock_supply/order_point.py index a238bed7b9..bdbca89ee6 100644 --- a/modules/stock_supply/order_point.py +++ b/modules/stock_supply/order_point.py @@ -1,7 +1,5 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from sql import Null - from trytond.i18n import gettext from trytond.model import ModelSQL, ModelView, fields from trytond.pool import Pool @@ -105,26 +103,6 @@ class OrderPoint(ModelSQL, ModelView): ]) unit = fields.Function(fields.Many2One('product.uom', 'Unit'), 'get_unit') - @classmethod - def __register__(cls, module_name): - cursor = Transaction().connection.cursor() - sql_table = cls.__table__() - table = cls.__table_handler__(module_name) - - # Migration from 4.2 - table.drop_constraint('check_max_qty_greater_min_qty') - table.not_null_action('min_quantity', 'remove') - table.not_null_action('max_quantity', 'remove') - target_qty_exist = table.column_exist('target_quantity') - - super(OrderPoint, cls).__register__(module_name) - - # Migration from 4.2 - if not target_qty_exist: - cursor.execute(*sql_table.update( - [sql_table.target_quantity, sql_table.max_quantity], - [sql_table.max_quantity, Null])) - @staticmethod def default_type(): return "purchase" diff --git a/modules/timesheet/line.py b/modules/timesheet/line.py index 20cf6e574c..6c302a536e 100644 --- a/modules/timesheet/line.py +++ b/modules/timesheet/line.py @@ -95,40 +95,6 @@ class Line(ModelSQL, ModelView): (t.employee, Index.Equality())), }) - @classmethod - def __register__(cls, module_name): - transaction = Transaction() - cursor = transaction.connection.cursor() - update = transaction.connection.cursor() - table = cls.__table_handler__(module_name) - sql_table = cls.__table__() - pool = Pool() - Work = pool.get('timesheet.work') - work = Work.__table__() - - created_company = not table.column_exist('company') - - super(Line, cls).__register__(module_name) - - # Migration from 3.4: new company field - if created_company: - # Don't use FROM because SQLite nor MySQL support it. - update.execute(*sql_table.update( - [sql_table.company], [work.select(work.company, - where=work.id == sql_table.work)])) - # Migration from 3.4: change hours into timedelta duration - if table.column_exist('hours'): - table.drop_constraint('check_move_hours_pos') - cursor.execute(*sql_table.select( - sql_table.id, sql_table.hours)) - for id_, hours in cursor: - duration = datetime.timedelta(hours=hours) - update.execute(*sql_table.update( - [sql_table.duration], - [duration], - where=sql_table.id == id_)) - table.drop_column('hours') - @staticmethod def default_company(): return Transaction().context.get('company') diff --git a/modules/timesheet/work.py b/modules/timesheet/work.py index 53d90612a5..2d3e6092d2 100644 --- a/modules/timesheet/work.py +++ b/modules/timesheet/work.py @@ -67,45 +67,6 @@ class Work(ModelSQL, ModelView): 'timesheet.msg_work_origin_unique_company'), ] - @classmethod - def __register__(cls, module_name): - table_h = cls.__table_handler__(module_name) - table = cls.__table__() - cursor = Transaction().connection.cursor() - - super(Work, cls).__register__(module_name) - - # Migration from 4.0: remove required on name - table_h.not_null_action('name', 'remove') - - # Migration from 4.0: remove parent, left and right - if table_h.column_exist('parent'): - id2name = {} - id2parent = {} - cursor.execute(*table.select( - table.id, table.parent, table.name)) - for id_, parent, name in cursor: - id2name[id_] = name - id2parent[id_] = parent - - for id_, name in id2name.items(): - parent = id2parent[id_] - while parent: - name = '%s\\%s' % (id2name[parent], name) - parent = id2parent[parent] - cursor.execute(*table.update( - [table.name], [name], - where=table.id == id_)) - table_h.drop_column('parent') - table_h.drop_column('left') - table_h.drop_column('right') - - # Migration from 4.0: remove timesheet_available - if table_h.column_exist('timesheet_available'): - cursor.execute(*table.delete( - where=table.timesheet_available == Literal(False))) - table_h.drop_column('timesheet_available') - @staticmethod def default_company(): return Transaction().context.get('company') diff --git a/modules/timesheet_cost/timesheet.py b/modules/timesheet_cost/timesheet.py index 2003ca9b2e..f5c6c3b43f 100644 --- a/modules/timesheet_cost/timesheet.py +++ b/modules/timesheet_cost/timesheet.py @@ -1,10 +1,9 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from sql import Null from trytond.model import fields -from trytond.pool import Pool, PoolMeta -from trytond.transaction import Transaction, without_check_access +from trytond.pool import PoolMeta +from trytond.transaction import without_check_access from .company import price_digits @@ -15,35 +14,6 @@ class Line(metaclass=PoolMeta): cost_price = fields.Numeric('Cost Price', digits=price_digits, required=True, readonly=True) - @classmethod - def __register__(cls, module_name): - pool = Pool() - Employee = pool.get('company.employee') - - transaction = Transaction() - cursor = transaction.connection.cursor() - update = transaction.connection.cursor() - table = cls.__table__() - table_h = cls.__table_handler__(module_name) - - migrate_cost_price = not table_h.column_exist('cost_price') - - super().__register__(module_name) - - # Migration from 3.6: add cost_price - if migrate_cost_price: - cursor.execute(*table.select(table.id, table.employee, table.date, - where=(table.cost_price == 0) - & (table.employee != Null) - & (table.date != Null))) - for line_id, employee_id, date in cursor: - employee = Employee(employee_id) - cost_price = employee.compute_cost_price(date=date) - update.execute(*table.update( - [table.cost_price], - [cost_price], - where=table.id == line_id)) - @classmethod def default_cost_price(cls): # Needed at creation as cost_price is required diff --git a/modules/web_user/user.py b/modules/web_user/user.py index e1c0a498cd..549f96a4af 100644 --- a/modules/web_user/user.py +++ b/modules/web_user/user.py @@ -111,18 +111,6 @@ class User(avatar_mixin(100), DeactivableMixin, ModelSQL, ModelView): }, }) - @classmethod - def __register__(cls, module_name): - super(User, cls).__register__(module_name) - - table_h = cls.__table_handler__(module_name) - - # Migration from 4.6 - table_h.not_null_action('email', 'remove') - - # Migration from 4.6: replace unique by exclude - table_h.drop_constraint('email_unique') - @classmethod def default_email_valid(cls): return False diff --git a/trytond/trytond/backend/sqlite/table.py b/trytond/trytond/backend/sqlite/table.py index 5701a33a44..b2af7da8c7 100644 --- a/trytond/trytond/backend/sqlite/table.py +++ b/trytond/trytond/backend/sqlite/table.py @@ -55,31 +55,6 @@ class TableHandler(TableHandlerInterface): res = cursor.fetchone() if not res: return False - sql, = res - - # Migration from 1.6 add autoincrement - - if 'AUTOINCREMENT' not in sql.upper(): - temp_sql = sql.replace(table_name, '_temp_%s' % table_name) - cursor.execute(temp_sql) - cursor.execute('PRAGMA table_info("' + table_name + '")') - columns = [_escape_identifier(column) - for _, column, _, _, _, _ in cursor] - cursor.execute(('INSERT INTO %s ' - '(' + ','.join(columns) + ') ' - 'SELECT ' + ','.join(columns) - + ' FROM %s') % ( - _escape_identifier('_temp_' + table_name), - _escape_identifier(table_name))) - cursor.execute('DROP TABLE %s' % _escape_identifier(table_name)) - new_sql = sql.replace('PRIMARY KEY', - 'PRIMARY KEY AUTOINCREMENT') - cursor.execute(new_sql) - cursor.execute(('INSERT INTO "%s" ' - '(' + ','.join(columns) + ') ' - 'SELECT ' + ','.join(columns) - + ' FROM "_temp_%s"') % (table_name, table_name)) - cursor.execute('DROP TABLE "_temp_%s"' % table_name) return True @classmethod diff --git a/trytond/trytond/ir/action.py b/trytond/trytond/ir/action.py index e0cd5b89f3..ff111a9ec8 100644 --- a/trytond/trytond/ir/action.py +++ b/trytond/trytond/ir/action.py @@ -6,7 +6,6 @@ from functools import partial from operator import itemgetter from genshi.template.text import TextTemplate -from sql import Null from trytond.cache import Cache, MemoryCache from trytond.config import config @@ -576,24 +575,6 @@ class ActionReport(ActionMixin, ModelSQL, ModelView): module = fields.Char('Module', readonly=True) _template_cache = MemoryCache('ir.action.report.template', context=False) - @classmethod - def __register__(cls, module_name): - super(ActionReport, cls).__register__(module_name) - - transaction = Transaction() - cursor = transaction.connection.cursor() - table = cls.__table_handler__(module_name) - action_report = cls.__table__() - - # Migration from 3.4 remove report_name_module_uniq constraint - table.drop_constraint('report_name_module_uniq') - - # Migration from 4.4 replace plain extension by txt - cursor.execute(*action_report.update( - [action_report.extension], - ['txt'], - where=action_report.extension == 'plain')) - @staticmethod def default_type(): return 'ir.action.report' @@ -774,26 +755,6 @@ class ActionActWindow(ActionMixin, ModelSQL, ModelView): 'get': RPC(cache=dict(days=1)), }) - @classmethod - def __register__(cls, module_name): - cursor = Transaction().connection.cursor() - act_window = cls.__table__() - super(ActionActWindow, cls).__register__(module_name) - - table = cls.__table_handler__(module_name) - - # Migration from 3.0: auto_refresh removed - table.drop_column('auto_refresh') - - # Migration from 4.0: window_name removed - table.drop_column('window_name') - - # Migration from 4.2: remove required on limit - table.not_null_action('limit', 'remove') - cursor.execute(*act_window.update( - [act_window.limit], [Null], - where=act_window.limit == 0)) - @staticmethod def default_type(): return 'ir.action.act_window' diff --git a/trytond/trytond/ir/attachment.py b/trytond/trytond/ir/attachment.py index 15ff53739f..8afdb32edf 100644 --- a/trytond/trytond/ir/attachment.py +++ b/trytond/trytond/ir/attachment.py @@ -1,8 +1,5 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from sql import Null -from sql.operators import Concat - from trytond.config import config from trytond.i18n import lazy_gettext from trytond.model import ModelSQL, ModelView, fields @@ -55,34 +52,6 @@ class Attachment(ResourceMixin, ModelSQL, ModelView): ('id', 'DESC'), ] - @classmethod - def __register__(cls, module_name): - cursor = Transaction().connection.cursor() - - super(Attachment, cls).__register__(module_name) - - table = cls.__table_handler__(module_name) - attachment = cls.__table__() - - # Migration from 4.0: merge digest and collision into file_id - if table.column_exist('digest') and table.column_exist('collision'): - cursor.execute(*attachment.update( - [attachment.file_id], - [attachment.digest], - where=(attachment.collision == 0) - | (attachment.collision == Null))) - cursor.execute(*attachment.update( - [attachment.file_id], - [Concat(Concat(attachment.digest, '-'), - attachment.collision)], - where=(attachment.collision != 0) - & (attachment.collision != Null))) - table.drop_column('digest') - table.drop_column('collision') - - # Migration from 4.8: remove unique constraint - table.drop_constraint('resource_name') - @staticmethod def default_type(): return 'data' diff --git a/trytond/trytond/ir/model.py b/trytond/trytond/ir/model.py index 0ee5ee376e..6a338f813b 100644 --- a/trytond/trytond/ir/model.py +++ b/trytond/trytond/ir/model.py @@ -1225,19 +1225,10 @@ class ModelData(ModelSQL, ModelView): @classmethod def __register__(cls, module_name): - cursor = Transaction().connection.cursor() - model_data = cls.__table__() - super(ModelData, cls).__register__(module_name) table_h = cls.__table_handler__(module_name) - # Migration from 4.6: register buttons on ir module - cursor.execute(*model_data.update( - [model_data.module], ['ir'], - where=((model_data.module == 'res') - & (model_data.fs_id == 'model_data_sync_button')))) - # Migration from 5.0: remove required on db_id table_h.not_null_action('db_id', action='remove') @@ -1368,16 +1359,7 @@ class ModelData(ModelSQL, ModelView): @classmethod def load_values(cls, values): - try: - return dict(json.loads(values, object_hook=JSONDecoder())) - except ValueError: - # Migration from 3.2 - import datetime - from decimal import Decimal - return eval(values, { - 'Decimal': Decimal, - 'datetime': datetime, - }) + return dict(json.loads(values, object_hook=JSONDecoder())) @classmethod @ModelView.button diff --git a/trytond/trytond/ir/module.py b/trytond/trytond/ir/module.py index 9d2108e0c6..9a43ffe727 100644 --- a/trytond/trytond/ir/module.py +++ b/trytond/trytond/ir/module.py @@ -5,7 +5,6 @@ from functools import wraps from sql.operators import NotIn -from trytond import backend from trytond.cache import Cache from trytond.exceptions import UserError from trytond.i18n import gettext @@ -93,43 +92,6 @@ class Module(ModelSQL, ModelView): }, }) - @classmethod - def __register__(cls, module_name): - pool = Pool() - ModelData = pool.get('ir.model.data') - sql_table = cls.__table__() - model_data_sql_table = ModelData.__table__() - cursor = Transaction().connection.cursor() - - # Migration from 3.6: remove double module - old_table = 'ir_module_module' - if backend.TableHandler.table_exist(old_table): - backend.TableHandler.table_rename(old_table, cls._table) - - super(Module, cls).__register__(module_name) - - # Migration from 4.0: rename installed to activated - cursor.execute(*sql_table.update( - [sql_table.state], ['activated'], - where=sql_table.state == 'installed')) - cursor.execute(*sql_table.update( - [sql_table.state], ['not activated'], - where=sql_table.state == 'uninstalled')) - - # Migration from 4.6: register buttons on ir module - button_fs_ids = [ - 'module_activate_button', - 'module_activate_cancel_button', - 'module_deactivate_button', - 'module_deactivate_cancel_button', - 'module_upgrade_button', - 'module_upgrade_cancel_button', - ] - cursor.execute(*model_data_sql_table.update( - [model_data_sql_table.module], ['ir'], - where=((model_data_sql_table.module == 'res') - & (model_data_sql_table.fs_id.in_(button_fs_ids))))) - @staticmethod def default_state(): return 'not activated' @@ -333,15 +295,6 @@ class ModuleDependency(ModelSQL, ModelView): 'Dependency must be unique by module!'), ] - @classmethod - def __register__(cls, module_name): - # Migration from 3.6: remove double module - old_table = 'ir_module_module_dependency' - if backend.TableHandler.table_exist(old_table): - backend.TableHandler.table_rename(old_table, cls._table) - - super(ModuleDependency, cls).__register__(module_name) - @classmethod def get_state(cls, dependencies, name): pool = Pool() @@ -368,21 +321,6 @@ class ModuleConfigWizardItem(sequence_ordered(), ModelSQL, ModelView): @classmethod def __register__(cls, module_name): - cursor = Transaction().connection.cursor() - pool = Pool() - ModelData = pool.get('ir.model.data') - model_data = ModelData.__table__() - - # Migration from 3.6: remove double module - old_table = 'ir_module_module_config_wizard_item' - if backend.TableHandler.table_exist(old_table): - backend.TableHandler.table_rename(old_table, cls._table) - cursor.execute(*model_data.update( - columns=[model_data.model], - values=[cls.__name__], - where=(model_data.model - == 'ir.module.module.config_wizard.item'))) - super(ModuleConfigWizardItem, cls).__register__(module_name) table = cls.__table_handler__(module_name) diff --git a/trytond/trytond/ir/translation.py b/trytond/trytond/ir/translation.py index 26d304c8f6..aad2363243 100644 --- a/trytond/trytond/ir/translation.py +++ b/trytond/trytond/ir/translation.py @@ -109,9 +109,6 @@ class Translation(ModelSQL, ModelView): @classmethod def __register__(cls, module_name): - transaction = Transaction() - cursor = transaction.connection.cursor() - ir_translation = cls.__table__() table = cls.__table_handler__(module_name) # Migration from 5.0: remove src_md5 @@ -121,12 +118,6 @@ class Translation(ModelSQL, ModelView): super(Translation, cls).__register__(module_name) - # Migration from 3.8: rename odt type in report - cursor.execute(*ir_translation.update( - [ir_translation.type], - ['report'], - where=ir_translation.type == 'odt')) - @classmethod def register_model(cls, model, module_name): cursor = Transaction().connection.cursor() diff --git a/trytond/trytond/ir/trigger.py b/trytond/trytond/ir/trigger.py index 92f07e2e47..624c161951 100644 --- a/trytond/trytond/ir/trigger.py +++ b/trytond/trytond/ir/trigger.py @@ -3,7 +3,7 @@ import datetime import time -from sql import Literal, Null, Select +from sql import Literal, Select from sql.aggregate import Count, Max from sql.functions import CurrentTimestamp from sql.operators import Concat @@ -77,27 +77,11 @@ class Trigger(DeactivableMixin, ModelSQL, ModelView): @classmethod def __register__(cls, module_name): - cursor = Transaction().connection.cursor() - table = cls.__table_handler__(module_name) - sql_table = cls.__table__() - super(Trigger, cls).__register__(module_name) + cursor = Transaction().connection.cursor() table_h = cls.__table_handler__(module_name) - - # Migration from 3.4: - # change minimum_delay into timedelta minimum_time_delay - if table.column_exist('minimum_delay'): - cursor.execute(*sql_table.select( - sql_table.id, sql_table.minimum_delay, - where=sql_table.minimum_delay != Null)) - for id_, delay in cursor: - delay = datetime.timedelta(hours=delay) - cursor.execute(*sql_table.update( - [sql_table.minimum_time_delay], - [delay], - where=sql_table.id == id_)) - table.drop_column('minimum_delay') + sql_table = cls.__table__() # Migration from 5.4: merge action if (table_h.column_exist('action_model') diff --git a/trytond/trytond/modules/__init__.py b/trytond/trytond/modules/__init__.py index 1303a5a5da..ae7f3046c0 100644 --- a/trytond/trytond/modules/__init__.py +++ b/trytond/trytond/modules/__init__.py @@ -367,7 +367,6 @@ def register_classes(with_test=False): def load_modules( database_name, pool, update=None, lang=None, activatedeps=False): # Do not import backend when importing module - from trytond import backend res = True if update: update = update[:] @@ -380,23 +379,6 @@ def load_modules( with transaction.set_context(_no_trigger=True), \ transaction.connection.cursor() as cursor: - # Migration from 3.6: remove double module - old_table = 'ir_module_module' - new_table = 'ir_module' - if backend.TableHandler.table_exist(old_table): - backend.TableHandler.table_rename(old_table, new_table) - - # Migration from 4.0: rename installed to activated - cursor.execute(*ir_module.select(ir_module.name, - where=ir_module.state.in_(('installed', 'uninstalled')))) - if cursor.fetchone(): - cursor.execute(*ir_module.update( - [ir_module.state], ['activated'], - where=ir_module.state == 'installed')) - cursor.execute(*ir_module.update( - [ir_module.state], ['not activated'], - where=ir_module.state == 'uninstalled')) - if update: cursor.execute(*ir_module.select(ir_module.name, where=ir_module.state.in_(('activated', 'to activate', diff --git a/trytond/trytond/res/user.py b/trytond/trytond/res/user.py index 0065f76cd4..0ffcb5a7ca 100644 --- a/trytond/trytond/res/user.py +++ b/trytond/trytond/res/user.py @@ -28,9 +28,8 @@ from operator import attrgetter from passlib.context import CryptContext from sql import Literal, Null from sql.aggregate import Count -from sql.conditionals import Case, Coalesce +from sql.conditionals import Case from sql.functions import CurrentTimestamp -from sql.operators import Concat try: import bcrypt @@ -205,21 +204,6 @@ class User(avatar_mixin(100, 'login'), DeactivableMixin, ModelSQL, ModelView): model_data = ModelData.__table__() cursor = Transaction().connection.cursor() super(User, cls).__register__(module_name) - table = cls.__table_handler__(module_name) - - # Migration from 3.0 - if table.column_exist('password') and table.column_exist('salt'): - sqltable = cls.__table__() - password_hash_new = Concat('sha1$', Concat(sqltable.password, - Concat('$', Coalesce(sqltable.salt, '')))) - cursor.execute(*sqltable.update( - columns=[sqltable.password_hash], - values=[password_hash_new])) - table.drop_column('password') - table.drop_column('salt') - - # Migration from 4.2: Remove required on name - table.not_null_action('name', action='remove') # Migration from 5.6: Set noupdate to admin cursor.execute(*model_data.update( diff --git a/trytond/trytond/tools/multivalue.py b/trytond/trytond/tools/multivalue.py deleted file mode 100644 index 9cbb9de449..0000000000 --- a/trytond/trytond/tools/multivalue.py +++ /dev/null @@ -1,112 +0,0 @@ -# This file is part of Tryton. The COPYRIGHT file at the top level of -# this repository contains the full copyright notices and license terms. -from decimal import Decimal - -from sql import Column, Literal, Null, Table, Union -from sql.aggregate import Max - -from trytond import backend -from trytond.pool import Pool -from trytond.transaction import Transaction - - -def migrate_property( - model_name, field_names, ValueModel, value_names, - parent=None, fields=None): - "Migrate property from model_name.field_name to ValueModel.value_name" - pool = Pool() - Field = pool.get('ir.model.field') - Model = pool.get('ir.model') - if not backend.TableHandler.table_exist('ir_property'): - return - cursor = Transaction().connection.cursor() - field = Field.__table__() - model = Model.__table__() - table = ValueModel.__table__() - - if fields is None: - fields = [] - if isinstance(field_names, str): - field_names = [field_names] - if isinstance(value_names, str): - value_names = [value_names] - - def split_value(value): - return value.split(',')[1] - cast_funcs = { - 'numeric': lambda v: Decimal(split_value(v)) if v else None, - 'integer': lambda v: int(split_value(v)) if v else None, - 'float': lambda v: float(split_value(v)) if v else None, - 'char': lambda v: split_value(v) if v else None, - 'selection': lambda v: split_value(v) if v else None, - 'many2one': lambda v: int(split_value(v)) if v else None, - 'reference': lambda v: v, - } - - casts = [] - queries = [] - for field_name, value_name in zip(field_names, value_names): - value_field = getattr(ValueModel, value_name) - casts.append(cast_funcs[value_field._type]) - - property_ = Table('ir_property') - columns = [ - Literal(None).as_(f) if f != value_name - else property_.value.as_(value_name) - for f in value_names] - if parent: - columns.append(property_.res.as_(parent)) - where = property_.res.like(model_name + ',%') - else: - where = property_.res == Null - columns.extend([Column(property_, f).as_(f) for f in fields]) - query = property_.join(field, - condition=property_.field == field.id - ).join(model, - condition=field.model == model.id - ).select(*columns, - where=where - & (field.name == field_name) - & (model.model == model_name)) - queries.append(query) - - union = Union(*queries) - columns = [Max(Column(union, f)).as_(f) for f in value_names] - if parent: - columns.append(Column(union, parent).as_(parent)) - pcolumns = [Column(union, parent)] - else: - pcolumns = [] - vcolumns = [Column(union, f).as_(f) for f in fields] - cursor.execute( - *union.select(*(columns + vcolumns), group_by=pcolumns + vcolumns)) - - columns = [Column(table, f) for f in value_names] - if parent: - pcolumns = [Column(table, parent)] - else: - pcolumns = [] - vcolumns = [Column(table, f) for f in fields] - values = [] - length = len(value_names) - for row in cursor: - value = [c(v) for v, c in zip(row, casts)] - if parent: - value.append( - int(row[length].split(',')[1]) - if row[length] else None) - i = 1 - else: - i = 0 - value.extend(row[length + i:]) - values.append(value) - if (values and not ( - # No property defined - len(values) == 1 - and all(x is None for x in values[0][:len(columns)]))): - - # Delete previous migrated values - cursor.execute(*table.delete()) - - cursor.execute(*table.insert( - columns + pcolumns + vcolumns, values=values))