diff --git a/docsource/modules160-170.rst b/docsource/modules160-170.rst index 39b03c8be720..773334c81b32 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 000000000000..516c6950b600 --- /dev/null +++ b/openupgrade_scripts/scripts/analytic/17.0.1.1/post-migration.py @@ -0,0 +1,92 @@ +# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo) +# Copyright 2024 Hunki enterprises - Holger Brunn +# Copyright 2024 Tecnativa - Pedro M. Baeza +# 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 _adjust_analytic_plan_sequence(env): + """As now the order is by sequence, and on v16 it was the id, we have to assign the + sequence numbers to preserve the previous order by default, for not having any + undesired modification. Once in v17, you can redefine the order to your + choice if desired. + """ + openupgrade.logged_query( + env.cr, + """ + UPDATE account_analytic_plan aap + SET sequence = sub.row_number + FROM ( + SELECT id, row_number() + OVER (PARTITION BY True order by id) + FROM account_analytic_plan + ) as sub + WHERE sub.id = aap.id + """, + ) + + +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): + """ + Create ir.property for default_applicability of account.analytic.plan + in all companies as the company_id field was shifted from account.analytic.plan + to account.analytic.applicability + """ + env.cr.execute( + """ + SELECT id, default_applicability FROM account_analytic_plan + WHERE default_applicability != 'optional' + """ + ) + values = dict(env.cr.fetchall()) + for company in env["res.company"].search([]): + env["ir.property"].with_company(company)._set_multi( + "default_applicability", + "account.analytic.plan", + values, + ) + + +@openupgrade.migrate() +def migrate(env, version): + _adjust_analytic_plan_sequence(env) + openupgrade.load_data(env, "analytic", "17.0.1.1/noupdate_changes.xml") + 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 000000000000..c5587709d993 --- /dev/null +++ b/openupgrade_scripts/scripts/analytic/17.0.1.1/pre-migration.py @@ -0,0 +1,38 @@ +# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo) +# Copyright 2024 Hunki enterprises - Holger Brunn +# Copyright 2024 Tecnativa - Pedro M. Baeza +# 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.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; + """, + ) + # Save company_id field of analytic plans for modules reinstating this + # to pick up + openupgrade.copy_columns( + env.cr, {"account_analytic_plan": [("company_id", None, None)]} + ) 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 000000000000..098e371ba9a8 --- /dev/null +++ b/openupgrade_scripts/scripts/analytic/17.0.1.1/upgrade_analysis_work.txt @@ -0,0 +1,30 @@ +---Models in module 'analytic'--- +---Fields in module 'analytic'--- +analytic / account.analytic.account / message_main_attachment_id (many2one): DEL relation: ir.attachment +# NOTHING TO DO: Feature mainly not used + +analytic / account.analytic.account / root_plan_id (many2one) : not a function anymore +analytic / account.analytic.account / root_plan_id (many2one) : now related +# NOTHING TO DO: The related is equivalent to the previous compute + +analytic / account.analytic.plan / _order : _order is now 'sequence asc, id' ('complete_name asc') +analytic / account.analytic.plan / sequence (integer) : NEW hasdefault: default +# DONE: post-migration: Set sequence for following the same order than in previous version + +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 let empty value, as it's what preserves the previous behavior + +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: try to delete safely the record