From e6dda9889c188141efbd1fb8e8502246b953baba Mon Sep 17 00:00:00 2001 From: Tran Truong Son Date: Mon, 3 Jul 2023 11:45:58 +0700 Subject: [PATCH] [OU-ADD] project: migration data --- docsource/modules150-160.rst | 2 +- .../project/16.0.1.2/post-migration.py | 6 + .../scripts/project/16.0.1.2/pre-migration.py | 170 ++++++++++++++++++ .../16.0.1.2/upgrade_analysis_work.txt | 108 +++++++++++ 4 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 openupgrade_scripts/scripts/project/16.0.1.2/post-migration.py create mode 100644 openupgrade_scripts/scripts/project/16.0.1.2/pre-migration.py create mode 100644 openupgrade_scripts/scripts/project/16.0.1.2/upgrade_analysis_work.txt diff --git a/docsource/modules150-160.rst b/docsource/modules150-160.rst index 8ffa4bd4193f..d9031b55ad04 100644 --- a/docsource/modules150-160.rst +++ b/docsource/modules150-160.rst @@ -640,7 +640,7 @@ Module coverage 15.0 -> 16.0 +-------------------------------------------------+----------------------+-------------------------------------------------+ | product_matrix | Nothing to do | | +-------------------------------------------------+----------------------+-------------------------------------------------+ -| project | | | +| project |Done | | +-------------------------------------------------+----------------------+-------------------------------------------------+ | |del| project_account | | | +-------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/project/16.0.1.2/post-migration.py b/openupgrade_scripts/scripts/project/16.0.1.2/post-migration.py new file mode 100644 index 000000000000..2ba15f4506f9 --- /dev/null +++ b/openupgrade_scripts/scripts/project/16.0.1.2/post-migration.py @@ -0,0 +1,6 @@ +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.load_data(env.cr, "project", "16.0.1.2/noupdate_changes.xml") diff --git a/openupgrade_scripts/scripts/project/16.0.1.2/pre-migration.py b/openupgrade_scripts/scripts/project/16.0.1.2/pre-migration.py new file mode 100644 index 000000000000..11a71d26faa7 --- /dev/null +++ b/openupgrade_scripts/scripts/project/16.0.1.2/pre-migration.py @@ -0,0 +1,170 @@ +from openupgradelib import openupgrade + + +def _create_column_for_avoiding_automatic_computing(env): + """ + Create some new columns in the database and set values for them + to avoid computing by ORM + """ + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE project_project + ADD COLUMN IF NOT EXISTS allow_milestones boolean; + """, + ) + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE project_task + ADD COLUMN IF NOT EXISTS is_analytic_account_id_changed boolean; + """, + ) + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE project_task + ADD COLUMN IF NOT EXISTS is_closed boolean; + """, + ) + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE project_task + ADD COLUMN IF NOT EXISTS ancestor_id integer; + """, + ) + + +def _fill_proejct_allow_milestones(env): + # Set True if had milestone + openupgrade.logged_query( + env.cr, + """ + WITH cte as ( + SELECT project_id, count(*) as milestone_count + FROM project_milestone + GROUP BY project_id + ) + + UPDATE project_project project + SET allow_milestones = CASE + WHEN cte.milestone_count > 0 THEN TRUE + ELSE FALSE + END + FROM cte + WHERE project.id = cte.project_id; + """, + ) + + +def _fill_project_last_update_status_if_null(env): + """ + In some cases, the user can go to the DB and reset the `last_update_status` + field to NULL. In version 16.0 it is necessary to reset it to `to_define` + because it has a `required` attribute. + """ + openupgrade.logged_query( + env.cr, + """ + UPDATE project_project project + SET last_update_status = 'to_define' + WHERE last_update_status IS NULL; + """, + ) + + +def _set_task_stage_type_to_fold_if_is_closed(env): + """ + In version 16.0, task stages with type `is_closed` will be removed. + just use the `fold` style instead. Therefore, it is necessary to define + the phase types as `is_closed` and return them to `fold` + """ + openupgrade.logged_query( + env.cr, + """ + UPDATE project_task_type + SET fold = TRUE + WHERE is_closed = TRUE; + """, + ) + + +def _fill_project_task_is_analytic_account_id_changed(env): + """ + `is_analytic_account_id_changed` is a new field at version 16.0. + It has a value of False if you have the same admin account as the project, + otherwise it will have a value of True + """ + openupgrade.logged_query( + env.cr, + """ + UPDATE project_task task + SET is_analytic_account_id_changed = CASE + WHEN project_id IS NOT NULL + AND task.project_id = project.id + AND task.analytic_account_id != project.analytic_account_id + THEN TRUE + ELSE FALSE + END + FROM project_project as project; + """, + ) + + +def _fill_project_task_is_closed(env): + # `is_closed` field will be store at version 16.0 + openupgrade.logged_query( + env.cr, + """ + UPDATE project_task task + SET is_closed = CASE + WHEN stage.fold = TRUE THEN TRUE + ELSE FALSE + END + FROM project_task_type stage + WHERE task.stage_id = stage.id; + """, + ) + + +def _fil_project_task_ancestor_id(env): + """ + New column at version 16.0. valid as the ancestor of the current task + """ + openupgrade.logged_query( + env.cr, + """ + WITH RECURSIVE task_ancestors AS ( + SELECT id, parent_id, id AS ancestor_id + FROM project_task + WHERE parent_id IS NULL + + UNION ALL + + SELECT pt.id, pt.parent_id, ta.ancestor_id + FROM project_task pt + INNER JOIN task_ancestors ta ON pt.parent_id = ta.id + ) + + UPDATE project_task pt + SET ancestor_id = ta.ancestor_id + FROM task_ancestors ta + WHERE pt.id = ta.id; + + UPDATE project_task pt + SET ancestor_id = NULL + WHERE id = ancestor_id; + """, + ) + + +@openupgrade.migrate() +def migrate(env, version): + _create_column_for_avoiding_automatic_computing(env) + _fill_project_last_update_status_if_null(env) + _fill_project_task_is_analytic_account_id_changed(env) + _set_task_stage_type_to_fold_if_is_closed(env) + _fill_project_task_is_analytic_account_id_changed(env) + _fill_project_task_is_closed(env) + _fil_project_task_ancestor_id(env) diff --git a/openupgrade_scripts/scripts/project/16.0.1.2/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/project/16.0.1.2/upgrade_analysis_work.txt new file mode 100644 index 000000000000..342673eed9e0 --- /dev/null +++ b/openupgrade_scripts/scripts/project/16.0.1.2/upgrade_analysis_work.txt @@ -0,0 +1,108 @@ +---Models in module 'project'--- +obsolete model project.delete.wizard [transient] +---Fields in module 'project'--- +project / account.analytic.tag / task_ids (many2many) : DEL relation: project.task +project / project.milestone / task_ids (one2many) : NEW relation: project.task +# NOTHING TO DO + +project / project.project / allow_milestones (boolean) : NEW hasdefault: default +# DONE pre-migration: Set True if this project had project_milestone + +project / project.project / last_update_status (selection): not a function anymore +project / project.project / last_update_status (selection): now required +project / project.project / last_update_status (selection): selection_keys is now '['at_risk', 'off_track', 'on_hold', 'on_track', 'to_define']' ('['at_risk', 'off_track', 'on_hold', 'on_track']') +# DONE: pre-migration: set value to `to_define` if last_update_status IS NULL + +project / project.project / task_properties_definition (properties_definition): NEW +project / project.tags / project_ids (many2many) : NEW relation: project.project +project / project.tags / task_ids (many2many) : NEW relation: project.task +# NOTHING TO DO + +project / project.task / analytic_tag_ids (many2many) : DEL relation: account.analytic.tag +# NOTHING TO DO + +project / project.task / ancestor_id (many2one) : NEW relation: project.task, isfunction: function, stored +# DONE: pre-migration: Add new column & set value for it + +project / project.task / is_analytic_account_id_changed (boolean): NEW isfunction: function, stored +# DONE: pre-migration: Add new column & set value for it + +project / project.task / is_blocked (boolean) : NEW isfunction: function, stored +# NOTHING TO DO: Hand by ORM + +project / project.task / is_closed (boolean) : is now stored +# DONE: pre-migration: Add new column & set value for it + +project / project.task / milestone_id (many2one) : NEW relation: project.milestone, hasdefault: compute +# NOTHING TO DO + +project / project.task / task_properties (properties) : NEW hasdefault: compute +# NOTHING TO DO + +project / project.task.type / is_closed (boolean) : DEL +# DONE: pre-migration: Move value to fold stage + +project / res.company / analytic_plan_id (many2one) : NEW relation: account.analytic.plan, hasdefault: compute +# NOTHING TO DO + +---XML records in module 'project'--- +NEW digest.tip: project.digest_tip_project_1 +NEW ir.actions.act_window: project.action_send_mail_project_project +NEW ir.actions.act_window: project.action_send_mail_project_task +NEW ir.actions.act_window: project.action_view_task_from_milestone +NEW ir.actions.act_window: project.open_view_project_all_config_group_stage +NEW ir.actions.act_window: project.project_sharing_project_task_action_sub_task +NEW ir.actions.act_window: project.project_task_action_sub_task +# NOTHING TO DO + +DEL ir.actions.act_window: project.project_milestone_all +NEW ir.actions.act_window.view: project.open_view_all_task_list_calendar +NEW ir.actions.act_window.view: project.open_view_all_task_list_kanban +NEW ir.actions.act_window.view: project.open_view_all_task_list_tree +NEW ir.actions.act_window.view: project.open_view_project_all_config_group_stage_kanban_action_view +NEW ir.actions.act_window.view: project.open_view_project_all_config_group_stage_tree_action_view +NEW ir.actions.act_window.view: project.project_all_task_activity_action_view +NEW ir.actions.act_window.view: project.project_all_task_calendar_action_view +NEW ir.actions.act_window.view: project.project_all_task_graph_action_view +NEW ir.actions.act_window.view: project.project_all_task_pivot_action_view +NEW ir.actions.act_window.view: project.project_sharing_subtasks_form_action_view +NEW ir.actions.act_window.view: project.project_sharing_subtasks_kanban_action_view +NEW ir.actions.act_window.view: project.project_sharing_subtasks_tree_action_view +NEW ir.actions.act_window.view: project.project_task_form_action_view +NEW ir.actions.act_window.view: project.project_task_kanban_action_view +NEW ir.actions.act_window.view: project.project_task_tree_action_view +NEW ir.actions.act_window.view: project.rating_rating_action_task_kanban +NEW ir.actions.act_window.view: project.rating_rating_action_view_project_rating_kanban +# NOTHING TO DO + +DEL ir.actions.server: project.unlink_project_action +NEW ir.model.access: project.access_project_task_burndown_chart_report_user +NEW ir.model.access: project.access_report_project_task_user_project_user +DEL ir.model.access: project.access_project_delete_wizard +# NOTHING TO DO + +NEW ir.rule: project.burndown_chart_project_manager_rule (noupdate) +NEW ir.rule: project.burndown_chart_project_user_rule (noupdate) +NEW ir.rule: project.report_project_task_manager_rule (noupdate) +NEW ir.rule: project.report_project_task_user_rule (noupdate) +# NOTHING TO DO + +NEW ir.ui.menu: project.menu_projects_config_group_stage +NEW ir.ui.view: project.rating_rating_project_view_kanban +NEW ir.ui.view: project.task_type_tree_inherited +NEW ir.ui.view: project.view_project_calendar +NEW ir.ui.view: project.view_project_config_kanban +NEW ir.ui.view: project.view_project_task_pivot_inherit +NEW ir.ui.view: project.view_project_task_type_unarchive_wizard +NEW ir.ui.view: project.view_task_all_calendar +NEW ir.ui.view: project.view_task_kanban_inherit_my_task +DEL ir.ui.view: project.project_collaborator_view_form +DEL ir.ui.view: project.project_delete_wizard_form +DEL ir.ui.view: project.project_task_burndown_chart_report_view_pivot +# NOTHING TO DO + +NEW mail.message.subtype: project.mt_project_update_create (noupdate) +NEW mail.message.subtype: project.mt_task_progress (noupdate) +NEW mail.message.subtype: project.mt_update_create (noupdate) +NEW res.groups: project.group_project_milestone +# NOTHING TO DO