Skip to content

Commit f7e9a1e

Browse files
committed
[OU-ADD] l10n_fr_hr_holidays: Migration scripts
1 parent 29bfed4 commit f7e9a1e

3 files changed

Lines changed: 67 additions & 1 deletion

File tree

docsource/modules160-170.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ Module coverage 16.0 -> 17.0
370370
+---------------------------------------------------+----------------------+-------------------------------------------------+
371371
| l10n_fr_fec | |No DB layout changes. |
372372
+---------------------------------------------------+----------------------+-------------------------------------------------+
373-
| |new| l10n_fr_hr_holidays | | |
373+
| |new| l10n_fr_hr_holidays | Done | |
374374
+---------------------------------------------------+----------------------+-------------------------------------------------+
375375
| |new| l10n_fr_hr_work_entry_holidays | | |
376376
+---------------------------------------------------+----------------------+-------------------------------------------------+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2026 Le Filament
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
from openupgradelib import openupgrade
4+
5+
6+
def _assign_default_leave_type(env):
7+
"""
8+
We try to compute most probable leave type for FR companies
9+
in the following order :
10+
1. default leave type from hr_holidays still active
11+
2. leave type with most common default configuration
12+
3. leave type accessible to that company, configured in days
13+
or half days and of type = "leave"
14+
for case 2 or 3, ordering by sequence and taking the first found
15+
"""
16+
fr_company_ids = (
17+
env["res.company"].search([]).filtered(lambda c: c.country_id.code == "FR")
18+
)
19+
default_leave_type = env.ref("hr_holidays.holiday_status_cl", False)
20+
for company in fr_company_ids:
21+
if (
22+
default_leave_type
23+
and default_leave_type.active
24+
and default_leave_type.company_id.id in [False, company.id]
25+
):
26+
leave_type = default_leave_type
27+
else:
28+
leave_type = env["hr.leave.type"].search(
29+
[
30+
("company_id", "in", [False, company.id]),
31+
("requires_allocation", "=", "yes"),
32+
("employee_requests", "=", "no"),
33+
("request_unit", "in", ["day", "half_day"]),
34+
("leave_validation_type", "!=", "no_validation"),
35+
("time_type", "=", "leave"),
36+
],
37+
order="sequence asc",
38+
limit=1,
39+
)
40+
if not leave_type:
41+
leave_type = env["hr.leave.type"].search(
42+
[
43+
("company_id", "in", [False, company.id]),
44+
("request_unit", "in", ["day", "half_day"]),
45+
("time_type", "=", "leave"),
46+
],
47+
order="sequence asc",
48+
limit=1,
49+
)
50+
company.l10n_fr_reference_leave_type = leave_type
51+
52+
53+
@openupgrade.migrate()
54+
def migrate(env, version):
55+
_assign_default_leave_type(env)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---Models in module 'l10n_fr_hr_holidays'---
2+
---Fields in module 'l10n_fr_hr_holidays'---
3+
l10n_fr_hr_holidays / hr.leave / l10n_fr_date_to_changed (boolean): NEW
4+
# NOTHING TO DO: new functionality will be used on new leaves
5+
6+
l10n_fr_hr_holidays / res.company / l10n_fr_reference_leave_type (many2one): NEW relation: hr.leave.type
7+
# DONE: post-migration: initialize this field with most probable holiday type
8+
---XML records in module 'l10n_fr_hr_holidays'---
9+
NEW ir.ui.menu: l10n_fr_hr_holidays.hr_holidays_menu_configuration
10+
NEW ir.ui.view: l10n_fr_hr_holidays.res_config_settings_view_form
11+
# NOTHING TO DO: handled by ORM

0 commit comments

Comments
 (0)