diff --git a/openupgrade_scripts/apriori.py b/openupgrade_scripts/apriori.py index e91211ef0680..ea123532cf84 100644 --- a/openupgrade_scripts/apriori.py +++ b/openupgrade_scripts/apriori.py @@ -91,6 +91,7 @@ "survey_description": "survey", # OCA/project "project_mail_chatter": "project", + "project_status": "project", "project_task_dependency": "project", "project_timeline_task_dependency": "project_timeline", # OCA/timesheet 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..a315b2d1ed3e 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 @@ -1,4 +1,7 @@ from openupgradelib import openupgrade +import logging + +_logger = logging.getLogger(__name__) def _convert_project_task_assigned_users(env): @@ -70,6 +73,27 @@ def _fill_project_task_display_project_id(env): ) +def _activate_project_stages_conditionally(env): + """Activate project stages if module project_status was installed""" + project_status = env["ir.module.module"].search( + [ + ("name", "=", "project_status"), + ], + limit=1, + ) + _logger.info("Sate of project_status: %s", project_status.state) + if project_status.state == "to upgrade": + _logger.info("project_status module was installed so enable project stages") + internal_group = env.ref("base.group_user") + stage_group = env.ref("project.group_project_stages") + internal_group.implied_ids += stage_group + + _logger.info("marking project_status as to be removed") + #env["ir.module.module"].search( + # [("name", "=", "project_status")], limit=1 + #).button_immediate_uninstall() + + @openupgrade.migrate() def migrate(env, version): _convert_project_task_assigned_users(env) @@ -77,6 +101,7 @@ def migrate(env, version): _add_followers_to_project_for_allowed_portal_users(env) _add_followers_to_task_for_allowed_users(env) _fill_project_task_display_project_id(env) + _activate_project_stages_conditionally(env) openupgrade.load_data(env.cr, "project", "15.0.1.2/noupdate_changes.xml") openupgrade.delete_record_translations( env.cr, 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 3c3b8a495088..84ce769dbb39 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 @@ -71,6 +71,59 @@ def rename_project_milestone_target_date(env): ) +def migrate_project_status(env): + """Migrate project_status module if installed to + project.project.stages. + """ + if openupgrade.table_exists(env.cr, "project_status"): + openupgrade.rename_tables( + env.cr, + [("project_status", "project_project_stage")], + ) + openupgrade.rename_columns( + env.cr, + { + "project_project_stage": [ + ("company_id", None), + ("description", None), + ("status_sequence", "sequence"), + ("is_closed", None), + ], + }, + ) + openupgrade.rename_columns( + env.cr, + { + "project_project": [ + ("project_status", "stage_id"), + ], + }, + ) + # Remove project_status views + xmlids_views = [ + "project.project_status_seq", + "project.project_status_view_list", + "project.project_status_action", + "project.project_status_menu", + "project.view_project", + "project.edit_project", + "project.project_project_view_form_simplified", + "project.project_view_kanban", + "project.view_project_project_filter", + ] + #xmlids_security = [ + # "project.project_status_company_rule", + # "project.project_status_user", + # "project.project_status_manager", + #] + openupgrade.delete_records_safely_by_xml_id( + env, xmlids_views, delete_childs=False + ) + #openupgrade.delete_records_safely_by_xml_id( + # env, xmlids_security, delete_childs=False + #) + + @openupgrade.migrate() def migrate(env, version): openupgrade.rename_columns(env.cr, _column_renames) @@ -78,3 +131,4 @@ def migrate(env, version): fill_project_project_allow_task_dependencies(env) fill_project_project_last_update_status(env) rename_project_milestone_target_date(env) + migrate_project_status(env)