From ce6e58b1268ed3b8c42abc8826478e159ade7619 Mon Sep 17 00:00:00 2001 From: Chankya Soni Date: Mon, 21 Jun 2021 13:21:29 +0530 Subject: [PATCH 1/3] [14.0][ADD] hr: migrate --- .../hr/14.0.1.1/openupgrade_analysis_work.txt | 26 +++++++++++++++++++ .../scripts/hr/14.0.1.1/post-migrate.py | 21 +++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 openupgrade_scripts/scripts/hr/14.0.1.1/openupgrade_analysis_work.txt create mode 100644 openupgrade_scripts/scripts/hr/14.0.1.1/post-migrate.py diff --git a/openupgrade_scripts/scripts/hr/14.0.1.1/openupgrade_analysis_work.txt b/openupgrade_scripts/scripts/hr/14.0.1.1/openupgrade_analysis_work.txt new file mode 100644 index 000000000000..299b063d851e --- /dev/null +++ b/openupgrade_scripts/scripts/hr/14.0.1.1/openupgrade_analysis_work.txt @@ -0,0 +1,26 @@ +---Models in module 'hr'--- +---Fields in module 'hr'--- +hr / hr.employee / address_id (many2one) : now a function +hr / hr.employee / certificate (selection) : selection_keys is now '['bachelor', 'doctor', 'graduate', 'master', 'other']' ('['bachelor', 'master', 'other']') +hr / hr.employee / coach_id (many2one) : now a function +hr / hr.employee / company_id (many2one) : now required, req_default: function +# DONE: Post-migration: Filled with Create user company_id +hr / hr.employee / departure_date (date) : NEW +hr / hr.employee / job_title (char) : now a function +hr / hr.employee / parent_id (many2one) : now a function +hr / hr.employee / work_phone (char) : now a function +hr / hr.plan.activity.type / summary (char) : now a function +hr / res.users / barcode (char) : module is now 'base' ('hr') +---XML records in module 'hr'--- +NEW ir.actions.act_window: hr.hr_department_kanban_action +NEW ir.actions.act_window: hr.hr_department_tree_action +DEL ir.actions.act_window: hr.open_module_tree_department +NEW ir.model.access: hr.access_hr_departure_wizard +NEW ir.model.access: hr.access_hr_plan_wizard +DEL ir.model.access: hr.access_ir_property_hr_user +NEW ir.ui.menu: hr.menu_hr_department_kanban +NEW ir.ui.view: hr.qunit_suite +DEL mail.template: hr.mail_template_data_unknown_employee_email_address (noupdate) +NEW res.partner: hr.res_partner_admin_private_address (noupdate) +hr.employee: hr.employee_admin (noupdate) +# DONE: post-migration: noupdate changed to "res_partner_admin_private_address" diff --git a/openupgrade_scripts/scripts/hr/14.0.1.1/post-migrate.py b/openupgrade_scripts/scripts/hr/14.0.1.1/post-migrate.py new file mode 100644 index 000000000000..b37056f2d40b --- /dev/null +++ b/openupgrade_scripts/scripts/hr/14.0.1.1/post-migrate.py @@ -0,0 +1,21 @@ +# Copyright (C) 2021 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from openupgradelib import openupgrade + +def fill_hr_employee_company_id(env): + openupgrade.logged_query( + env.cr, """ + UPDATE hr_employee hr + SET company_id = ru.company_id + FROM res_users ru + WHERE ru.id = hr.create_uid AND + hr.company_id is NULL + """, + ) + + +@openupgrade.migrate() +def migrate(env, version): + fill_hr_employee_company_id(env) + # Load noupdate changes + openupgrade.load_data(env.cr, "hr", "14.0.1.1/noupdate_changes.xml") From 9e4b4a6c213ea6780135ee19e33f54e8be61a3f6 Mon Sep 17 00:00:00 2001 From: mreficent Date: Tue, 6 Jul 2021 12:31:49 +0200 Subject: [PATCH 2/3] [MIG] hr (continuation) --- docsource/modules130-140.rst | 2 +- .../scripts/hr/14.0.1.1/noupdate_changes.xml | 8 +++--- .../scripts/hr/14.0.1.1/post-migrate.py | 28 ++++++++++++++++--- ...sis_work.txt => upgrade_analysis_work.txt} | 12 ++++++-- 4 files changed, 39 insertions(+), 11 deletions(-) rename openupgrade_scripts/scripts/hr/14.0.1.1/{openupgrade_analysis_work.txt => upgrade_analysis_work.txt} (90%) diff --git a/docsource/modules130-140.rst b/docsource/modules130-140.rst index ee713d1ca55a..7db4b74ca618 100644 --- a/docsource/modules130-140.rst +++ b/docsource/modules130-140.rst @@ -150,7 +150,7 @@ Module coverage 13.0 -> 14.0 +--------------------------------------------+-------------------------------------------------+ |google_spreadsheet | | +--------------------------------------------+-------------------------------------------------+ -|hr | | +|hr | Done | +--------------------------------------------+-------------------------------------------------+ |hr_attendance | | +--------------------------------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/hr/14.0.1.1/noupdate_changes.xml b/openupgrade_scripts/scripts/hr/14.0.1.1/noupdate_changes.xml index 4316bb75c645..6f68b8ed3bb7 100644 --- a/openupgrade_scripts/scripts/hr/14.0.1.1/noupdate_changes.xml +++ b/openupgrade_scripts/scripts/hr/14.0.1.1/noupdate_changes.xml @@ -4,15 +4,15 @@ - + - + - + - + diff --git a/openupgrade_scripts/scripts/hr/14.0.1.1/post-migrate.py b/openupgrade_scripts/scripts/hr/14.0.1.1/post-migrate.py index b37056f2d40b..07893f71061b 100644 --- a/openupgrade_scripts/scripts/hr/14.0.1.1/post-migrate.py +++ b/openupgrade_scripts/scripts/hr/14.0.1.1/post-migrate.py @@ -2,20 +2,40 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from openupgradelib import openupgrade + def fill_hr_employee_company_id(env): openupgrade.logged_query( - env.cr, """ + env.cr, + """ UPDATE hr_employee hr SET company_id = ru.company_id FROM res_users ru - WHERE ru.id = hr.create_uid AND - hr.company_id is NULL + WHERE ru.id = hr.create_uid AND hr.company_id is NULL """, ) +def update_new_private_admin_partner(env): + private_partner = env.ref("hr.res_partner_admin_private_address") + public_partner = env.ref("hr.employee_admin").address_home_id + private_partner.update( + { + "name": public_partner.name, + "company_id": public_partner.company_id, + "email": public_partner.email, + "image_1920": public_partner.image_1920, + } + ) + + @openupgrade.migrate() def migrate(env, version): fill_hr_employee_company_id(env) - # Load noupdate changes + update_new_private_admin_partner(env) openupgrade.load_data(env.cr, "hr", "14.0.1.1/noupdate_changes.xml") + openupgrade.delete_record_translations( + env.cr, "hr", ["mail_template_data_unknown_employee_email_address"] + ) + openupgrade.delete_records_safely_by_xml_id( + env.cr, ["hr.mail_template_data_unknown_employee_email_address"] + ) diff --git a/openupgrade_scripts/scripts/hr/14.0.1.1/openupgrade_analysis_work.txt b/openupgrade_scripts/scripts/hr/14.0.1.1/upgrade_analysis_work.txt similarity index 90% rename from openupgrade_scripts/scripts/hr/14.0.1.1/openupgrade_analysis_work.txt rename to openupgrade_scripts/scripts/hr/14.0.1.1/upgrade_analysis_work.txt index 299b063d851e..6fdf256a0f52 100644 --- a/openupgrade_scripts/scripts/hr/14.0.1.1/openupgrade_analysis_work.txt +++ b/openupgrade_scripts/scripts/hr/14.0.1.1/upgrade_analysis_work.txt @@ -3,14 +3,19 @@ hr / hr.employee / address_id (many2one) : now a function hr / hr.employee / certificate (selection) : selection_keys is now '['bachelor', 'doctor', 'graduate', 'master', 'other']' ('['bachelor', 'master', 'other']') hr / hr.employee / coach_id (many2one) : now a function +# NOTHING TO DO + hr / hr.employee / company_id (many2one) : now required, req_default: function # DONE: Post-migration: Filled with Create user company_id + hr / hr.employee / departure_date (date) : NEW hr / hr.employee / job_title (char) : now a function hr / hr.employee / parent_id (many2one) : now a function hr / hr.employee / work_phone (char) : now a function hr / hr.plan.activity.type / summary (char) : now a function hr / res.users / barcode (char) : module is now 'base' ('hr') +# NOTHING TO DO + ---XML records in module 'hr'--- NEW ir.actions.act_window: hr.hr_department_kanban_action NEW ir.actions.act_window: hr.hr_department_tree_action @@ -20,7 +25,10 @@ NEW ir.model.access: hr.access_hr_plan_wizard DEL ir.model.access: hr.access_ir_property_hr_user NEW ir.ui.menu: hr.menu_hr_department_kanban NEW ir.ui.view: hr.qunit_suite +# NOTHING TO DO + DEL mail.template: hr.mail_template_data_unknown_employee_email_address (noupdate) +# DONE: post-migration: deleted xmlid safely (and its translations) + NEW res.partner: hr.res_partner_admin_private_address (noupdate) -hr.employee: hr.employee_admin (noupdate) -# DONE: post-migration: noupdate changed to "res_partner_admin_private_address" +# DONE: post-migration: update this partner with actual admin data From 5a695d5d79ef4258be0f0580e58f5b2aa9e7e63a Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Sat, 11 Dec 2021 19:01:10 +0100 Subject: [PATCH 3/3] [FIX+IMP] hr: Finish migration scripts - Add more comments to the analysis work file - Refine company_id assignation using department's company first - Don't load noupdate records without changes TT29982 --- .../scripts/hr/14.0.1.1/noupdate_changes.xml | 24 +++++++++---------- .../scripts/hr/14.0.1.1/post-migrate.py | 10 ++++---- .../hr/14.0.1.1/upgrade_analysis_work.txt | 20 +++++++++------- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/openupgrade_scripts/scripts/hr/14.0.1.1/noupdate_changes.xml b/openupgrade_scripts/scripts/hr/14.0.1.1/noupdate_changes.xml index 6f68b8ed3bb7..80f0b8e9dd54 100644 --- a/openupgrade_scripts/scripts/hr/14.0.1.1/noupdate_changes.xml +++ b/openupgrade_scripts/scripts/hr/14.0.1.1/noupdate_changes.xml @@ -3,16 +3,16 @@ - - - - - - - - - - - - + + + + diff --git a/openupgrade_scripts/scripts/hr/14.0.1.1/post-migrate.py b/openupgrade_scripts/scripts/hr/14.0.1.1/post-migrate.py index 07893f71061b..d873fa528a2b 100644 --- a/openupgrade_scripts/scripts/hr/14.0.1.1/post-migrate.py +++ b/openupgrade_scripts/scripts/hr/14.0.1.1/post-migrate.py @@ -7,10 +7,12 @@ def fill_hr_employee_company_id(env): openupgrade.logged_query( env.cr, """ - UPDATE hr_employee hr - SET company_id = ru.company_id - FROM res_users ru - WHERE ru.id = hr.create_uid AND hr.company_id is NULL + UPDATE hr_employee he + SET company_id = COALESCE(hd.company_id, ru.company_id) + FROM hr_employee he2 + JOIN res_users ru ON ru.id = COALESCE(he2.create_uid, 1) + LEFT JOIN hr_department hd ON hd.id = he2.department_id + WHERE he.id = he2.id AND he.company_id is NULL """, ) diff --git a/openupgrade_scripts/scripts/hr/14.0.1.1/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/hr/14.0.1.1/upgrade_analysis_work.txt index 6fdf256a0f52..0eaf739ef3e3 100644 --- a/openupgrade_scripts/scripts/hr/14.0.1.1/upgrade_analysis_work.txt +++ b/openupgrade_scripts/scripts/hr/14.0.1.1/upgrade_analysis_work.txt @@ -1,18 +1,22 @@ ---Models in module 'hr'--- ---Fields in module 'hr'--- hr / hr.employee / address_id (many2one) : now a function -hr / hr.employee / certificate (selection) : selection_keys is now '['bachelor', 'doctor', 'graduate', 'master', 'other']' ('['bachelor', 'master', 'other']') hr / hr.employee / coach_id (many2one) : now a function -# NOTHING TO DO +hr / hr.employee / parent_id (many2one) : now a function +hr / hr.employee / job_title (char) : now a function +hr / hr.employee / work_phone (char) : now a function +hr / hr.plan.activity.type / summary (char) : now a function +# NOTHING TO DO: Converted to computed writable fields and the depends are not being changed (nor the dependency chain) + +hr / hr.employee / certificate (selection) : selection_keys is now '['bachelor', 'doctor', 'graduate', 'master', 'other']' ('['bachelor', 'master', 'other']') +# NOTHING TO DO: Only extra values hr / hr.employee / company_id (many2one) : now required, req_default: function -# DONE: Post-migration: Filled with Create user company_id +# DONE: post-migration: Filled with the most proper data those without company_id hr / hr.employee / departure_date (date) : NEW -hr / hr.employee / job_title (char) : now a function -hr / hr.employee / parent_id (many2one) : now a function -hr / hr.employee / work_phone (char) : now a function -hr / hr.plan.activity.type / summary (char) : now a function +# NOTHING TO DO: New info field + hr / res.users / barcode (char) : module is now 'base' ('hr') # NOTHING TO DO @@ -25,7 +29,7 @@ NEW ir.model.access: hr.access_hr_plan_wizard DEL ir.model.access: hr.access_ir_property_hr_user NEW ir.ui.menu: hr.menu_hr_department_kanban NEW ir.ui.view: hr.qunit_suite -# NOTHING TO DO +# NOTHING TO DO: noupdate=0 records DEL mail.template: hr.mail_template_data_unknown_employee_email_address (noupdate) # DONE: post-migration: deleted xmlid safely (and its translations)