From 9064d39180b247f1f9103f57e5074439ca4057d7 Mon Sep 17 00:00:00 2001 From: AaronHForgeFlow Date: Tue, 23 May 2023 11:50:37 +0200 Subject: [PATCH] [IMP] priupgrqade analytic_stages [FIX] project [IMP] openupgrade_scripts: project_stock to project_stock_link --- openupgrade_scripts/apriori.py | 2 ++ .../project/15.0.1.2/post-migration.py | 27 +++++++++++++++++++ .../scripts/project/15.0.1.2/pre-migration.py | 9 +++++++ 3 files changed, 38 insertions(+) diff --git a/openupgrade_scripts/apriori.py b/openupgrade_scripts/apriori.py index 082ede8ae7d3..fdda9de11e15 100644 --- a/openupgrade_scripts/apriori.py +++ b/openupgrade_scripts/apriori.py @@ -96,6 +96,8 @@ # OCA/website "website_google_analytics_4": "website", "website_snippet_timeline": "website", + # custom addons + "project_stock": "project_stock_link", } # only used here for upgrade_analysis diff --git a/openupgrade_scripts/scripts/project/15.0.1.2/post-migration.py b/openupgrade_scripts/scripts/project/15.0.1.2/post-migration.py index 6270eef36908..2d197c7b0a57 100644 --- a/openupgrade_scripts/scripts/project/15.0.1.2/post-migration.py +++ b/openupgrade_scripts/scripts/project/15.0.1.2/post-migration.py @@ -69,6 +69,32 @@ def _fill_project_task_display_project_id(env): """, ) +def _fill_project_project_stage(env): + # use data from analytic_account_stage + env.cr.execute(""" + alter table account_analytic_account drop constraint if exists account_analytic_account_stage_id_fkey; + """) + env.cr.execute(""" + UPDATE project_project_stage SET active = false; + INSERT INTO project_project_stage + (create_date, write_date, sequence, name, fold, create_uid, write_uid, active) + SELECT create_date, write_date, sequence, name, fold, create_uid, write_uid, true + FROM analytic_account_stage; + """) + env.cr.execute(""" + WITH BQ AS( + SELECT pps.id as pps_id, aas.id as aas_id from project_project_stage pps + INNER JOIN analytic_account_stage aas on aas.name = pps.name + WHERE pps.name = aas.name + ) + UPDATE account_analytic_account aaa + SET stage_id = ( + SELECT BQ.pps_id + FROM account_analytic_account aaa2 + JOIN BQ ON BQ.aas_id = aaa2.stage_id + AND aaa.id = aaa2.id); + """) + @openupgrade.migrate() def migrate(env, version): @@ -86,3 +112,4 @@ def migrate(env, version): "rating_project_request_email_template", ], ) + _fill_project_project_stage(env) diff --git a/openupgrade_scripts/scripts/project/15.0.1.2/pre-migration.py b/openupgrade_scripts/scripts/project/15.0.1.2/pre-migration.py index 54558bdbb5d2..ca7b0a2b5c70 100644 --- a/openupgrade_scripts/scripts/project/15.0.1.2/pre-migration.py +++ b/openupgrade_scripts/scripts/project/15.0.1.2/pre-migration.py @@ -59,6 +59,14 @@ def adapt_project_task_dependency(env): env.cr, {"task_dependencies_rel": [("dependency_task_id", "depends_on_id")]} ) +def save_stage_id(env): + if not openupgrade.column_exists(env.cr, "account_analytic_account", "old_stage_id"): + env.cr.execute( + "alter table account_analytic_account add column old_stage_id int;" + ) + env.cr.execute( + "update account_analytic_account set old_stage_id = stage_id;" + ) @openupgrade.migrate() def migrate(env, version): @@ -66,3 +74,4 @@ def migrate(env, version): adapt_project_task_dependency(env) fill_project_project_allow_task_dependencies(env) fill_project_project_last_update_status(env) + save_stage_id(env)