From 2ee4269045d1a7b5d2cfe6fff794638c67ba6709 Mon Sep 17 00:00:00 2001 From: Payam Yasaie Date: Wed, 8 Apr 2020 14:56:55 +0430 Subject: [PATCH 1/2] [MIG] project --- .../13.0.1.1/openupgrade_analysis_work.txt | 50 ++++++++++++++++++ .../migrations/13.0.1.1/post-migration.py | 8 +++ .../migrations/13.0.1.1/pre-migration.py | 51 +++++++++++++++++++ .../openupgrade/doc/source/modules120-130.rst | 2 +- 4 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 addons/project/migrations/13.0.1.1/openupgrade_analysis_work.txt create mode 100644 addons/project/migrations/13.0.1.1/post-migration.py create mode 100644 addons/project/migrations/13.0.1.1/pre-migration.py diff --git a/addons/project/migrations/13.0.1.1/openupgrade_analysis_work.txt b/addons/project/migrations/13.0.1.1/openupgrade_analysis_work.txt new file mode 100644 index 000000000000..1cc51ed49104 --- /dev/null +++ b/addons/project/migrations/13.0.1.1/openupgrade_analysis_work.txt @@ -0,0 +1,50 @@ +---Models in module 'project'--- +---Fields in module 'project'--- +project / account.analytic.account / project_count (integer) : previously in module hr_timesheet +project / account.analytic.account / project_ids (one2many) : previously in module hr_timesheet +project / project.project / analytic_account_id (many2one): previously in module hr_timesheet +# NOTHING TO DO: Moved to another module no data loss + +project / project.project / percentage_satisfaction_project (integer): DEL +project / project.project / percentage_satisfaction_task (integer): DEL +# NOTHING TO DO: Features removed + +project / project.project / rating_ids (one2many) : NEW relation: rating.rating +# NOTHING TO DO: New one2many field + +project / project.task / company_id (many2one) : now required, req_default: function +# DONE: pre-migration: filled the field when empty + +project / project.task / date_start (datetime) : DEL +project / project.task / notes (text) : DEL +project / project.task.type / legend_priority (char) : DEL +# NOTHING TO DO: Features removed + +---XML records in module 'project'--- +NEW ir.actions.act_window: project.portal_share_action +NEW ir.model.access: project.access_account_analytic_account_manager [renamed from hr_timesheet module] +NEW ir.model.access: project.access_account_analytic_account_user [renamed from hr_timesheet module] +NEW ir.model.access: project.access_account_analytic_line_project [renamed from hr_timesheet module] +# DONE: pre-migration (renamed) + +NEW ir.module.category: base.module_category_operations_project (noupdate) +# NOTHING TO DO: New record + +NEW ir.ui.view: project.account_analytic_account_view_form_inherit +NEW ir.ui.view: project.project_project_view_form_simplified_footer +NEW ir.ui.view: project.project_tags_tree_view +NEW ir.ui.view: project.project_task_view_activity +DEL ir.ui.view: project.qunit_suite +# NOTHING TO DO: noupdate=0 + +mail.message.subtype: project.mt_project_task_blocked (noupdate) (noupdate switched) +mail.message.subtype: project.mt_project_task_new (noupdate) (noupdate switched) +mail.message.subtype: project.mt_project_task_rating (noupdate) (noupdate switched) +mail.message.subtype: project.mt_project_task_ready (noupdate) (noupdate switched) +mail.message.subtype: project.mt_project_task_stage (noupdate) (noupdate switched) +mail.message.subtype: project.mt_task_blocked (noupdate) (noupdate switched) +mail.message.subtype: project.mt_task_new (noupdate) (noupdate switched) +mail.message.subtype: project.mt_task_rating (noupdate) (noupdate switched) +mail.message.subtype: project.mt_task_ready (noupdate) (noupdate switched) +mail.message.subtype: project.mt_task_stage (noupdate) (noupdate switched) +# DONE: pre-migration diff --git a/addons/project/migrations/13.0.1.1/post-migration.py b/addons/project/migrations/13.0.1.1/post-migration.py new file mode 100644 index 000000000000..9f4b1718d6bc --- /dev/null +++ b/addons/project/migrations/13.0.1.1/post-migration.py @@ -0,0 +1,8 @@ +# Copyright 2020 Payam Yasaie +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.load_data(env.cr, 'project', 'migrations/13.0.1.1/noupdate_changes.xml') diff --git a/addons/project/migrations/13.0.1.1/pre-migration.py b/addons/project/migrations/13.0.1.1/pre-migration.py new file mode 100644 index 000000000000..121bb43de0b6 --- /dev/null +++ b/addons/project/migrations/13.0.1.1/pre-migration.py @@ -0,0 +1,51 @@ +# Copyright 2020 Payam Yasaie +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openupgradelib import openupgrade + +_xmlid_renames = [ + ('hr_timesheet.access_account_analytic_account_manager', 'project.access_account_analytic_account_manager'), + ('hr_timesheet.access_account_analytic_account_user', 'project.access_account_analytic_account_user'), + ('hr_timesheet.access_account_analytic_line_project', 'project.access_account_analytic_line_project'), +] + + +def fill_project_task_company_id(cr): + openupgrade.logged_query( + cr, """ + UPDATE project_task pt + SET company_id = pp.company_id + FROM project_project pp + WHERE pp.id = pt.project_id AND pt.company_id IS NULL + """ + ) + openupgrade.logged_query( + cr, """ + UPDATE project_task pt + SET company_id = ru.company_id + FROM res_users ru + WHERE pt.project_id IS NULL AND pt.company_id IS NULL AND pt.create_uid = ru.id + """ + ) + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.rename_xmlids(env.cr, _xmlid_renames) + fill_project_task_company_id(env.cr) + openupgrade.set_xml_ids_noupdate_value( + env, + "project", + [ + "mt_project_task_blocked", + "mt_project_task_new", + "mt_project_task_rating", + "mt_project_task_ready", + "mt_project_task_stage", + "mt_task_blocked", + "mt_task_new", + "mt_task_rating", + "mt_task_ready", + "mt_task_stage", + ], + True, + ) diff --git a/odoo/openupgrade/doc/source/modules120-130.rst b/odoo/openupgrade/doc/source/modules120-130.rst index 175f4526f663..ba1b597f7aa8 100644 --- a/odoo/openupgrade/doc/source/modules120-130.rst +++ b/odoo/openupgrade/doc/source/modules120-130.rst @@ -533,7 +533,7 @@ missing in the new release are marked with |del|. +----------------------------------------------+-------------------------------------------------+ | |new| product_matrix | | +----------------------------------------------+-------------------------------------------------+ -|project | | +|project | Done | +----------------------------------------------+-------------------------------------------------+ |project_timesheet_holidays | | +----------------------------------------------+-------------------------------------------------+ From af0960f4b79d90560cf494b9c83a376eb15908ee Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Wed, 11 Nov 2020 19:37:15 +0100 Subject: [PATCH 2/2] [MIG+IMP] project: Finish migration scripts * Remove unneeded SQL, as company_id is required on project * Update module field definition --- .../13.0.1.1/openupgrade_analysis_work.txt | 6 ++-- .../migrations/13.0.1.1/pre-migration.py | 29 ++++++++++++++----- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/addons/project/migrations/13.0.1.1/openupgrade_analysis_work.txt b/addons/project/migrations/13.0.1.1/openupgrade_analysis_work.txt index 1cc51ed49104..50a4d0805975 100644 --- a/addons/project/migrations/13.0.1.1/openupgrade_analysis_work.txt +++ b/addons/project/migrations/13.0.1.1/openupgrade_analysis_work.txt @@ -3,7 +3,7 @@ project / account.analytic.account / project_count (integer) : previously in module hr_timesheet project / account.analytic.account / project_ids (one2many) : previously in module hr_timesheet project / project.project / analytic_account_id (many2one): previously in module hr_timesheet -# NOTHING TO DO: Moved to another module no data loss +# DONE: pre-migration: Update field definition project / project.project / percentage_satisfaction_project (integer): DEL project / project.project / percentage_satisfaction_task (integer): DEL @@ -21,7 +21,6 @@ project / project.task.type / legend_priority (char) : DEL # NOTHING TO DO: Features removed ---XML records in module 'project'--- -NEW ir.actions.act_window: project.portal_share_action NEW ir.model.access: project.access_account_analytic_account_manager [renamed from hr_timesheet module] NEW ir.model.access: project.access_account_analytic_account_user [renamed from hr_timesheet module] NEW ir.model.access: project.access_account_analytic_line_project [renamed from hr_timesheet module] @@ -30,12 +29,13 @@ NEW ir.model.access: project.access_account_analytic_line_project [renamed from NEW ir.module.category: base.module_category_operations_project (noupdate) # NOTHING TO DO: New record +NEW ir.actions.act_window: project.portal_share_action NEW ir.ui.view: project.account_analytic_account_view_form_inherit NEW ir.ui.view: project.project_project_view_form_simplified_footer NEW ir.ui.view: project.project_tags_tree_view NEW ir.ui.view: project.project_task_view_activity DEL ir.ui.view: project.qunit_suite -# NOTHING TO DO: noupdate=0 +# NOTHING TO DO: noupdate=0 ir records mail.message.subtype: project.mt_project_task_blocked (noupdate) (noupdate switched) mail.message.subtype: project.mt_project_task_new (noupdate) (noupdate switched) diff --git a/addons/project/migrations/13.0.1.1/pre-migration.py b/addons/project/migrations/13.0.1.1/pre-migration.py index 121bb43de0b6..68187343f02a 100644 --- a/addons/project/migrations/13.0.1.1/pre-migration.py +++ b/addons/project/migrations/13.0.1.1/pre-migration.py @@ -1,4 +1,5 @@ # Copyright 2020 Payam Yasaie +# Copyright 2020 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openupgradelib import openupgrade @@ -9,6 +10,25 @@ ] +def update_module_moved_fields(env): + if not openupgrade.is_module_installed(env.cr, "hr_timesheet"): + return + openupgrade.update_module_moved_fields( + env.cr, + "account.analytic.account", + ["project_count", "project_ids"], + "hr_timesheet", + "project", + ) + openupgrade.update_module_moved_fields( + env.cr, + "project.project", + ["analytic_account_id"], + "hr_timesheet", + "project", + ) + + def fill_project_task_company_id(cr): openupgrade.logged_query( cr, """ @@ -18,19 +38,12 @@ def fill_project_task_company_id(cr): WHERE pp.id = pt.project_id AND pt.company_id IS NULL """ ) - openupgrade.logged_query( - cr, """ - UPDATE project_task pt - SET company_id = ru.company_id - FROM res_users ru - WHERE pt.project_id IS NULL AND pt.company_id IS NULL AND pt.create_uid = ru.id - """ - ) @openupgrade.migrate() def migrate(env, version): openupgrade.rename_xmlids(env.cr, _xmlid_renames) + update_module_moved_fields(env) fill_project_task_company_id(env.cr) openupgrade.set_xml_ids_noupdate_value( env,