Skip to content

Conversation

@MiquelRForgeFlow
Copy link
Contributor

Supersedes #5023.

@MiquelRForgeFlow
Copy link
Contributor Author

/ocabot migration hr_holidays

@peregrine-2024

This comment was marked as spam.

@peregrine-2024

This comment was marked as spam.

@legalsylvain
Copy link
Contributor

Previous comments looks very much like text generated by artificial stupidity...

# DONE: pre-migration: officer -> hr, no -> no_validation

hr_holidays / hr.leave.type / include_public_holidays_in_duration (boolean): NEW hasdefault: default
# NOTHING TO DO: new feature
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to consider whether we should do something due to https://github.com/OCA/hr-holidays/tree/18.0/hr_holidays_public/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact, "considering hr_holidays_public" is outside this PR. So, if somebody want to analyze compatibilities, feel free.

@MiquelRForgeFlow MiquelRForgeFlow force-pushed the 18.0-mig-hr_holidays branch 6 times, most recently from acb94fb to a566ec0 Compare August 1, 2025 19:57
@MiquelRForgeFlow MiquelRForgeFlow merged commit 30d7661 into OCA:18.0 Aug 4, 2025
3 of 4 checks passed
@MiquelRForgeFlow MiquelRForgeFlow deleted the 18.0-mig-hr_holidays branch August 4, 2025 12:40
Comment on lines +88 to +181
def split_employee_leaves(env):
for table in ["hr_leave", "hr_leave_allocation"]:
env.cr.execute(
f"""
SELECT column_name
FROM information_schema.columns
WHERE table_name = '{table}'
"""
)
columns = ", ".join(
[x[0] for x in env.cr.fetchall() if x[0] not in ("id", "employee_id")]
)
leave_employees = []
# case multi_employee
env.cr.execute(
f"""
SELECT leave.id, 'employee', array_agg(rel.hr_employee_id) as employee_ids
FROM {table} AS leave
JOIN hr_employee_{table}_rel rel ON rel.{table}_id = leave.id
WHERE leave.holiday_type = 'employee' AND leave.multi_employee
GROUP BY leave.id
"""
)
leave_employees.extend(env.cr.fetchall())
# case company
env.cr.execute(
f"""
SELECT leave.id, 'company', array_agg(he.id) as employee_ids
FROM {table} AS leave
JOIN hr_employee he ON he.company_id = leave.mode_company_id
WHERE leave.holiday_type = 'company'
GROUP BY leave.id
"""
)
leave_employees.extend(env.cr.fetchall())
# case category
env.cr.execute(
f"""
SELECT leave.id, 'category', array_agg(rel.employee_id) as employee_ids
FROM {table} AS leave
JOIN employee_category_rel rel ON rel.category_id = leave.category_id
WHERE leave.holiday_type = 'category'
GROUP BY leave.id
"""
)
leave_employees.extend(env.cr.fetchall())
# case department
env.cr.execute(
f"""
SELECT leave.id, 'department', array_agg(he.id) as employee_ids
FROM {table} AS leave
JOIN hr_employee he ON he.department_id = leave.department_id
WHERE leave.holiday_type = 'department'
GROUP BY leave.id
"""
)
leave_employees.extend(env.cr.fetchall())
for table_id, holiday_type, employee_ids in leave_employees:
employees = env["hr.employee"].browse(employee_ids)
if employee_ids:
openupgrade.logged_query(
env.cr,
f"""
UPDATE {table}
SET employee_id = {employees[0].id}
WHERE id = {table_id}
""",
)
if holiday_type != "employee":
openupgrade.logged_query(
env.cr,
f"""
UPDATE {table}
SET holiday_type = 'employee'
WHERE id = {table_id}
""",
)
for employee in employees[1:]:
openupgrade.logged_query(
env.cr,
f"""
INSERT INTO {table} (employee_id, {columns})
SELECT {employee.id}, {columns}
FROM {table}
WHERE id = {table_id}
""",
)
else:
openupgrade.logged_query(
env.cr,
f"""
DELETE FROM {table} WHERE id = {table_id}
""",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @MiquelRForgeFlow are you sure about that one ?
On my database, everytime I had a leave or allocation concerning multiple employees, individuals leave or allocations were also created for each one of these.
Now running migration on my database, I end up with duplicate leave and allocations (even worse when I had allocation for company, it created allocations for employees which are not anymore under contract for years).

Maybe we should do that only for leave / allocation which are in draft state only ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants