def __register__(cls, module_name): TableHandler = backend.TableHandler cursor = Transaction().connection.cursor() sql_table = cls.__table__() code_exists = True date_exists = True if backend.TableHandler.table_exist(cls._table): table = backend.TableHandler(cls, module_name) code_exists = table.column_exist('code') date_exists = table.column_exist('date') super(Activity, cls).__register__(module_name) table = backend.TableHandler(cls, module_name) # Migration from 3.2: Remove type and direction fields table.not_null_action('type', action='remove') table.not_null_action('direction', action='remove') # Migration from 3.2: Add code field if (not code_exists and table.column_exist('type') and table.column_exist('direction')): cursor.execute(*sql_table.update( columns=[sql_table.code], values=[sql_table.id], where=sql_table.code == Null)) table.not_null_action('code', action='add') # Migration from 3.4.1: subject is no more required table.not_null_action('subject', 'remove') # Migration from 5.2 if not date_exists: cursor.execute(*sql_table.update( columns=[sql_table.date, sql_table.time], values=[Cast(sql_table.dtstart, 'DATE'), Cast(sql_table.dtstart, 'TIME')])) cursor.execute(*sql_table.update( columns=[sql_table.duration], values=[sql_table.dtend - sql_table.dtstart], where=sql_table.dtend != Null)) cursor.execute(*sql_table.update( columns=[sql_table.state], values=['done'], where=sql_table.state == 'held')) cursor.execute(*sql_table.update( columns=[sql_table.state], values=['canceled'], where=sql_table.state == 'not_held'))
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 = backend.TableHandler(ProductCostPrice, 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])))
def __register__(cls, module_name): table = backend.TableHandler(cls, module_name) if table.column_exist('start_zip'): table.column_rename('start_zip', 'zip') super(eSaleAccountTaxRule, cls).__register__(module_name)
def __register__(cls, module_name): attachment_h = backend.TableHandler(cls) pool = Pool() Signature = pool.get('document.signature') super(Attachment, cls).__register__(module_name) if not attachment_h.column_exist('cryptolog_status'): return # Migration from coog 2.4 Move data to signature table = cls.__table__() signature = Signature.__table__() cursor = Transaction().connection.cursor() cursor.execute(*table.select(table.id, table.cryptolog_id, table.cryptolog_status, table.cryptolog_logs, table.cryptolog_url, where=table.cryptolog_id != Null)) for attachment_id, cryptolog_id, status, logs, url in cursor.fetchall( ): cursor.execute(*signature.insert([ signature.attachment, signature.provider_id, signature.status, signature.logs, signature.provider_url ], [[attachment_id, cryptolog_id, status, logs, url]])) attachment_h.drop_column('cryptolog_id') attachment_h.drop_column('cryptolog_status') attachment_h.drop_column('cryptolog_logs') attachment_h.drop_column('cryptolog_url') attachment_h.drop_column('cryptolog_signer')
def __register__(cls, module_name): table = backend.TableHandler(cls, module_name) # Migration from 3.8: rename reference_external into number_external if (table.column_exist('reference_external') and not table.column_exist('number_external')): table.column_rename('reference_external', 'number_external') super(Sale, cls).__register__(module_name)
def __register__(cls, module_name): table = backend.TableHandler(cls, module_name) # Migration: rename account_date into account_date_utc if (table.column_exist('account_date') and not table.column_exist('account_date_utc')): table.column_rename('account_date', 'account_date_utc') super(StatementLine, cls).__register__(module_name)
def __register__(cls, module_name): cursor = Transaction().connection.cursor() table = backend.TableHandler(cls, module_name) created_347 = table.column_exist('include_347') super(Party, cls).__register__(module_name) # We need to reload table as it may be modified by __register__ table = backend.TableHandler(cls, module_name) if (not created_347 and table.column_exist('include_347')): sql_table = cls.__table__() identifier = Pool().get('party.identifier').__table__() query = identifier.select(identifier.party, where=Substring(identifier.code, 1, 2) == 'ES') cursor.execute(*sql_table.update(columns=[sql_table.include_347], values=[True], where=(sql_table.id.in_(query))))
def __register__(cls, module_name): table = backend.TableHandler(cls, module_name) old_table = 'sale_pos_device_account_statement_journal' if backend.TableHandler.table_exist(old_table): backend.TableHandler.table_rename(old_table, cls._table) old_column = 'pos_device' new_column = 'device' if table.column_exist(old_column): table.drop_fk(old_column) table.column_rename(old_column, new_column) super(SaleDeviceStatementJournal, cls).__register__(module_name)
def __register__(cls, module_name): cursor = Transaction().connection.cursor() sql_table = cls.__table__() # Migration from 3.2 table = backend.TableHandler(cls, module_name) move_delivery_dates = (not table.column_exist('manual_delivery_date') and table.column_exist('shipping_date')) super(SaleLine, cls).__register__(module_name) if move_delivery_dates: cursor.execute(*sql_table.update( columns=[sql_table.manual_delivery_date], values=[sql_table.shipping_date])) table.drop_column('shipping_date')
def __register__(cls, module_name): configuration_h = backend.TableHandler(cls) Credential = Pool().get('document.signature.configuration') super().__register__(module_name) # Migration from coog 2.6 Link configuration to credential if configuration_h.column_exist('company'): table = cls.__table__() credential = Credential.__table__() cursor = Transaction().connection.cursor() cursor.execute(*credential.select(credential.id)) result = cursor.fetchone() if result is not None: credential_id = result[0] cursor.execute(*table.update(columns=[table.credential], values=[credential_id])) configuration_h.drop_column('company')
def __register__(cls, module_name): cursor = Transaction().connection.cursor() table = backend.TableHandler(cls, 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]))