From 3749ab59278bd54119e5471918b38569f1a8e237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20-=20Le=20Filament?= <30716308+remi-filament@users.noreply.github.com> Date: Tue, 24 Dec 2024 13:26:37 +0100 Subject: [PATCH] [17.0][OU-ADD] hr_holidays: Migration to 17.0 --- docsource/modules160-170.rst | 2 +- .../hr_holidays/17.0.1.6/noupdate_changes.xml | 2 + .../hr_holidays/17.0.1.6/post-migration.py | 44 +++++ .../hr_holidays/17.0.1.6/pre-migration.py | 97 +++++++++ .../17.0.1.6/upgrade_analysis_work.txt | 184 ++++++++++++++++++ 5 files changed, 328 insertions(+), 1 deletion(-) create mode 100644 openupgrade_scripts/scripts/hr_holidays/17.0.1.6/post-migration.py create mode 100644 openupgrade_scripts/scripts/hr_holidays/17.0.1.6/pre-migration.py create mode 100644 openupgrade_scripts/scripts/hr_holidays/17.0.1.6/upgrade_analysis_work.txt diff --git a/docsource/modules160-170.rst b/docsource/modules160-170.rst index e2cb80aab102..ceda84a1ca3b 100644 --- a/docsource/modules160-170.rst +++ b/docsource/modules160-170.rst @@ -168,7 +168,7 @@ Module coverage 16.0 -> 17.0 +---------------------------------------------------+----------------------+-------------------------------------------------+ | hr_gamification | |No DB layout changes. | +---------------------------------------------------+----------------------+-------------------------------------------------+ -| hr_holidays | | | +| hr_holidays | Done | | +---------------------------------------------------+----------------------+-------------------------------------------------+ | hr_holidays_attendance | | | +---------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/hr_holidays/17.0.1.6/noupdate_changes.xml b/openupgrade_scripts/scripts/hr_holidays/17.0.1.6/noupdate_changes.xml index 03a69a97aea9..d5bac96a969a 100644 --- a/openupgrade_scripts/scripts/hr_holidays/17.0.1.6/noupdate_changes.xml +++ b/openupgrade_scripts/scripts/hr_holidays/17.0.1.6/noupdate_changes.xml @@ -1,5 +1,6 @@ + Time Off: multi company global rule diff --git a/openupgrade_scripts/scripts/hr_holidays/17.0.1.6/post-migration.py b/openupgrade_scripts/scripts/hr_holidays/17.0.1.6/post-migration.py new file mode 100644 index 000000000000..fc145ff65df3 --- /dev/null +++ b/openupgrade_scripts/scripts/hr_holidays/17.0.1.6/post-migration.py @@ -0,0 +1,44 @@ +# Copyright 2024- Le Filament (https://le-filament.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from openupgradelib import openupgrade + + +def _leave_type_responsible_convert_field_m2o_to_m2m(env): + # Convert m2o to m2m in 'onboarding.onboarding.step' + openupgrade.m2o_to_x2m( + env.cr, + env["hr.leave.type"], + "hr_leave_type", + "responsible_ids", + "responsible_id", + ) + + +def _compute_already_accrued(env): + openupgrade.logged_query( + env.cr, + """ + UPDATE hr_leave_allocation + SET already_accrued = True + WHERE allocation_type = 'accrual' + AND state = 'validate' + AND accrual_plan_id IS NOT NULL + AND employee_id IS NOT NULL + AND number_of_days > 0; + """, + ) + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.load_data(env, "hr_holidays", "17.0.1.6/noupdate_changes.xml") + _leave_type_responsible_convert_field_m2o_to_m2m(env) + _compute_already_accrued(env) + openupgrade.delete_records_safely_by_xml_id( + env, + [ + "hr_holidays.mail_act_leave_allocation_second_approval", + "hr_holidays.hr_leave_stress_day_rule_multi_company", + ], + ) diff --git a/openupgrade_scripts/scripts/hr_holidays/17.0.1.6/pre-migration.py b/openupgrade_scripts/scripts/hr_holidays/17.0.1.6/pre-migration.py new file mode 100644 index 000000000000..e11bad43d986 --- /dev/null +++ b/openupgrade_scripts/scripts/hr_holidays/17.0.1.6/pre-migration.py @@ -0,0 +1,97 @@ +# Copyright 2024- Le Filament (https://le-filament.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from openupgradelib import openupgrade + +_model_renames = [ + ("hr.leave.stress.day", "hr.leave.mandatory.day"), +] + +_table_renames = [ + ("hr_leave_stress_day", "hr_leave_mandatory_day"), +] + + +def _map_leave_accrual_level_action(cr): + openupgrade.logged_query( + cr, + """ + UPDATE hr_leave_accrual_level + SET action_with_unused_accruals = 'all' + WHERE action_with_unused_accruals = 'postponed'; + """, + ) + + +def _map_leave_accrual_level_added_value_type(cr): + openupgrade.logged_query( + cr, + """ + UPDATE hr_leave_accrual_level + SET added_value_type = 'day' + WHERE added_value_type = 'days'; + """, + ) + openupgrade.logged_query( + cr, + """ + UPDATE hr_leave_accrual_level + SET added_value_type = 'hour' + WHERE added_value_type = 'hours'; + """, + ) + + +def _map_leave_allocation_state(cr): + openupgrade.logged_query( + cr, + """ + UPDATE hr_leave_allocation + SET state = 'confirm' + WHERE state = 'draft'; + """, + ) + openupgrade.logged_query( + cr, + """ + UPDATE hr_leave_allocation + SET state = 'refuse' + WHERE state = 'cancel'; + """, + ) + + +def _set_is_based_on_worked_time(cr): + openupgrade.logged_query( + cr, + """ + ALTER TABLE hr_leave_accrual_plan + ADD COLUMN IF NOT EXISTS is_based_on_worked_time BOOLEAN; + """, + ) + openupgrade.logged_query( + cr, + """ + UPDATE hr_leave_accrual_plan plan + SET is_based_on_worked_time = level.is_based_on_worked_time + FROM hr_leave_accrual_level level + WHERE level.accrual_plan_id = plan.id; + """, + ) + + +def _delete_sql_constraints(env): + # Delete constraints to recreate it + openupgrade.delete_sql_constraint_safely( + env, "hr_holidays", "hr_leave_accrual_level", "check_dates" + ) + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.rename_models(env.cr, _model_renames) + openupgrade.rename_tables(env.cr, _table_renames) + _map_leave_accrual_level_action(env.cr) + _map_leave_accrual_level_added_value_type(env.cr) + _map_leave_allocation_state(env.cr) + _set_is_based_on_worked_time(env.cr) + _delete_sql_constraints(env) diff --git a/openupgrade_scripts/scripts/hr_holidays/17.0.1.6/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/hr_holidays/17.0.1.6/upgrade_analysis_work.txt new file mode 100644 index 000000000000..99fbbac97c90 --- /dev/null +++ b/openupgrade_scripts/scripts/hr_holidays/17.0.1.6/upgrade_analysis_work.txt @@ -0,0 +1,184 @@ +---Models in module 'hr_holidays'--- +obsolete model hr.leave.stress.day +new model hr.leave.mandatory.day +# DONE pre-migration: rename model + +---Fields in module 'hr_holidays'--- +hr_holidays / hr.leave / activity_user_id (many2one) : not related anymore +hr_holidays / hr.leave / activity_user_id (many2one) : now a function +# NOTHING TO DO: not stored field + +hr_holidays / hr.leave / category_id (many2one) : not a function anymore +# NOTHING TO DO: states and validate removed only + +hr_holidays / hr.leave / company_id (many2one) : NEW relation: res.company, isfunction: function, stored +hr_holidays / hr.leave / date_from (datetime) : now a function +hr_holidays / hr.leave / date_to (datetime) : now a function +hr_holidays / hr.leave / employee_ids (many2many) : now a function +# NOTHING TO DO: computed fields + +hr_holidays / hr.leave / holiday_allocation_id (many2one): DEL relation: hr.leave.allocation +# NOTHING TO DO: removed field + +hr_holidays / hr.leave / message_has_sms_error (boolean): previously in module sms +# NOTHING TO DO: Handled by Odoo registry + +hr_holidays / hr.leave / mode_company_id (many2one) : not a function anymore +# NOTHING TO DO: states removed only + +hr_holidays / hr.leave / number_of_days (float) : now a function +hr_holidays / hr.leave / number_of_hours (float) : NEW isfunction: function, stored +# NOTHING TO DO: computed fields + +hr_holidays / hr.leave / rating_ids (one2many) : NEW relation: rating.rating +hr_holidays / hr.leave / resource_calendar_id (many2one): NEW relation: resource.calendar, hasdefault: compute +# NOTHING TO DO: new field + +hr_holidays / hr.leave / website_message_ids (one2many): previously in module portal +# NOTHING TO DO: Handled by Odoo registry + +hr_holidays / hr.leave.accrual.level / action_with_unused_accruals (selection): selection_keys is now '['all', 'lost', 'maximum']' ('['lost', 'postponed']') +# DONE: pre-migration reallocate postponed --> all + +hr_holidays / hr.leave.accrual.level / added_value_type (selection) : selection_keys is now '['day', 'hour']' ('['days', 'hours']') +# DONE: pre-migration reallocate values + +hr_holidays / hr.leave.accrual.level / cap_accrued_time (boolean) : NEW hasdefault: default +# NOTHING TO DO: new functionality + +hr_holidays / hr.leave.accrual.level / frequency (selection) : selection_keys is now '['bimonthly', 'biyearly', 'daily', 'hourly', 'monthly', 'weekly', 'yearly']' ('['bimonthly', 'biyearly', 'daily', 'monthly', 'weekly', 'yearly']') +# NOTHING TO DO: new key 'hourly' + +hr_holidays / hr.leave.accrual.level / is_based_on_worked_time (boolean): DEL +hr_holidays / hr.leave.accrual.plan / is_based_on_worked_time (boolean): NEW hasdefault: compute +# DONE: pre-migration propagate value from hr.leave.accrual.level to hr.leave.accrual.plan + +hr_holidays / hr.leave.accrual.level / parent_id (many2one) : DEL relation: hr.leave.accrual.level +# NOTHING TO DO: removed field without replacement + +hr_holidays / hr.leave.accrual.plan / accrued_gain_time (selection) : NEW required, selection_keys: ['end', 'start'], hasdefault: default +# NOTHING TO DO: new field with default value = v16 behaviour + +hr_holidays / hr.leave.accrual.plan / active (boolean) : NEW hasdefault: default +# NOTHING TO DO: new field, default = active + +hr_holidays / hr.leave.accrual.plan / added_value_type (selection) : NEW selection_keys: ['day', 'hour'], isfunction: function, stored +# NOTHING TO DO: new fields computed based on value in hr.leave.accrual.level + +hr_holidays / hr.leave.accrual.plan / carryover_date (selection) : NEW required, selection_keys: ['allocation', 'other', 'year_start'], hasdefault: default +hr_holidays / hr.leave.accrual.plan / carryover_day (integer) : NEW hasdefault: default +hr_holidays / hr.leave.accrual.plan / carryover_month (selection) : NEW selection_keys: ['apr', 'aug', 'dec', 'feb', 'jan', 'jul', 'jun', 'mar', 'may', 'nov', 'oct', 'sep'], hasdefault: default +# NOTHING TO DO: new fields with default value = v16 behaviour + +hr_holidays / hr.leave.accrual.plan / company_id (many2one) : NEW relation: res.company, hasdefault: compute +# NOTHING TO DO: computed fields + +hr_holidays / hr.leave.allocation / activity_user_id (many2one) : not related anymore +hr_holidays / hr.leave.allocation / activity_user_id (many2one) : now a function +# NOTHING TO DO: not stored field + +hr_holidays / hr.leave.allocation / already_accrued (boolean) : NEW +# DONE post-migration: compute field + +hr_holidays / hr.leave.allocation / department_id (many2one) : not a function anymore +# NOTHING TO DO: states removed only + +hr_holidays / hr.leave.allocation / message_has_sms_error (boolean): previously in module sms +# NOTHING TO DO: Handled by Odoo registry + +hr_holidays / hr.leave.allocation / message_main_attachment_id (many2one): DEL relation: ir.attachment +# NOTHING TO DO : mostly unused + +hr_holidays / hr.leave.allocation / rating_ids (one2many) : NEW relation: rating.rating +# NOTHING TO DO: new field + +hr_holidays / hr.leave.allocation / state (selection) : selection_keys is now '['confirm', 'refuse', 'validate']' ('['cancel', 'confirm', 'draft', 'refuse', 'validate']') +# DONE: pre-migration: reallocate previous state 'draft' to 'confirm' and 'cancel' to 'refuse' + +hr_holidays / hr.leave.allocation / taken_leave_ids (one2many) : DEL relation: hr.leave +# NOTHING TO DO: removed link + +hr_holidays / hr.leave.allocation / type_request_unit (selection) : not related anymore +hr_holidays / hr.leave.allocation / type_request_unit (selection) : now a function +hr_holidays / hr.leave.allocation / type_request_unit (selection) : selection_keys is now '['day', 'half_day', 'hour']' ('function') +# NOTHING TO DO: was related to holiday_status_id is now computed + +hr_holidays / hr.leave.allocation / website_message_ids (one2many): previously in module portal +# NOTHING TO DO: Handled by Odoo registry + +hr_holidays / hr.leave.mandatory.day / color (integer) : NEW hasdefault: default +hr_holidays / hr.leave.mandatory.day / company_id (many2one) : NEW relation: res.company, required, hasdefault: default +hr_holidays / hr.leave.mandatory.day / department_ids (many2many) : NEW relation: hr.department +hr_holidays / hr.leave.mandatory.day / end_date (date) : NEW required +hr_holidays / hr.leave.mandatory.day / name (char) : NEW required +hr_holidays / hr.leave.mandatory.day / resource_calendar_id (many2one): NEW relation: resource.calendar +hr_holidays / hr.leave.mandatory.day / start_date (date) : NEW required +hr_holidays / hr.leave.stress.day / color (integer) : DEL +hr_holidays / hr.leave.stress.day / company_id (many2one) : DEL relation: res.company, required +hr_holidays / hr.leave.stress.day / department_ids (many2many) : DEL relation: hr.department +hr_holidays / hr.leave.stress.day / end_date (date) : DEL required +hr_holidays / hr.leave.stress.day / name (char) : DEL required +hr_holidays / hr.leave.stress.day / resource_calendar_id (many2one): DEL relation: resource.calendar +hr_holidays / hr.leave.stress.day / start_date (date) : DEL required +# DONE: pre-migration rename model (no field changes) + +hr_holidays / hr.leave.type / allows_negative (boolean) : NEW +hr_holidays / hr.leave.type / max_allowed_negative (integer): NEW +# NOTHING TO DO: new feature + +hr_holidays / hr.leave.type / color_name (selection) : DEL required, selection_keys: ['black', 'blue', 'brown', 'ivory', 'lavender', 'lightblue', 'lightcoral', 'lightcyan', 'lightgreen', 'lightpink', 'lightsalmon', 'lightyellow', 'magenta', 'red', 'violet', 'wheat'] +# NOTHING TO DO: removed field + +hr_holidays / hr.leave.type / responsible_id (many2one) : DEL relation: res.users +hr_holidays / hr.leave.type / responsible_ids (many2many) : NEW relation: res.users +# DONE: post-migration: convert m2o to m2m + +---XML records in module 'hr_holidays'--- +NEW ir.actions.act_window: hr_holidays.act_hr_employee_holiday_type +ir.actions.act_window: hr_holidays.hr_leave_action_holiday_allocation_id (deleted domain) +NEW ir.actions.act_window: hr_holidays.hr_leave_mandatory_day_action +DEL ir.actions.act_window: hr_holidays.hr_leave_stress_day_action +NEW ir.actions.act_window.view: hr_holidays.action_window_leave_list +DEL ir.actions.report: hr_holidays.action_report_holidayssummary2 +DEL ir.actions.server: hr_holidays.act_hr_employee_holiday_request +NEW ir.cron: hr_holidays.hr_leave_cron_cancel_invalid +NEW ir.model.access: hr_holidays.access_hr_leave_mandatory_day_manager +NEW ir.model.access: hr_holidays.access_hr_leave_mandatory_day_user +DEL ir.model.access: hr_holidays.access_hr_leave_stress_day_manager +DEL ir.model.access: hr_holidays.access_hr_leave_stress_day_user +# NOTHING TO DO: handled by ORM + +ir.model.constraint: hr_holidays.constraint_hr_leave_accrual_level_check_dates (changed definition: is now 'check((frequency in('daily','hourly')) or(week_day is not null and frequency = 'weekly') or(first_day > 0 and second_day > first_day and first_day <= 31 and second_day <= 31 and frequency = 'bimonthly') or(first_day > 0 and first_day <= 31 and frequency = 'monthly')or(first_month_day > 0 and first_month_day <= 31 and second_month_day > 0 and second_month_day <= 31 and frequency = 'biyearly') or(yearly_day > 0 and yearly_day <= 31 and frequency = 'yearly'))' ('check((frequency = 'daily') or(week_day is not null and frequency = 'weekly') or(first_day > 0 and second_day > first_day and first_day <= 31 and second_day <= 31 and frequency = 'bimonthly') or(first_day > 0 and first_day <= 31 and frequency = 'monthly')or(first_month_day > 0 and first_month_day <= 31 and second_month_day > 0 and second_month_day <= 31 and frequency = 'biyearly') or(yearly_day > 0 and yearly_day <= 31 and frequency = 'yearly'))')) +# DONE: pre-migration: safely remove constraint so that it can be recreated by ORM + +NEW ir.model.constraint: hr_holidays.constraint_hr_leave_date_check3 +NEW ir.model.constraint: hr_holidays.constraint_hr_leave_mandatory_day_date_from_after_day_to +NEW ir.model.constraint: hr_holidays.constraint_hr_leave_type_check_negative +DEL ir.model.constraint: hr_holidays.constraint_hr_leave_stress_day_date_from_after_day_to +NEW ir.rule: hr_holidays.hr_leave_accrual_plan_rule_multi_company (noupdate) +NEW ir.rule: hr_holidays.hr_leave_mandatory_day_rule_multi_company (noupdate) +# NOTHING TO DO: handled by ORM + +DEL ir.rule: hr_holidays.hr_leave_stress_day_rule_multi_company (noupdate) +# DONE: post-migration: safe removal of ir.rule + +NEW ir.ui.menu: hr_holidays.hr_holidays_mandatory_day_menu_configuration +NEW ir.ui.menu: hr_holidays.menu_hr_holidays_management +DEL ir.ui.menu: hr_holidays.hr_holidays_stress_day_menu_configuration +DEL ir.ui.menu: hr_holidays.menu_hr_holidays_approvals +NEW ir.ui.view: hr_holidays.hr_accrual_plan_view_search +NEW ir.ui.view: hr_holidays.hr_leave_mandatory_day_view_form +NEW ir.ui.view: hr_holidays.hr_leave_mandatory_day_view_list +NEW ir.ui.view: hr_holidays.hr_leave_mandatory_day_view_search +NEW ir.ui.view: hr_holidays.hr_leave_report_graph +NEW ir.ui.view: hr_holidays.hr_leave_report_search_view +NEW ir.ui.view: hr_holidays.hr_leave_view_kanban_my +NEW ir.ui.view: hr_holidays.view_holiday_list +DEL ir.ui.view: hr_holidays.hr_leave_report_view_form +DEL ir.ui.view: hr_holidays.hr_leave_stress_day_view_form +DEL ir.ui.view: hr_holidays.hr_leave_stress_day_view_list +DEL ir.ui.view: hr_holidays.hr_leave_stress_day_view_search +# NOTHING TO DO: handled by ORM + +DEL mail.activity.type: hr_holidays.mail_act_leave_allocation_second_approval (noupdate) +# DONE: post-migration: safe removal for activity.type