diff --git a/docsource/modules160-170.rst b/docsource/modules160-170.rst index 39b03c8be72..773334c81b3 100644 --- a/docsource/modules160-170.rst +++ b/docsource/modules160-170.rst @@ -40,7 +40,7 @@ Module coverage 16.0 -> 17.0 +---------------------------------------------------+----------------------+-------------------------------------------------+ | account_tax_python | | | +---------------------------------------------------+----------------------+-------------------------------------------------+ -| analytic | | | +| analytic | Done | | +---------------------------------------------------+----------------------+-------------------------------------------------+ | |del| association | |Merged into membership. | +---------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/analytic/17.0.1.1/post-migration.py b/openupgrade_scripts/scripts/analytic/17.0.1.1/post-migration.py new file mode 100644 index 00000000000..dd88553c724 --- /dev/null +++ b/openupgrade_scripts/scripts/analytic/17.0.1.1/post-migration.py @@ -0,0 +1,75 @@ +# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openupgradelib import openupgrade + +_deleted_xml_records = ["analytic.analytic_plan_comp_rule"] + + +def _analytic_line_create_x_plan_column(env): + """ + This method set system parameter for project analytic plan + and create dynamic field on analytic items using + '_sync_plan_column' method + """ + project_plan = ( + env.ref("analytic.analytic_plan_projects", raise_if_not_found=False) + or env["account.analytic.plan"] + ) + if project_plan: + env["ir.config_parameter"].set_param( + "analytic.project_plan", str(project_plan.id) + ) + plans_to_create_fields = env["account.analytic.plan"].search([]) + (plans_to_create_fields - project_plan)._sync_plan_column() + for plan in plans_to_create_fields - project_plan: + if plan.parent_id: + continue + column = plan._strict_column_name() + openupgrade.logged_query( + env.cr, + f""" + UPDATE account_analytic_line + SET {column} = account_id, + account_id = NULL + WHERE plan_id = {plan.id}; + """, + ) + + +def _analytic_plan_update_applicability_into_property(env): + """ + Manually create ir.property for default_applicability of account.analytic.plan + """ + vals_list = [] + field_id = ( + env["ir.model.fields"]._get("account.analytic.plan", "default_applicability").id + ) + env.cr.execute( + """ + SELECT id, default_applicability, company_id FROM account_analytic_plan + WHERE default_applicability != 'optional' + """ + ) + for plan_id, default_applicability, company_id in env.cr.fetchall(): + vals_list.append( + { + "fields_id": field_id, + "company_id": company_id, + "res_id": "account.analytic.plan,%s" % plan_id, + "name": "default_applicability", + "value": default_applicability, + "type": "selection", + } + ) + if vals_list: + env["ir.property"].create(vals_list) + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.delete_records_safely_by_xml_id( + env, + _deleted_xml_records, + ) + _analytic_line_create_x_plan_column(env) + _analytic_plan_update_applicability_into_property(env) diff --git a/openupgrade_scripts/scripts/analytic/17.0.1.1/pre-migration.py b/openupgrade_scripts/scripts/analytic/17.0.1.1/pre-migration.py new file mode 100644 index 00000000000..f542950d4c4 --- /dev/null +++ b/openupgrade_scripts/scripts/analytic/17.0.1.1/pre-migration.py @@ -0,0 +1,40 @@ +# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from openupgradelib import openupgrade + + +def _fill_config_parameter_analytic_project_plan(env): + env["ir.config_parameter"].set_param("analytic.project_plan", "1") + + +def _analytic_applicability_fill_company_id(env): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE account_analytic_applicability + ADD COLUMN IF NOT EXISTS company_id INTEGER; + """, + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE account_analytic_applicability t1 + SET company_id = t2.company_id + FROM account_analytic_plan t2 + WHERE t1.analytic_plan_id = t2.id + """, + ) + + +@openupgrade.migrate() +def migrate(env, version): + _fill_config_parameter_analytic_project_plan(env) + _analytic_applicability_fill_company_id(env) + # Drop triagram index on name column of account.analytic.account + # to avoid error when loading registry, it will be recreated + openupgrade.logged_query( + env.cr, + """ + DROP INDEX IF EXISTS account_analytic_account_name_index; + """, + ) diff --git a/openupgrade_scripts/scripts/analytic/17.0.1.1/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/analytic/17.0.1.1/upgrade_analysis_work.txt new file mode 100644 index 00000000000..32936487c9c --- /dev/null +++ b/openupgrade_scripts/scripts/analytic/17.0.1.1/upgrade_analysis_work.txt @@ -0,0 +1,26 @@ +---Models in module 'analytic'--- +---Fields in module 'analytic'--- +analytic / account.analytic.account / message_main_attachment_id (many2one): DEL relation: ir.attachment +analytic / account.analytic.account / root_plan_id (many2one) : not a function anymore +analytic / account.analytic.account / root_plan_id (many2one) : now related +analytic / account.analytic.plan / _order : _order is now 'sequence asc, id' ('complete_name asc') +analytic / account.analytic.plan / sequence (integer) : NEW hasdefault: default +# NOTHING TO DO + +analytic / account.analytic.applicability / company_id (many2one) : NEW relation: res.company, hasdefault: default +analytic / account.analytic.plan / company_id (many2one) : DEL relation: res.company +# DONE pre-migration: create column and fill value using company in plan_id + +analytic / account.analytic.line / plan_id (many2one) : DEL relation: account.analytic.plan +# DONE post-migration: create dynamic x_plan_id column using '_sync_plan_column' method in analytic.plan, pr: https://github.com/odoo/odoo/pull/139225 + +analytic / account.analytic.plan / default_applicability (selection): not stored anymore +# DONE post-migration: create ir.property if default_applicability != 'optional' + +---XML records in module 'analytic'--- +NEW account.analytic.plan: analytic.analytic_plan_projects (noupdate) +NEW ir.rule: analytic.analytic_applicability_comp_rule (noupdate) +# NOTHING TO DO + +DEL ir.rule: analytic.analytic_plan_comp_rule (noupdate) +# DONE post-migration: delete xml-id