Skip to content
Merged
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
1 change: 1 addition & 0 deletions openupgrade_scripts/apriori.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
# only used here for upgrade_analysis
renamed_models = {
# odoo
"hr.leave.stress.day": "hr.leave.mandatory.day",
"mail.channel": "discuss.channel",
"mail.channel.member": "discuss.channel.member",
"mail.channel.rtc.session": "discuss.channel.rtc.session",
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>
-->
<record id="hr_leave_allocation_rule_multicompany" model="ir.rule">
<field name="domain_force">[
'|',
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",
],
)
154 changes: 154 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,154 @@
# 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 _pre_create_accrual_plan_active(cr):
"""
Precreate column with default value true, then remove default from SQL
"""
openupgrade.logged_query(
cr,
"""
ALTER TABLE hr_leave_accrual_plan ADD COLUMN active boolean DEFAULT true
""",
)
openupgrade.logged_query(
cr,
"""
ALTER TABLE hr_leave_accrual_plan ALTER COLUMN active DROP DEFAULT
""",
)


def _hr_leave_company_id(cr):
"""Create and set company_id value in the same order than new compute
(employee_company_id, mode_company_id, department_id.company_id)
"""
openupgrade.logged_query(
cr,
"""
ALTER TABLE hr_leave
ADD COLUMN IF NOT EXISTS company_id INTEGER;
""",
)
openupgrade.logged_query(
cr,
"""UPDATE hr_leave AS leave
SET company_id = CASE
WHEN employee_company_id IS NOT NULL THEN employee_company_id
WHEN mode_company_id IS NOT NULL THEN mode_company_id
ELSE NULL
END
WHERE leave.company_id IS NULL""",
)
openupgrade.logged_query(
cr,
"""UPDATE hr_leave AS leave
SET company_id = d.company_id
FROM hr_department AS d
WHERE leave.company_id IS NULL AND leave.department_id = d.id""",
)


def _map_leave_accrual_level_action(cr):
openupgrade.logged_query(
cr,
"""
UPDATE hr_leave_accrual_level
SET action_with_unused_accruals = CASE
WHEN maximum_leave > 0 AND postpone_max_days > 0 THEN 'maximum'
ELSE 'all'
END
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 = subquery.max_value::BOOLEAN
FROM (
SELECT accrual_plan_id, MAX(is_based_on_worked_time::INT) AS max_value
FROM hr_leave_accrual_level
GROUP BY accrual_plan_id
) subquery
WHERE subquery.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)
_pre_create_accrual_plan_active(env.cr)
_hr_leave_company_id(env.cr)
_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)
Loading
Loading