Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][OU-ADD] hr_holidays: Migration to 17.0 #4702

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docsource/modules160-170.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Module coverage 16.0 -> 17.0
+---------------------------------------------------+----------------------+-------------------------------------------------+
| hr_gamification | |No DB layout changes. |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| hr_holidays | | |
| hr_holidays | Done | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| hr_holidays_attendance | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version='1.0' encoding='utf-8'?>
<odoo>
<!-- Already covered by transforming m2o responsible_id in m2m responsible_ids
<record id="holiday_status_cl" model="hr.leave.type">
<field name="responsible_ids" eval="[(4, ref('base.user_admin'))]"/>
</record>
Expand All @@ -12,6 +13,7 @@
<record id="holiday_status_unpaid" model="hr.leave.type">
<field name="responsible_ids" eval="[(4, ref('base.user_admin'))]"/>
</record>
-->

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, I think it is better to keep these so that we see what we should not update.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it is, and it actually what is usually done on other scripts as well, see for instannce :

<!-- Don't recreate this, as they are usually touched by users and in fact the changes are only to use Command syntax
<record id="account_payment_term_15days" model="account.payment.term">
<field name="line_ids" eval="[Command.clear(), Command.create({'value': 'balance', 'value_amount': 0.0, 'days': 15})]"/>
</record>
<record id="account_payment_term_21days" model="account.payment.term">
<field name="line_ids" eval="[Command.clear(), Command.create({'value': 'balance', 'value_amount': 0.0, 'days': 21})]"/>
</record>
<record id="account_payment_term_2months" model="account.payment.term">
<field name="line_ids" eval="[Command.clear(), Command.create({'value': 'balance', 'value_amount': 0.0, 'months': 2})]"/>
</record>
<record id="account_payment_term_30days" model="account.payment.term">
<field name="line_ids" eval="[Command.clear(), Command.create({'value': 'balance', 'value_amount': 0.0, 'days': 30})]"/>
</record>
<record id="account_payment_term_45days" model="account.payment.term">
<field name="line_ids" eval="[Command.clear(), Command.create({'value': 'balance', 'value_amount': 0.0, 'days': 45})]"/>
</record>
<record id="account_payment_term_advance_60days" model="account.payment.term">
<field name="line_ids" eval="[ Command.clear(), Command.create({'value': 'percent', 'value_amount': 30.0, 'days': 0}), Command.create({'value': 'balance', 'value_amount': 0.0, 'days': 60})]"/>
</record>
<record id="account_payment_term_immediate" model="account.payment.term">
<field name="line_ids" eval="[Command.clear(), Command.create({'value': 'balance', 'value_amount': 0.0})]"/>
</record> -->

The use case where it is useful is for when we run analysis again, (like it was done with #4697) by keeping the comments, we know that these data were commented out willingly, and it was not new data which was added after last analysis or data which was forgotten.

<record id="hr_leave_allocation_rule_multicompany" model="ir.rule">
<field name="name">Time Off: multi company global rule</field>
</record>
Expand Down
44 changes: 44 additions & 0 deletions openupgrade_scripts/scripts/hr_holidays/17.0.1.6/post-migration.py
Original file line number Diff line number Diff line change
@@ -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",
],
)
97 changes: 97 additions & 0 deletions openupgrade_scripts/scripts/hr_holidays/17.0.1.6/pre-migration.py
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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
Loading