def migrate(env, version): if not version: return cr = env.cr if not openupgrade.column_exists(cr, "child_disaster_impact", "child_global_id"): cr.execute(""" ALTER TABLE child_disaster_impact ADD COLUMN child_global_id character varying """) if not openupgrade.column_exists(cr, "fcp_disaster_impact", "project_fcp_id"): cr.execute(""" ALTER TABLE fcp_disaster_impact ADD COLUMN project_fcp_id character varying """) cr.execute(""" UPDATE child_disaster_impact impact SET child_global_id = ( SELECT global_id FROM compassion_child WHERE id = impact.child_id) """) cr.execute(""" UPDATE fcp_disaster_impact impact SET project_fcp_id = ( SELECT fcp_id FROM compassion_project WHERE id = impact.project_id) """)
def migrate(env, version): if openupgrade.column_exists(env.cr, "joint_buying_tour", "date_tour"): openupgrade.logged_query( env.cr, """ ALTER TABLE joint_buying_tour RENAME COLUMN date_tour TO start_date; """, ) if not openupgrade.column_exists(env.cr, "joint_buying_tour", "end_date"): openupgrade.logged_query( env.cr, """ ALTER TABLE joint_buying_tour ADD COLUMN end_date TIMESTAMP; """, ) openupgrade.logged_query( env.cr, """ UPDATE joint_buying_tour SET end_date = start_date + interval '4 hour' """, )
def migrate(env, version): openupgrade.copy_columns(env.cr, _column_copies) if openupgrade.column_exists(env.cr, 'sale_order', 'payment_tx_id'): # from sale_payment module openupgrade.rename_columns(env.cr, _column_renames) rename_sale_payment_config_parameters(env.cr, _config_param_renames) openupgrade.lift_constraints(env.cr, "sale_order", "payment_tx_id") openupgrade.lift_constraints(env.cr, "sale_order ", "payment_acquirer_id") openupgrade.lift_constraints(env.cr, "payment_transaction ", "sale_order_id") if openupgrade.column_exists(env.cr, 'sale_order', 'requested_date'): # from sale_order_dates module openupgrade.rename_fields(env, _field_renames_order_dates) if openupgrade.table_exists(env.cr, 'sale_quote_line'): # from website_quote module openupgrade.rename_columns(env.cr, _column_renames2) fill_sale_order_line_sections(env.cr) openupgrade.logged_query( env.cr, "ALTER TABLE sale_order_line ADD COLUMN qty_delivered_method varchar", ) openupgrade.logged_query( env.cr, "ALTER TABLE sale_order_line ADD COLUMN untaxed_amount_invoiced " "NUMERIC") openupgrade.logged_query( env.cr, "ALTER TABLE sale_order_line ADD COLUMN untaxed_amount_to_invoice " "NUMERIC")
def pre_init_hook(cr): if ( openupgrade.column_exists( cr, 'res_partner', 'document_type_id') and not openupgrade.column_exists( cr, 'res_partner', 'main_id_category_id')): openupgrade.rename_columns(cr, column_renames) fix_data_on_l10n_ar_partner(cr)
def migrate(env, version): if not version: return if not openupgrade.column_exists( env.cr, "sale_order", "priority") or not openupgrade.column_exists( env.cr, "sale_order_line", "priority"): return change_priorities(env)
def pre_init_hook(cr): _logger.info('Running pre init hook') if ( openupgrade.column_exists( cr, 'res_partner', 'document_type_id') and not openupgrade.column_exists( cr, 'res_partner', 'main_id_category_id')): openupgrade.rename_columns(cr, column_renames) fix_data_on_l10n_cl_partner(cr)
def migrate(env, version): openupgrade.copy_columns(env.cr, _column_copies) if openupgrade.column_exists(env.cr, 'sale_order', 'payment_tx_id'): # from sale_payment module openupgrade.rename_columns(env.cr, _column_renames) if openupgrade.column_exists(env.cr, 'sale_order', 'requested_date'): # from sale_order_dates module openupgrade.rename_fields(env, _field_renames_order_dates) fill_sale_order_line_sections(env.cr)
def migrate(env, version): cr = env.cr # Restore columns disabled on 8.0 -> 9.0 migration for row in column_renames[table]: if openupgrade.column_exists(cr, table, row[0]): if openupgrade.column_exists(cr, table, row[1]): row1 = [(table, row[1])] openupgrade.drop_columns(cr, row1) columns = {table: [(row[0], row[1])]} openupgrade.rename_columns(cr, columns)
def migrate(env, version): if openupgrade.column_exists(env.cr, "res_partner", "group_id"): if not openupgrade.column_exists(env.cr, "res_partner", "company_group_id"): openupgrade.rename_fields(env, field_renames) else: openupgrade.logged_query( env.cr, """ UPDATE res_partner SET company_group_id = group_id WHERE company_group_id IS NULL AND group_id IS NOT NULL""", )
def migrate(env, version): openupgrade.copy_columns(env.cr, _column_copies) if openupgrade.column_exists(env.cr, 'sale_order', 'payment_tx_id'): # from sale_payment module openupgrade.rename_columns(env.cr, _column_renames) if openupgrade.column_exists(env.cr, 'sale_order', 'requested_date'): # from sale_order_dates module openupgrade.rename_fields(env, _field_renames_order_dates) fill_sale_order_line_sections(env.cr) openupgrade.logged_query( env.cr, "ALTER TABLE sale_order_line ADD COLUMN qty_delivered_method varchar", )
def migrate(env, version): if not version: return if openupgrade.table_exists(env.cr, 'ambassador_details'): openupgrade.rename_tables(env.cr, [ ('ambassador_details', 'advocate_details'), ('ambassador_engagement', 'advocate_engagement'), ('ambassador_engagement_rel', 'advocate_engagement_rel') ]) openupgrade.rename_models(env.cr, [ ('ambassador.details', 'advocate.details'), ('ambassador.engagement', 'advocate.engagement') ]) if not openupgrade.column_exists(env.cr, 'res_partner', 'advocate_details_id'): openupgrade.rename_fields(env, [ ('res.partner', 'res_partner', 'ambassador_details_id', 'advocate_details_id'), ], True) openupgrade.rename_columns(env.cr, { 'advocate_engagement_rel': [ ('ambassador_details_id', 'advocate_details_id')] }) if openupgrade.column_exists(env.cr, 'res_partner', 'ambassador_details_id'): openupgrade.drop_columns(env.cr, [('res_partner', 'ambassador_details_id')]) # Replace field in views to avoid errors at update env.cr.execute(""" UPDATE ir_ui_view SET arch_db = replace(arch_db, 'ambassador_details_id', 'advocate_details_id') WHERE arch_db LIKE '%ambassador_details_id%'; """) # Delete old translations env.cr.execute(""" DELETE FROM ir_translation WHERE value = 'Details of ambassador' """) # Update templates env.cr.execute(""" UPDATE ir_translation SET value = replace(value, 'ambassador_details_id', 'advocate_details_id'), src = replace(src, 'ambassador_details_id', 'advocate_details_id') WHERE value LIKE '%ambassador_details_id%' """)
def migrate(env, version): cr = env.cr table = 'res_partner' old_column = 'property_comment_template_id' new_column = openupgrade.get_legacy_name(old_column) if openupgrade.column_exists(cr, table, old_column): openupgrade.rename_columns(cr, {table: [(old_column, new_column)]})
def migrate(env, version): cr = env.cr openupgrade.delete_records_safely_by_xml_id( env, ['account.action_view_account_move_line_reconcile'], ) openupgrade.copy_columns(cr, _column_copies) openupgrade.rename_columns(cr, _column_renames) openupgrade.rename_fields(env, _field_renames) openupgrade.rename_xmlids(cr, xmlid_renames) if openupgrade.table_exists(cr, 'sale_order'): openupgrade.rename_fields(env, _field_renames_sale) if openupgrade.table_exists(cr, 'sale_layout_category'): fill_account_invoice_line_sections(cr) if openupgrade.table_exists(cr, 'account_move_reverse'): # module account_reversal openupgrade.rename_fields(env, _field_renames_account_reversal) if not openupgrade.column_exists(env.cr, 'res_company', 'incoterm_id'): openupgrade.logged_query( env.cr, """ ALTER TABLE res_company ADD COLUMN incoterm_id INTEGER""", ) prefill_account_chart_template_transfer_account_prefix(env) openupgrade.set_xml_ids_noupdate_value( env, 'account', ['account_analytic_line_rule_billing_user'], False)
def migrate(env, version): """ Column `move_type` of table `account_move` has been renamed to `financial_type` because `move_type` is now used by the core, so the column is moved during migration of module `account` in the core. Enterprise renames it to `move_type_custom`; OpenUpgrade renames it to its legacy name. Move data from the renamed column to the new `financial_type` column. """ old_move_type_column = "move_type" new_move_type_column = "financial_type" move_table_name = "account_move" enterprise_move_type_rename = "move_type_custom" ou_move_type_rename = openupgrade.get_legacy_name(old_move_type_column) for move_type_rename in (enterprise_move_type_rename, ou_move_type_rename): if openupgrade.column_exists(env.cr, move_table_name, move_type_rename): openupgrade.rename_columns( env.cr, { move_table_name: [(move_type_rename, new_move_type_column) ], }, ) break
def migrate(env, version): if openupgrade.column_exists(env.cr, 'account_voucher', 'company_id'): # In odoo v8, the company_id was stored. Thus, maybe some databases # that have been migrating since v8, may still have that column. Thus, # if new records have been created in newer versions, they may have # this field empty. assure_company(env.cr)
def migrate(env, version): type_change_payment_transaction_and_sale_order(env) fill_res_company_portal_confirmation(env.cr) fill_sale_order_line_is_expense(env.cr) fill_sale_order_line_qty_delivered_method(env.cr) fill_sale_order_line_untaxed_amount_invoiced(env) fill_sale_order_line_untaxed_amount_to_invoice(env) if openupgrade.column_exists( env.cr, 'sale_order', openupgrade.get_legacy_name('commitment_date')): set_group_sale_order_dates(env.cr) openupgrade.load_data(env.cr, 'sale', 'migrations/12.0.1.1/noupdate_changes.xml') openupgrade.delete_record_translations( env.cr, 'sale', [ 'email_template_edi_sale', ], ) openupgrade.delete_records_safely_by_xml_id( env, [ 'sale.mail_template_data_notification_email_sale_order', ], )
def migrate(env, version): if openupgrade.column_exists(env.cr, "hr_course", "migration_course_id"): return openupgrade.logged_query( env.cr, """ ALTER TABLE hr_course ADD COLUMN migration_course_id integer""", ) openupgrade.logged_query( env.cr, """ INSERT INTO hr_course ( name, category_id, permanence, permanence_time, migration_course_id ) SELECT name, category_id, permanence, permanence_time, id FROM hr_course_schedule """, ) openupgrade.logged_query( env.cr, """ UPDATE hr_course_schedule hcs SET course_id = hc.id FROM hr_course hc WHERE hc.migration_course_id = hcs.id """, ) openupgrade.load_data(env.cr, "hr_course", "migrations/14.0.2.0.0/noupdate_changes.xml")
def migrate(env, version): column = openupgrade.get_legacy_name('scan') if openupgrade.column_exists(env.cr, 'account_banking_mandate', column): openupgrade_90.convert_binary_field_to_attachment( env, {'account.banking.mandate': [('scan', None)]}, )
def recreate_analytic_lines(cr): """If the module project_timesheet is not installed, we need to convert project.task.work elements, or we will lose this history. This is done inserting new records in account_analytic_line, and adding one extra column work_id in case other modules need to fill some fields for each created line. """ cr.execute("ALTER TABLE account_analytic_line ADD task_id integer") cr.execute("ALTER TABLE account_analytic_line ADD work_id integer") if not openupgrade.column_exists(cr, 'account_analytic_line', 'is_timesheet'): cr.execute( "ALTER TABLE account_analytic_line ADD is_timesheet boolean") # TODO: Calculate line cost according employee data openupgrade.logged_query( cr, """ INSERT INTO account_analytic_line (company_id, date, name, task_id, user_id, unit_amount, account_id, amount, is_timesheet, work_id) SELECT w.company_id, COALESCE(w.date, w.create_date), COALESCE(w.name, '(migrated line)'), w.task_id, w.user_id, w.hours, p.analytic_account_id, 0, True, w.id FROM project_task_work w, project_task t, project_project p WHERE w.task_id = t.id AND t.project_id = p.id """ )
def map_tax_groups_to_taxes(cr, registry): if (openupgrade.column_exists(cr, 'account_tax', 'tax_code_id') and openupgrade.table_exists(cr, 'account_tax_code')): # we make an union to add tax without tax code but with base code openupgrade.logged_query( cr, """ SELECT at.id as tax_id, application, afip_code, tax, type FROM account_tax at INNER JOIN account_tax_code as atc on at.tax_code_id = atc.id UNION SELECT at.id as tax_id, application, afip_code, tax, type FROM account_tax at INNER JOIN account_tax_code as atc on at.base_code_id = atc.id and at.tax_code_id is null """, ) taxes_read = cr.fetchall() for tax_read in taxes_read: (tax_id, application, afip_code, tax, type) = tax_read domain = [ ('application', '=', application), ('tax', '=', tax), ('type', '=', type), ] # because only vat and type tax should have afip_code if afip_code and tax == 'vat' and type == 'tax': domain += [('afip_code', '=', afip_code)] tax_group_ids = registry['account.tax.group'].search(cr, 1, domain) # we only assign tax group if we found one if len(tax_group_ids) == 1: registry['account.tax'].write( cr, 1, tax_id, {'tax_group_id': tax_group_ids[0]})
def update_payments_from_vouchers(env): """Update account.payment rows from corresponding account.voucher rows.""" # Use the fact that id of migrated account_payment is id of original # account_voucher. # Do not set: check_number = av.number # new check_number is integer value, av.number was text filled from # sequence. env.cr.execute("""\ UPDATE account_payment ap SET check_amount_in_words = av.amount_in_word FROM account_voucher av WHERE ap.id = av.id """) check_method = env.ref( 'account_check_printing.account_payment_method_check') if openupgrade.column_exists(env.cr, 'account_journal', 'allow_check_writing'): env.cr.execute( """\ UPDATE account_payment ap SET payment_method_id = %s FROM account_voucher av INNER JOIN account_journal aj ON aj.id = av.journal_id WHERE ap.id = av.id AND aj.allow_check_writing = True AND ap.payment_type = 'outbound' """, (check_method.id, ))
def handle_account_asset_disposal_migration(env): """Take care of potentially installed `account_asset_disposal` module. In this phase we rename stuff for adapting to the new data structure. """ cr = env.cr if not openupgrade.column_exists(cr, 'account_asset', 'disposal_move_id'): return openupgrade.copy_columns(cr, {'account_asset': [('state', None, None)]}) openupgrade.rename_columns(cr, {'account_asset': [('disposal_move_id', None)]}) openupgrade.map_values( cr, openupgrade.get_legacy_name('state'), 'state', [('disposed', 'removed')], table='account_asset', ) openupgrade.rename_fields( env, [ ('account.asset', 'account_asset', 'disposal_date', 'date_remove'), ('account.asset.profile', 'account_asset_profile', 'account_loss_id', 'account_residual_value_id'), ], )
def migrate(env, version): column = openupgrade.get_legacy_name('logo') if openupgrade.column_exists(env.cr, 'product_brand', column): openupgrade_90.convert_binary_field_to_attachment( env, {'product.brand': [('logo', None)]}, )
def create_account_invoice_amount_tax_company_signed(env): if not openupgrade.column_exists(env.cr, "account_invoice", "amount_tax_company_signed"): openupgrade.logged_query( env.cr, """ ALTER TABLE account_invoice ADD COLUMN amount_tax_company_signed numeric""") openupgrade.logged_query( env.cr, """ SELECT ai.id, ai.amount_tax, ai.type, ai.currency_id, ai.company_id, rc.currency_id, ai.date_invoice FROM account_invoice ai JOIN res_company rc ON ai.company_id = rc.id""") for _id, tax, inv_type, curr, company, company_curr, date in \ env.cr.fetchall(): company_tax = tax if curr != company_curr: curr_ = env["res.currency"].browse(curr) company_curr_ = env["res.currency"].browse(company_curr) company_ = env["res.company"].browse(company) company_tax = curr_._convert(company_tax, company_curr_, company_, date or fields.Date.today()) sign = inv_type in ['in_refund', 'out_refund'] and -1 or 1 company_tax = company_tax * sign openupgrade.logged_query( env.cr, """ UPDATE account_invoice SET amount_tax_company_signed = %s WHERE id = %s""", (company_tax, _id), )
def update_procurement_field_from_sale(env): """Connecting new sale_id field of procurement_group with respective sale orders (considering procurement_group_id of sale order). """ if not openupgrade.column_exists(env.cr, 'procurement_group', 'sale_id'): openupgrade.add_fields(env, [ ('sale_id', 'procurement.group', 'procurement_group', 'many2one', False, 'sale_stock'), ]) openupgrade.logged_query( env.cr, """ UPDATE procurement_group pg SET sale_id = sol.order_id FROM stock_move sm JOIN sale_order_line sol ON sm.sale_line_id = sol.id WHERE sm.group_id = pg.id""", ) openupgrade.logged_query( env.cr, """ UPDATE procurement_group pg SET sale_id = sol.order_id FROM procurement_order po JOIN sale_order_line sol ON po.sale_line_id = sol.id WHERE po.group_id = pg.id AND pg.sale_id IS NULL""", )
def create_withholding_data_lines(env): """ Create ftpa_withholding_ids from ftpa_withholding_type and ftpa_withholding_amount """ column_wht_amount = openupgrade.get_legacy_name('withholding_tax_amount') column_wht_type = openupgrade.get_legacy_name('ftpa_withholding_type') exists = openupgrade.column_exists(env.cr, 'account_invoice', column_wht_amount) mapping = { 'name': 'ai.{ftpa_withholding_type}'.format( ftpa_withholding_type=column_wht_type), 'invoice_id': 'ai.id', 'create_uid': 'ai.create_uid', 'create_date': 'ai.create_date', 'write_date': 'ai.write_date', 'write_uid': 'ai.write_uid', } if exists: mapping.update( {'amount': 'ai.{ftpa_withholding_amount}'.format( ftpa_withholding_amount=column_wht_amount)}) query = """ INSERT INTO withholding_data_line ({columns}) SELECT {values} FROM account_invoice AS ai WHERE ai.{ftpa_withholding_type} IS NOT NULL;""".format( columns=','.join(mapping.keys()), values=','.join(mapping.values()), ftpa_withholding_type=column_wht_type) openupgrade.logged_query(env.cr, sql.SQL(query))
def update_purchase_order_lines(cr): cr.execute(""" ALTER TABLE purchase_order_line RENAME COLUMN product_template TO product_tmpl_id; """) if openupgrade.column_exists( cr, 'purchase_order_line_attribute', 'attribute_id'): attribute_column = 'attribute_id' value_column = 'value_id' else: attribute_column = 'attribute' value_column = 'value' cr.execute(""" INSERT INTO product_configurator_attribute (owner_model, owner_id, attribute_id, value_id, product_tmpl_id) SELECT 'purchase.order.line', attr.purchase_line, attr.%s, attr.%s, line.product_tmpl_id FROM purchase_order_line_attribute AS attr, purchase_order_line AS line WHERE line.id = attr.purchase_line AND attr.purchase_line IS NOT NULL; """ % (attribute_column, value_column))
def post_init_hook(cr, registry): """Loaded after installing the module. This module's DB modifications will be available. :param openerp.sql_db.Cursor cr: Database cursor. :param openerp.modules.registry.RegistryManager registry: Database registry, using v7 api. """ # we don not force dependency on openupgradelib, only if available we try # o un de hook if not openupgrade.column_exists: return False # write en vez de sql para que genere los campos por defecto necesarios if openupgrade.column_exists(cr, 'res_partner', 'document_number'): # we make this so it ise much faster openupgrade.logged_query(cr, """ INSERT into res_partner_id_number (partner_id, category_id, name, sequence, create_uid, write_uid, create_date, write_date, active) SELECT id, main_id_category_id, document_number, 10, 1, 1, create_date, write_date, true FROM res_partner WHERE main_id_category_id is not null and document_number is not null """,)
def update_sale_order_lines(cr): cr.execute(""" ALTER TABLE sale_order_line RENAME COLUMN product_template TO product_tmpl_id; """) if openupgrade.column_exists(cr, 'sale_order_line_attribute', 'attribute_id'): attribute_column = 'attribute_id' value_column = 'value_id' else: attribute_column = 'attribute' value_column = 'value' cr.execute(""" INSERT INTO product_configurator_attribute (owner_model, owner_id, attribute_id, value_id, product_tmpl_id) SELECT 'sale.order.line', attr.sale_line, attr.%s, attr.%s, line.product_tmpl_id FROM sale_order_line_attribute AS attr, sale_order_line AS line WHERE line.id = attr.sale_line AND attr.sale_line IS NOT NULL; """ % (attribute_column, value_column))
def migrate(env, version): column = openupgrade.get_legacy_name('parent_id') if openupgrade.column_exists(env.cr, 'account_asset_profile', column): # if migrating directly from v11 `account_asset` module, there are no # view assets nor parents create_asset_groups(env.cr) update_asset_group_links(env.cr)
def migrate(env, version): if not openupgrade.column_exists(env.cr, "account_analytic_account", "vehicle_id"): openupgrade.add_fields( env, [ ( "vehicle_id", "account.analytic.account", "account_analytic_account", "integer", False, "project_vehicle", ), ], ) openupgrade.logged_query( env.cr, """UPDATE account_analytic_account a SET vehicle_id = p.vehicle_id FROM project_project p WHERE a.id = p.analytic_account_id AND p.vehicle_id IS NOT NULL AND a.vehicle_id IS NULL AND a.vehicle_id IS NULL """, )