def migrate(env, version): cr = env.cr install_new_modules(env.cr) if openupgrade.is_module_installed(env.cr, 'bank_view_improv'): openupgrade.update_module_names(env.cr, [('bank_view_improv', 'nsm_account')], merge_modules=True) if openupgrade.is_module_installed(env.cr, 'nsm_analytic'): openupgrade.update_module_names(env.cr, [('nsm_analytic', 'nsm_account')], merge_modules=True) if openupgrade.is_module_installed(env.cr, 'nsm_analytic_2'): openupgrade.update_module_names(env.cr, [('nsm_analytic_2', 'nsm_account')], merge_modules=True) if openupgrade.is_module_installed(env.cr, 'nsm_invoice_layout'): openupgrade.update_module_names( env.cr, [('nsm_invoice_layout', 'nsm_account')], merge_modules=True) if openupgrade.is_module_installed(env.cr, 'nsm_merge_to_print_supplier_invoices'): openupgrade.update_module_names( env.cr, [('nsm_merge_to_print_supplier_invoices', 'nsm_account')], merge_modules=True)
def migrate(env, version): install_new_modules(env.cr) openupgrade.rename_columns(env.cr, column_renames_account_payment) if openupgrade.is_module_installed(env.cr, 'account_direct_debit'): openupgrade.update_module_names( env.cr, [('account_direct_debit', 'account_payment_order')], merge_modules=True) if openupgrade.is_module_installed(env.cr, 'account_banking_payment_export'): openupgrade.update_module_names( env.cr, [('account_banking_payment_export', 'account_payment_order')], merge_modules=True) openupgrade.rename_columns(env.cr, column_renames_payment_export) migrate_payment_mode_types(env) if openupgrade.is_module_installed(env.cr, 'account_banking_payment_transfer'): openupgrade.rename_columns(env.cr, column_renames_payment_transfer) openupgrade.update_module_names( env.cr, [('account_banking_payment_transfer', 'account_payment_order')], merge_modules=True) openupgrade.rename_models(env.cr, models_renames) openupgrade.rename_tables(env.cr, table_renames) populate_computed_fields(env)
def migrate(env, version): if not version: return # Force recompute acc_type, issue with inheritance chain between base # module and base_iban with this module if openupgrade.is_module_installed(env.cr, 'base_iban'): env['res.partner.bank'].search([])._compute_acc_type()
def sale_expense_update_module_names_partial(cr): """We don't use openupgrade.update_module_names here because the field expense_policy is moved from the sale_expense module to the sale module but sale_expense still exists in odoo 10. Because the field name didn't change and we only deal with text field without constraints etc. we only have to change the related ir_model_data entries. """ new_name = 'sale' old_name = 'sale_expense' if not openupgrade.is_module_installed(cr, old_name): return # get moved model fields moved_fields = ['expense_policy'] cr.execute( """ SELECT id FROM ir_model_fields WHERE model = 'product.template' AND name in %s """, (moved_fields, )) field_ids = [r[0] for r in cr.fetchall()] # update ir_model_data, the subselect allows to avoid duplicated XML-IDs, query = ("UPDATE ir_model_data SET module = %s " "WHERE module = %s AND res_id IN %s AND name NOT IN " "(SELECT name FROM ir_model_data WHERE module = %s)") openupgrade.logged_query(cr, query, (new_name, old_name, field_ids, new_name)) # delete ir_translation because the translations changes completely query = ("DELETE FROM ir_translation " "WHERE module = %s AND res_id IN %s") openupgrade.logged_query(cr, query, (old_name, field_ids))
def fill_analytic_line_project(env): """Fill project with the linked one in the related task or issue.""" openupgrade.logged_query( env.cr, """ UPDATE account_analytic_line aal SET project_id = pt.project_id FROM project_task pt WHERE pt.id = aal.task_id AND pt.project_id IS NOT NULL AND aal.project_id IS NULL """, ) if not openupgrade.is_module_installed(env.cr, 'project_issue'): return # Don't perform next operation openupgrade.logged_query( env.cr, """ UPDATE account_analytic_line aal SET project_id = pi.project_id FROM project_issue pi WHERE pi.id = aal.issue_id AND pi.project_id IS NOT NULL AND aal.project_id IS NULL """, )
def migrate(env, version): install_new_modules(env.cr) if openupgrade.is_module_installed(env.cr, 'nsm_supportal_extension'): openupgrade.update_module_names( env.cr, [('nsm_supportal_extension', 'nsm_supplier_portal')], merge_modules=True)
def migrate(cr, version): openupgrade.copy_columns(cr, column_copies) openupgrade.rename_tables(cr, table_renames) openupgrade.rename_columns(cr, column_renames) openupgrade.rename_xmlids(cr, xmlid_renames) if not openupgrade.is_module_installed(cr, 'project_timesheet'): recreate_analytic_lines(cr) cr.execute('''update ir_module_module set state='to install' where name='project_timesheet' and state in ('uninstalled', 'to remove') and exists (select id from ir_module_module where name='hr_timesheet' and state in ('to upgrade', 'to_install', 'installed'))''')
def migrate_sale_layout(env): # We need to manually removed these views because the cleanup is done # after YAML demo data is loaded and there's an error on that phase env.cr.execute( """ DELETE FROM ir_ui_view WHERE NAME in %s """, (tuple([ 'sale.order.form.inherit_1', 'account.invoice.form.inherit_1', 'account.invoice.line.form.inherit_2', ]), )) if openupgrade.is_module_installed(env.cr, 'sale_layout'): openupgrade.rename_columns(env.cr, column_renames_sale_layout) openupgrade.rename_models(env.cr, model_renames_sale_layout)
def migrate(env, version): if not version: return # Force recompute acc_type, issue with inheritance chain between base # module and base_iban with this module if openupgrade.is_module_installed(env.cr, 'base_iban'): env['res.partner.bank'].search([])._compute_acc_type() # Store payment_type in store related field openupgrade.logged_query( env.cr, """ UPDATE account_payment_mode apm SET payment_type = pm.payment_type FROM account_payment_method pm WHERE apm.payment_method_id = pm.id WHERE payment_type IS NULL; """)
def migrate_account_invoice_shipping_address(cr): """The feature of this module is now on core, so we merge and change data accordingly. """ module_name = 'account_invoice_shipping_address' if not openupgrade.is_module_installed(cr, module_name): return openupgrade.update_module_names( cr, [(module_name, 'sale')], merge_modules=True, ) openupgrade.rename_columns( cr, [('address_shipping_id', 'partner_shipping_id')], )
def update_module_moved_fields(env): if not openupgrade.is_module_installed(env.cr, "hr_timesheet"): return openupgrade.update_module_moved_fields( env.cr, "account.analytic.account", ["project_count", "project_ids"], "hr_timesheet", "project", ) openupgrade.update_module_moved_fields( env.cr, "project.project", ["analytic_account_id"], "hr_timesheet", "project", )
def assign_security_groups(env): """Assign the group that has been unfolded in 2 in the new version to the users that had the old one. Assign also the warning group if the old module is installed. :param env: Environment """ users = env['res.users'].search([ ('groups_id', '=', env.ref('stock.group_stock_multi_locations').id) ]) users.write({ 'groups_id': [(4, env.ref('stock.group_stock_multi_warehouses').id)], }) if openupgrade.is_module_installed(env.cr, 'warning'): env['res.users'].search([]).write({ 'groups_id': [(4, env.ref('stock.group_warning_stock').id)], })
def rename_old_italian_module(cr): if not openupgrade.is_module_installed(cr, "l10n_it_esigibilita_iva"): return openupgrade.rename_xmlids( cr, [ ( "l10n_it_esigibilita_iva.view_tax_code_esigibilita_form", "l10n_it_vat_payability.view_tax_code_payability_form", ), ], ) openupgrade.update_module_names( cr, [ ("l10n_it_esigibilita_iva", "l10n_it_vat_payability"), ], merge_modules=True, )
def warning_update_module_names_partial(cr): """We don't use openupgrade.update_module_names here because only the fields sale_line_warn, sale_line_warn_msg, sale_warn and sale_warn_msg are moved from the old warning module to the sale module. Other fields are moved in other modules (e. g. field purchase_warn in purchase module). If we would using openupgrade.update_module_names there might be problems when first use openupgrade.update_module_names in sale module and then again in purchase module and so on. Because the field names didn't change and we only deal with text fields without constraints etc. we only have to change the related ir_model_data and ir_translation entries. """ new_name = 'sale' old_name = 'warning' if not openupgrade.is_module_installed(cr, old_name): return # get moved model fields moved_fields = [ 'sale_line_warn', 'sale_line_warn_msg', 'sale_warn', 'sale_warn_msg' ] cr.execute( """ SELECT id FROM ir_model_fields WHERE model IN ('res.partner', 'product.template') AND name in %s """, (moved_fields, )) field_ids = [r[0] for r in cr.fetchall()] # update ir_model_data, the subselect allows to avoid duplicated XML-IDs query = ("UPDATE ir_model_data SET module = %s " "WHERE module = %s AND res_id IN %s AND name NOT IN " "(SELECT name FROM ir_model_data WHERE module = %s)") openupgrade.logged_query(cr, query, (new_name, old_name, field_ids, new_name)) # update ir_translation query = ("UPDATE ir_translation SET module = %s " "WHERE module = %s AND res_id IN %s") openupgrade.logged_query(cr, query, (new_name, old_name, field_ids))
def migrate_account_auto_fy_sequence(env): """As now Odoo implements a feature for having several sequence numbers per date range, we don't need anymore this module. This handles a smooth transition from v8 having it installed to v9 properly configured and without the module. """ if not openupgrade.is_module_installed(env.cr, 'account_auto_fy_sequence'): return # Merge with the main module for avoid uninstallation of dependent modules openupgrade.update_module_names( env.cr, [('account_auto_fy_sequence', 'account')], merge_modules=True, ) query = """ UPDATE ir_sequence SET {0}=replace({0}, '%(fy)s', '%(range_year)s'), use_date_range=True WHERE {0} like '%\%(fy)s%' """ env.cr.execute(query.format('prefix')) env.cr.execute(query.format('suffix'))
def fill_analytic_line_project(env): """Fill project with the linked one in the related task, issue, or project related to the analytic account.""" openupgrade.logged_query( env.cr, """ UPDATE account_analytic_line aal SET project_id = pt.project_id FROM project_task pt WHERE pt.id = aal.task_id AND pt.project_id IS NOT NULL AND aal.project_id IS NULL """, ) if openupgrade.is_module_installed(env.cr, 'project_issue'): openupgrade.logged_query( env.cr, """ UPDATE account_analytic_line aal SET project_id = pi.project_id FROM project_issue pi WHERE pi.id = aal.issue_id AND pi.project_id IS NOT NULL AND aal.project_id IS NULL """, ) # Finally, try to link the rest of the lines that are not linked to a # task nor an issue to the project associated with the analytic account openupgrade.logged_query( env.cr, """ UPDATE account_analytic_line aal SET project_id = pp.id FROM project_project pp WHERE pp.analytic_account_id = aal.account_id AND aal.project_id IS NULL AND aal.is_timesheet IS True """, )
def rename_old_italian_module(cr): if not openupgrade.is_module_installed(cr, "l10n_it_withholding_tax_causali"): return openupgrade.rename_xmlids( cr, [ ( "l10n_it_withholding_tax_causali.view_withholding_tax_form_causale", "l10n_it_withholding_tax_causali.view_withholding_tax_form_reason", ), ], ) openupgrade.update_module_names( cr, [ ("l10n_it_withholding_tax_causali", "l10n_it_withholding_tax_reason"), ], merge_modules=True, )
def migrate(env, version): set_sale_order_qty_delivered(env) if openupgrade.is_module_installed(env.cr, 'stock_account'): set_product_template_invoice_policy_delivery(env) set_incoterm_group(env) set_invoice_incoterms_id(env)
def migrate(cr, version): if openupgrade.is_module_installed(cr, 'im_chat'): openupgrade.rename_tables(cr, [('im_chat_presence', 'bus_presence')])
def migrate(env, version): if openupgrade.is_module_installed(env.cr, 'website_crm'): openupgrade.rename_xmlids(env.cr, _xmlid_renames)
def migrate(cr, version): if openupgrade.is_module_installed(cr, 'stock_account'): openupgrade.rename_columns(cr, {'stock_move': [('invoice_state', None)]})
def migrate(cr, version): map_bank_state(cr) map_type_tax_use(cr) map_type_tax_use_template(cr) map_journal_state(cr) account_templates(cr) parent_id_to_m2m(cr) cashbox(cr) account_properties(cr) # If the close_method is 'none', then set to 'False', otherwise set to # 'True' cr.execute(""" UPDATE account_account_type SET include_initial_balance = CASE WHEN %(openupgrade)s = 'none' THEN False ELSE True END """ % {'openupgrade': openupgrade.get_legacy_name('close_method')}) # Set bank_statements_source to 'manual' cr.execute(""" UPDATE account_journal SET bank_statements_source = 'manual' """) # Value 'percentage_of_total' => 'percentage' cr.execute(""" UPDATE account_operation_template SET amount_type = 'percentage' WHERE amount_type = 'percentage_of_total' """) # Set up anglosaxon accounting cr.execute( "UPDATE res_company SET anglo_saxon_accounting = %s", (openupgrade.is_module_installed(cr, 'account_anglo_saxon'), ), ) # deprecate accounts where active is False cr.execute(""" UPDATE account_account SET deprecated = True WHERE active = False """) # Set display_on_footer to False cr.execute(""" UPDATE account_journal SET display_on_footer = False """) # Logic to move from child_ids to children_tax_ids (o2m => m2m) cr.execute(""" INSERT INTO account_tax_filiation_rel (parent_tax, child_tax) SELECT parent_id, id from account_tax WHERE parent_id IS NOT NULL """) # Get parent_id and insert it into children_tax_ids (m2o => m2m) cr.execute(""" INSERT INTO account_tax_template_filiation_rel (parent_tax, child_tax) SELECT parent_id, id from account_tax_template WHERE parent_id IS NOT NULL """) # In v8, if child_depend == True, then in v9, set amount_type='group' cr.execute(""" UPDATE account_tax SET amount_type = 'group' WHERE child_depend IS True """) cr.execute(""" UPDATE account_tax_template SET amount_type = 'group' WHERE child_depend IS True """) registry = RegistryManager.get(cr.dbname) openupgrade.m2o_to_x2m( cr, registry['account.bank.statement.line'], 'account_bank_statement_line', 'journal_entry_ids', openupgrade.get_legacy_name('journal_entry_id'), ) parent_id_to_tag(cr, 'account.tax') parent_id_to_tag(cr, 'account.account', recursive=True) account_internal_type(cr)
def rename_old_italian_module(cr): """ Move data and fields from italian module `l10n_it_dichiarazione_intento` to this module. """ old_module_name = "l10n_it_dichiarazione_intento" if not openupgrade.is_module_installed(cr, old_module_name): return new_module_name = "l10n_it_declaration_of_intent" env = api.Environment(cr, SUPERUSER_ID, {}) old_sequence = env["ir.model.data"].get_object( old_module_name, "dichiarazione_intento_seq") old_sequence.code = "declaration_of_intent" renamed_fields = [ ( "res.company", "res_company", "dichiarazione_yearly_limit_ids", "declaration_yearly_limit_ids", ), ( "dichiarazione.intento.yearly.limit", "dichiarazione_intento_yearly_limit", "dichiarazione_id", "declaration_id", ), ( "dichiarazione.intento.line", "dichiarazione_intento_line", "dichiarazione_id", "declaration_id", ), ( "account.fiscal.position", "account_fiscal_position", "valid_for_dichiarazione_intento", "valid_for_declaration_of_intent", ), ( "account.move.line", "account_move_line", "force_dichiarazione_intento_id", "force_declaration_of_intent_id", ), ( "account.move", "account_move", "dichiarazione_intento_ids", "declaration_of_intent_ids", ), ] openupgrade.rename_fields( env, renamed_fields, ) renamed_models = [ ( "dichiarazione.intento.yearly.limit", "l10n_it_declaration_of_intent.yearly_limit", ), ("dichiarazione.intento", "l10n_it_declaration_of_intent.declaration"), ( "dichiarazione.intento.line", "l10n_it_declaration_of_intent.declaration_line", ), ] openupgrade.rename_models( cr, renamed_models, ) renamed_tables = [( old_model.replace(".", "_"), new_model.replace(".", "_"), ) for old_model, new_model in renamed_models] openupgrade.rename_tables( cr, renamed_tables, ) renamed_xmlids = [ ("access_dichiarazione_intento", "access_declaration_of_intent"), ("access_dichiarazione_intento_base", "access_declaration_of_intent_base"), ("access_dichiarazione_intento_line", "access_declaration_of_intent_line"), ( "access_dichiarazione_intento_yearly_limit", "access_declaration_of_intent_yearly_limit", ), ("dichiarazione_intento_seq", "declaration_of_intent_seq"), ("dichiarazione_intento_invoice_form", "declaration_of_intent_invoice_form"), ( "dichiarazione_intento_invoice_line_form", "declaration_of_intent_invoice_line_form", ), ( "dichiarazione_intento_account_position_form", "declaration_of_intent_account_position_form", ), ( "dichiarazione_intento_view_company_form", "declaration_of_intent_view_company_form", ), ("dichiarazione_intento_form", "declaration_of_intent_form"), ("dichiarazione_intento_search", "declaration_of_intent_search"), ("dichiarazione_intento_tree", "declaration_of_intent_tree"), ("dichiarazione_intento_action", "declaration_of_intent_action"), ("dichiarazione_intento_menu", "declaration_of_intent_menu"), ] renamed_xmlids = [(".".join([old_module_name, old_xmlid]), ".".join([new_module_name, new_xmlid])) for (old_xmlid, new_xmlid) in renamed_xmlids] openupgrade.rename_xmlids( cr, renamed_xmlids, ) renamed_modules = [ (old_module_name, new_module_name), ] openupgrade.update_module_names( cr, renamed_modules, merge_modules=True, )
def migrate(env, version): cr = env.cr map_bank_state(cr) map_type_tax_use(cr) map_type_tax_use_template(cr) map_journal_state(cr) openupgrade_90.replace_account_types(env, account_type_map) account_templates(env) parent_id_to_m2m(cr) cashbox(cr) account_properties(cr) # If the close_method is 'none', then set to 'False', otherwise set to # 'True' cr.execute(""" UPDATE account_account_type SET include_initial_balance = CASE WHEN %(openupgrade)s = 'none' THEN False ELSE True END """ % {'openupgrade': openupgrade.get_legacy_name('close_method')}) # Set bank_statements_source to 'manual' cr.execute(""" UPDATE account_journal SET bank_statements_source = 'manual' """) # Value 'percentage_of_total' => 'percentage' cr.execute(""" UPDATE account_operation_template SET amount_type = 'percentage' WHERE amount_type = 'percentage_of_total' """) # Set up anglosaxon accounting cr.execute( "UPDATE res_company SET anglo_saxon_accounting = %s", (openupgrade.is_module_installed(cr, 'account_anglo_saxon'), ), ) # deprecate accounts where active is False cr.execute(""" UPDATE account_account SET deprecated = True WHERE active = False """) # Set display_on_footer to False cr.execute(""" UPDATE account_journal SET display_on_footer = False """) # Logic to move from child_ids to children_tax_ids (o2m => m2m) cr.execute(""" INSERT INTO account_tax_filiation_rel (parent_tax, child_tax) SELECT parent_id, id from account_tax WHERE parent_id IS NOT NULL """) # Get parent_id and insert it into children_tax_ids (m2o => m2m) cr.execute(""" INSERT INTO account_tax_template_filiation_rel (parent_tax, child_tax) SELECT parent_id, id from account_tax_template WHERE parent_id IS NOT NULL """) # In v8, if child_depend == True, then in v9, set amount_type='group' cr.execute(""" UPDATE account_tax SET amount_type = 'group' WHERE child_depend IS True """) cr.execute(""" UPDATE account_tax_template SET amount_type = 'group' WHERE child_depend IS True """) # In v9, percentages are expressed as hundred-based percentage, # not one-based percentage cr.execute('UPDATE account_tax set amount=amount*100 ' "WHERE amount_type='percent'") registry = RegistryManager.get(cr.dbname) openupgrade.m2o_to_x2m( cr, registry['account.bank.statement.line'], 'account_bank_statement_line', 'journal_entry_ids', openupgrade.get_legacy_name('journal_entry_id'), ) parent_id_to_tag(env, 'account.tax') parent_id_to_tag(env, 'account.account', recursive=True) move_view_accounts(env) account_internal_type(env) map_account_tax_type(cr) map_account_tax_template_type(cr) migrate_account_sequence_fiscalyear(cr) migrate_account_auto_fy_sequence(env) fill_move_taxes(env) fill_blacklisted_fields(cr) reset_blacklist_field_recomputation() fill_move_line_invoice(cr) merge_invoice_journals(env) update_account_invoice_date(cr) update_move_date(cr) fill_bank_accounts(cr) openupgrade.load_data( cr, 'account', 'migrations/9.0.1.1/noupdate_changes.xml', )
def migrate_l10n_fr_siret_field(env): """If l10n_fr_siret is installed in version 10.0, we must rename xmlid""" if openupgrade.is_module_installed(env.cr, 'l10n_fr_siret'): openupgrade.rename_xmlids(env.cr, ('l10n_fr_siret.field_res_partner_siret', 'l10n_fr.field_res_partner_siret'))