Skip to content

Commit

Permalink
[IMP] priupgrqade analytic_stages
Browse files Browse the repository at this point in the history
[FIX] project

[IMP] openupgrade_scripts: project_stock to project_stock_link
  • Loading branch information
AaronHForgeFlow committed Jan 15, 2024
1 parent 6a63efc commit 9064d39
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions openupgrade_scripts/apriori.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions openupgrade_scripts/scripts/project/15.0.1.2/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -86,3 +112,4 @@ def migrate(env, version):
"rating_project_request_email_template",
],
)
_fill_project_project_stage(env)
9 changes: 9 additions & 0 deletions openupgrade_scripts/scripts/project/15.0.1.2/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,19 @@ 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):
openupgrade.rename_columns(env.cr, _column_renames)
adapt_project_task_dependency(env)
fill_project_project_allow_task_dependencies(env)
fill_project_project_last_update_status(env)
save_stage_id(env)

0 comments on commit 9064d39

Please sign in to comment.