def migrate(env, version): openupgrade.remove_tables_fks(env.cr, _obsolete_tables) remove_invoice_table_relations(env) # Deactivate the noupdate flag (hardcoded on initial SQL load) for allowing # to update changed data on this group. openupgrade.logged_query( env.cr, """ UPDATE ir_model_data SET noupdate=False WHERE module='base' AND name='group_user'""", ) openupgrade.update_module_names(env.cr, apriori.renamed_modules.items()) openupgrade.update_module_names(env.cr, apriori.merged_modules.items(), merge_modules=True) openupgrade.copy_columns(env.cr, column_copies) openupgrade.rename_columns(env.cr, column_renames) openupgrade.rename_fields(env, field_renames, no_deep=True) openupgrade.rename_xmlids(env.cr, xmlid_renames_res_country_state) openupgrade.rename_xmlids(env.cr, xmlid_renames_ir_model_access) fill_ir_model_data_noupdate(env) fix_lang_table(env.cr) remove_offending_translations(env) handle_web_favicon_module(env) add_res_lang_url_code(env) switch_noupdate_records(env) rename_ir_module_category(env) openupgrade.logged_query( env.cr, """ UPDATE ir_model_constraint SET create_date = date_init WHERE create_date IS NULL AND date_init IS NOT NULL """) openupgrade.logged_query( env.cr, """ UPDATE ir_model_constraint SET write_date = date_update WHERE write_date IS NULL AND date_update IS NOT NULL """)
def drop_obsolete_fk_constraints(env): """We remove the constraints on wizard_multi_charts_accounts to avoid not null error if account chart changed and account template has been removed. For exemple l10n_fr.pcg_58 has been removed between 11.0 and 12.0 and is used as default transfer_account_id. Note : wizard_multi_charts_accounts is an obsolete table. Model has been removed in V12.0 """ openupgrade.remove_tables_fks(env.cr, [ 'wizard_multi_charts_accounts', 'account_aged_trial_balance', 'account_aged_trial_balance_account_journal_rel', 'account_balance_report', 'account_balance_report_journal_rel', 'account_bank_accounts_wizard', 'account_common_account_report', 'account_common_partner_report', 'account_financial_report', 'accounting_report', 'account_move_line_reconcile', 'account_move_line_reconcile_writeoff', 'account_opening', 'account_report_general_ledger', 'account_report_general_ledger_journal_rel', 'account_report_partner_ledger', 'account_tax_report', ]) # also, we lift some obsolete fk constraints from mny2ones openupgrade.lift_constraints(env.cr, "account_chart_template", "transfer_account_id") openupgrade.lift_constraints(env.cr, "account_chart_template", "company_id") openupgrade.lift_constraints(env.cr, "account_tax_template", "company_id")
def migrate(env, version): openupgrade.remove_tables_fks(env.cr, 'mrp_bom_line_product_attribute_value_rel') openupgrade.rename_models(env.cr, _model_renames) if openupgrade.table_exists(env.cr, 'mrp_subproduct'): openupgrade.rename_tables(env.cr, _mrp_subproduct_table_renames) fast_precreation_and_fill_mrp_bom_byproduct(env) openupgrade.rename_xmlids(env.cr, _mrp_subproduct_xmlid_renames) fast_precreation_and_fill_mrp_bom_line(env) openupgrade.rename_fields(env, _field_renames) openupgrade.copy_columns(env.cr, _column_copies) openupgrade.rename_columns(env.cr, _column_renames) mapped_reservation_state(env)
def migrate(env, version): openupgrade.remove_tables_fks(env.cr, _obsolete_tables) openupgrade.update_module_names(env.cr, apriori.renamed_modules.items()) openupgrade.update_module_names(env.cr, apriori.merged_modules.items(), merge_modules=True) openupgrade.rename_columns(env.cr, column_renames) openupgrade.rename_models(env.cr, model_renames_ir_actions_report) handle_partner_sector(env) env.cr.execute("""UPDATE ir_actions SET type = 'ir.actions.report' WHERE type = 'ir.actions.report.xml'""") rule_xml_ids = ('ir_config_parameter_rule', 'ir_values_default_rule') env.cr.execute( """ DELETE FROM ir_rule WHERE id IN ( SELECT res_id FROM ir_model_data WHERE module = 'base' AND name IN %s) """, (rule_xml_ids, )) env.cr.execute( """ DELETE FROM ir_model_data WHERE module = 'base' AND name IN %s """, (rule_xml_ids, )) # All existing server actions are of type server action env.cr.execute(""" ALTER TABLE ir_act_server ADD COLUMN usage VARCHAR; UPDATE ir_act_server SET usage = 'ir_actions_server'""") # For some window actions, there is a value in the old column # that was inherited from ir_actions before env.cr.execute( """ ALTER TABLE ir_act_window ADD COLUMN usage VARCHAR; UPDATE ir_act_window SET usage = %s""", (AsIs(openupgrade.get_legacy_name('usage')), )) # work_days interval was removed from selection values env.cr.execute(""" UPDATE ir_cron SET interval_type = 'days' WHERE interval_type = 'work_days'""") fill_cron_action_server_pre(env) openupgrade.set_xml_ids_noupdate_value(env, 'base', ['lang_km'], True) set_currency_rate_dates(env) # Rename 'mass_mailing_event' module to not collide with the new # core module with the same name. rename_mass_mailing_event(env)
def migrate(env, version): openupgrade.remove_tables_fks(env.cr, _obsolete_tables) # Deactivate the noupdate flag (hardcoded on initial SQL load) for allowing # to update changed data on this group. openupgrade.logged_query( env.cr, """ UPDATE ir_model_data SET noupdate=False WHERE module='base' AND name='group_user'""", ) openupgrade.update_module_names(env.cr, apriori.renamed_modules.items()) openupgrade.update_module_names(env.cr, apriori.merged_modules.items(), merge_modules=True) if openupgrade.table_exists(env.cr, 'product_uom'): openupgrade.rename_models(env.cr, model_renames_product) openupgrade.rename_tables(env.cr, table_renames_product) if openupgrade.table_exists(env.cr, 'stock_incoterms'): openupgrade.rename_models(env.cr, model_renames_stock) openupgrade.rename_tables(env.cr, table_renames_stock) openupgrade.rename_xmlids(env.cr, xmlid_renames) switch_noupdate_flag(env) eliminate_duplicate_translations(env.cr) # Make the system and admin user XML ids refer to the same entry for now to # prevent errors when base data is loaded. The users are picked apart in # this module's end stage migration script. # Safely, we check first if the `base.user_admin` already exists to # avoid possible conflicts: very old databases may have this record. env.cr.execute(""" SELECT id FROM ir_model_data WHERE name='user_admin' AND module='base' AND model='res.users'""") if env.cr.fetchone(): env.cr.execute(""" UPDATE ir_model_data SET model='res.users',res_id=1,noupdate=true WHERE name='user_admin' AND module='base' AND model='res.users'""") else: env.cr.execute(""" INSERT INTO ir_model_data (module, name, model, res_id, noupdate) VALUES('base', 'user_admin', 'res.users', 1, true)""") env.cr.execute(""" INSERT INTO ir_model_data (module, name, model, res_id, noupdate) (SELECT module, 'partner_admin', model, res_id, noupdate FROM ir_model_data WHERE module = 'base' AND name = 'partner_root') """) fix_lang_constraints(env) fix_lang_table(env) # fast compute of res_model_name fill_ir_attachment_res_model_name(env.cr) # for migration of web module openupgrade.rename_columns( env.cr, {'res_company': [('external_report_layout', None)]}) # for migration of website module fill_ir_ui_view_key(env.cr) openupgrade.set_xml_ids_noupdate_value(env, 'base', [ 'default_template_user_config', 'view_menu', 'lang_km', ], False) # In Odoo 12.0, fields xmlids are noupdate FALSE instead of NULL and are # thus included when cleaning up obsolete data records in _process_end. openupgrade.logged_query( env.cr, """UPDATE ir_model_data SET noupdate=FALSE WHERE model='ir.model.fields' AND noupdate IS NULL""") # Fix potentiel duplicates in res_groups_users_rel fix_double_membership(env.cr)
def migrate(env, version): openupgrade.rename_columns(env.cr, {'res_partner': [ ('zip_id', None), ]}) openupgrade.remove_tables_fks(env.cr, ['res_better_zip'])
def migrate_mass_editing(env): """ Migrates mass.editing to ir.actions.server """ # Remove FK (mass_editing_id) openupgrade.remove_tables_fks(env.cr, ["mass_editing_line"]) # Add legacy mass_editing_id column to server_actions openupgrade.logged_query( env.cr, sql.SQL(""" ALTER TABLE ir_act_server ADD COLUMN {} int4 """).format( sql.Identifier(openupgrade.get_legacy_name("mass_editing_id")), ), ) # Optional migration for server_action_domain # We create the domain column if it's missing, in case the module hasn't # been installed yet. By doing so, we make sure the domain is available # if the module is installed after. openupgrade.logged_query( env.cr, """ ALTER TABLE ir_act_server ADD COLUMN IF NOT EXISTS domain varchar """, ) # Create ir.actions.server for each mass.editing openupgrade.logged_query( env.cr, sql.SQL(""" INSERT INTO ir_act_server ( {}, name, type, usage, binding_type, activity_user_type, state, model_id, model_name, domain ) SELECT me.id, COALESCE(me.action_name, me.name), 'ir.actions.server', 'ir_actions_server', 'action', 'specific', 'mass_edit', me.model_id, mo.model, me.domain FROM mass_editing me LEFT JOIN ir_model mo ON (me.model_id = mo.id) """).format( sql.Identifier(openupgrade.get_legacy_name("mass_editing_id"))), ) # Migrate mass.editing.line openupgrade.add_fields( env, [ ( "server_action_id", "mass.editing.line", "mass_editing_line", "integer", False, "mass_editing", ), ], ) openupgrade.logged_query( env.cr, sql.SQL( """ UPDATE mass_editing_line l SET server_action_id = sa.id FROM ir_act_server sa WHERE l.mass_editing_id = sa.{} """, ).format( sql.Identifier( openupgrade.get_legacy_name("mass_editing_id"))), ) # Delete fields that no longer exist (ondelete didn't exist before) openupgrade.logged_query( env.cr, """ DELETE FROM mass_editing_line WHERE field_id IS NULL OR field_id NOT IN (SELECT id FROM ir_model_fields) """, )