From 1b32e717dc2cdfc6eca5f93288d61e6fec3be884 Mon Sep 17 00:00:00 2001 From: nguyenvietlam0640 Date: Wed, 28 Jun 2023 17:01:46 +0700 Subject: [PATCH 1/3] [MIG] hr_fleet: migrate 15 to 16 --- docsource/modules150-160.rst | 2 +- .../hr_fleet/16.0.1.0/upgrade_analysis_work.txt | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 openupgrade_scripts/scripts/hr_fleet/16.0.1.0/upgrade_analysis_work.txt diff --git a/docsource/modules150-160.rst b/docsource/modules150-160.rst index 20d035409bb0..823633dfe62e 100644 --- a/docsource/modules150-160.rst +++ b/docsource/modules150-160.rst @@ -172,7 +172,7 @@ Module coverage 15.0 -> 16.0 +-------------------------------------------------+----------------------+-------------------------------------------------+ | hr_expense | | | +-------------------------------------------------+----------------------+-------------------------------------------------+ -| hr_fleet | | | +| hr_fleet | Nothing to do | | +-------------------------------------------------+----------------------+-------------------------------------------------+ | hr_gamification | |No DB layout changes. | +-------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/hr_fleet/16.0.1.0/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/hr_fleet/16.0.1.0/upgrade_analysis_work.txt new file mode 100644 index 000000000000..7565e7c5ce43 --- /dev/null +++ b/openupgrade_scripts/scripts/hr_fleet/16.0.1.0/upgrade_analysis_work.txt @@ -0,0 +1,13 @@ +---Models in module 'hr_fleet'--- +---Fields in module 'hr_fleet'--- +hr_fleet / fleet.vehicle.assignation.log / driver_employee_id (many2one) : is now stored +hr_fleet / fleet.vehicle.assignation.log / driver_employee_id (many2one) : not related anymore + +# NOTHING TO DO: field changed from related field to compute field + +---XML records in module 'hr_fleet'--- +NEW ir.ui.view: hr_fleet.fleet_vehicle_assignation_log_employee_view_list +NEW ir.ui.view: hr_fleet.fleet_vehicle_view_tree_inherit_hr +NEW ir.ui.view: hr_fleet.view_attachment_kanban_inherit_hr + +# NOTHING TO DO \ No newline at end of file From bf17251b08bb7c5c420b8e310f35f1ba534673ec Mon Sep 17 00:00:00 2001 From: nguyenvietlam0640 Date: Thu, 29 Jun 2023 15:28:31 +0700 Subject: [PATCH 2/3] [FIX] hr_fleet: add pre-migration to create value for compute field with store=true by sql instead of auto orm --- docsource/modules150-160.rst | 2 +- .../hr_fleet/16.0.1.0/pre-migration.py | 26 +++++++++++++++++++ .../16.0.1.0/upgrade_analysis_work.txt | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 openupgrade_scripts/scripts/hr_fleet/16.0.1.0/pre-migration.py diff --git a/docsource/modules150-160.rst b/docsource/modules150-160.rst index 823633dfe62e..110afa66d924 100644 --- a/docsource/modules150-160.rst +++ b/docsource/modules150-160.rst @@ -172,7 +172,7 @@ Module coverage 15.0 -> 16.0 +-------------------------------------------------+----------------------+-------------------------------------------------+ | hr_expense | | | +-------------------------------------------------+----------------------+-------------------------------------------------+ -| hr_fleet | Nothing to do | | +| hr_fleet | Done | | +-------------------------------------------------+----------------------+-------------------------------------------------+ | hr_gamification | |No DB layout changes. | +-------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/hr_fleet/16.0.1.0/pre-migration.py b/openupgrade_scripts/scripts/hr_fleet/16.0.1.0/pre-migration.py new file mode 100644 index 000000000000..365645b4a32d --- /dev/null +++ b/openupgrade_scripts/scripts/hr_fleet/16.0.1.0/pre-migration.py @@ -0,0 +1,26 @@ +from openupgradelib import openupgrade + + +def create_drive_employee(env): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE fleet_vehicle_assignation_log + ADD IF NOT EXISTS driver_employee_id INT + """, + ) + + openupgrade.logged_query( + env.cr, + """ + UPDATE fleet_vehicle_assignation_log AS fval + SET driver_employee_id = fv.driver_employee_id + FROM fleet_vehicle AS fv + WHERE fval.vehicle_id = fv.id + """, + ) + + +@openupgrade.migrate() +def migrate(env, version): + create_drive_employee(env) diff --git a/openupgrade_scripts/scripts/hr_fleet/16.0.1.0/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/hr_fleet/16.0.1.0/upgrade_analysis_work.txt index 7565e7c5ce43..e8dabfd7731f 100644 --- a/openupgrade_scripts/scripts/hr_fleet/16.0.1.0/upgrade_analysis_work.txt +++ b/openupgrade_scripts/scripts/hr_fleet/16.0.1.0/upgrade_analysis_work.txt @@ -3,7 +3,7 @@ hr_fleet / fleet.vehicle.assignation.log / driver_employee_id (many2one) : is now stored hr_fleet / fleet.vehicle.assignation.log / driver_employee_id (many2one) : not related anymore -# NOTHING TO DO: field changed from related field to compute field +# DONE: fill data from old related field for now store current compute field in pre-migration ---XML records in module 'hr_fleet'--- NEW ir.ui.view: hr_fleet.fleet_vehicle_assignation_log_employee_view_list From a1151face91c3ab6becc482730571f086f9c5d7b Mon Sep 17 00:00:00 2001 From: Roy Le <43790414+royleviindoo@users.noreply.github.com> Date: Fri, 21 Jul 2023 17:45:29 +0700 Subject: [PATCH 3/3] Update openupgrade_scripts/scripts/hr_fleet/16.0.1.0/pre-migration.py --- .../scripts/hr_fleet/16.0.1.0/pre-migration.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openupgrade_scripts/scripts/hr_fleet/16.0.1.0/pre-migration.py b/openupgrade_scripts/scripts/hr_fleet/16.0.1.0/pre-migration.py index 365645b4a32d..9fd5ae7b5340 100644 --- a/openupgrade_scripts/scripts/hr_fleet/16.0.1.0/pre-migration.py +++ b/openupgrade_scripts/scripts/hr_fleet/16.0.1.0/pre-migration.py @@ -13,10 +13,10 @@ def create_drive_employee(env): openupgrade.logged_query( env.cr, """ - UPDATE fleet_vehicle_assignation_log AS fval - SET driver_employee_id = fv.driver_employee_id - FROM fleet_vehicle AS fv - WHERE fval.vehicle_id = fv.id + UPDATE fleet_vehicle_assignation_log log + SET driver_employee_id = emp.id + FROM hr_employee emp + WHERE log.driver_id IS NOT NULL and log.driver_id = emp.address_home_id """, )