Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] hr_holidays: finish migration
Browse files Browse the repository at this point in the history
MiquelRForgeFlow committed Aug 25, 2022
1 parent 1f0465f commit 2227ab3
Showing 3 changed files with 26 additions and 53 deletions.
41 changes: 0 additions & 41 deletions openupgrade_scripts/scripts/hr_holidays/15.0.1.5/post-migration.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,6 @@
import logging

from openupgradelib import openupgrade

from odoo import api
from odoo.exceptions import ValidationError

from odoo.addons.hr_holidays.models.hr_leave import HolidaysRequest

_logger = logging.getLogger(__name__)


@api.constrains("holiday_allocation_id")
def _check_allocation_id(self):
"""Don't raise ValidationError in _check_allocation_id method."""
try:
return HolidaysRequest._check_allocation_id._original_method(self)
except ValidationError:
_logger.warning(
"Could not find an allocation of type %s for the time off with ID %s."
"\nRequires allocation of this type is now set to 'No Limit'."
"\nPlease review requires allocation of this type manually "
"after the migration."
% (self.holiday_status_id.mapped("display_name"), self.ids)
)
self.holiday_status_id.write({"requires_allocation": "no"})


_check_allocation_id._original_method = HolidaysRequest._check_allocation_id
HolidaysRequest._check_allocation_id = _check_allocation_id


def _fill_hr_leave_holiday_allocation_id(env):
leaves = env["hr.leave"].search(
[
("holiday_status_id.requires_allocation", "=", "yes"),
("date_from", "!=", False),
("date_to", "!=", False),
]
)
leaves._compute_from_holiday_status_id()


@openupgrade.migrate()
def migrate(env, version):
_fill_hr_leave_holiday_allocation_id(env)
openupgrade.load_data(env.cr, "hr_holidays", "15.0.1.5/noupdate_changes.xml")
30 changes: 19 additions & 11 deletions openupgrade_scripts/scripts/hr_holidays/15.0.1.5/pre-migration.py
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ def _fast_fill_hr_leave_employee_company_id(env):
UPDATE hr_leave hl
SET employee_company_id = empl.company_id
FROM hr_employee empl
WHERE hl.employee_id IS NOT NULL AND hl.employee_id = empl.id""",
WHERE empl.company_id IS NOT NULL AND hl.employee_id = empl.id""",
)


@@ -89,7 +89,7 @@ def _fast_fill_hr_leave_allocation_employee_company_id(env):
UPDATE hr_leave hl
SET employee_company_id = empl.company_id
FROM hr_employee empl
WHERE hl.employee_id IS NOT NULL AND hl.employee_id = empl.id""",
WHERE empl.company_id IS NOT NULL AND hl.employee_id = empl.id""",
)


@@ -148,7 +148,7 @@ def _fast_fill_hr_leave_multi_employee(env):
env.cr,
"""
ALTER TABLE hr_leave
ADD COLUMN IF NOT EXISTS multi_employee boolean""",
ADD COLUMN IF NOT EXISTS multi_employee bool""",
)
openupgrade.logged_query(
env.cr,
@@ -204,13 +204,21 @@ def _fast_fill_hr_leave_allocation_multi_employee(env):
)


def _create_column_hr_leave_holiday_allocation_id(env):
# Manually create column for avoiding the automatic launch of the compute or default
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE hr_leave
ADD COLUMN IF NOT EXISTS holiday_allocation_id integer""",
def delete_sql_constraints(env):
openupgrade.delete_sql_constraint_safely(
env, "hr_holidays", "hr_leave_allocation", "duration_check"
)
openupgrade.delete_sql_constraint_safely(
env, "hr_holidays", "hr_leave_allocation", "type_value"
)
openupgrade.delete_sql_constraint_safely(
env, "hr_holidays", "hr_leave", "type_value"
)
openupgrade.delete_sql_constraint_safely(
env, "hr_holidays", "hr_leave_allocation", "interval_number_check"
)
openupgrade.delete_sql_constraint_safely(
env, "hr_holidays", "hr_leave_allocation", "number_per_interval_check"
)


@@ -229,4 +237,4 @@ def migrate(env, version):
_fast_fill_hr_leave_multi_employee(env)
_fast_fill_hr_leave_allocation_employee_ids(env)
_fast_fill_hr_leave_allocation_multi_employee(env)
_create_column_hr_leave_holiday_allocation_id(env)
delete_sql_constraints(env)
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ hr_holidays / hr.leave / employee_ids (many2many) : NEW re
# DONE: pre-migration: create table hr_employee_hr_leave_rel and fill data

hr_holidays / hr.leave / holiday_allocation_id (many2one): NEW relation: hr.leave.allocation, isfunction: function, stored
# DONE: pre-migration: create column; post-migration: fill data
# NOTHING TO DO (due to https://github.com/odoo/odoo/pull/96545)

hr_holidays / hr.leave / multi_employee (boolean) : NEW isfunction: function, stored
# DONE: pre-migration: create column and fill data
@@ -164,11 +164,17 @@ NEW ir.model.access: hr_holidays.access_hr_leave_employee_type_report
NEW ir.model.constraint: hr_holidays.constraint_hr_leave_accrual_level_added_value_greater_than_zero
NEW ir.model.constraint: hr_holidays.constraint_hr_leave_accrual_level_check_dates
NEW ir.model.constraint: hr_holidays.constraint_hr_leave_accrual_level_start_count_check
# NOTHING TO DO

ir.model.constraint: hr_holidays.constraint_hr_leave_allocation_duration_check (changed definition: is now 'check(( number_of_days > 0 and allocation_type='regular') or(allocation_type != 'regular'))' ('check( number_of_days >= 0 )'))
ir.model.constraint: hr_holidays.constraint_hr_leave_allocation_type_value (changed definition: is now 'check((holiday_type='employee' and(employee_id is not null or multi_employee is true)) or(holiday_type='category' and category_id is not null) or(holiday_type='department' and department_id is not null) or(holiday_type='company' and mode_company_id is not null))' ('check((holiday_type='employee' and employee_id is not null) or(holiday_type='category' and category_id is not null) or(holiday_type='department' and department_id is not null) or(holiday_type='company' and mode_company_id is not null))'))
ir.model.constraint: hr_holidays.constraint_hr_leave_type_value (changed definition: is now 'check((holiday_type='employee' and(employee_id is not null or multi_employee is true)) or(holiday_type='company' and mode_company_id is not null) or(holiday_type='category' and category_id is not null) or(holiday_type='department' and department_id is not null) )' ('check((holiday_type='employee' and employee_id is not null) or(holiday_type='company' and mode_company_id is not null) or(holiday_type='category' and category_id is not null) or(holiday_type='department' and department_id is not null) )'))
# DONE: pre-migration: delete constraints and let ORM add them again

DEL ir.model.constraint: hr_holidays.constraint_hr_leave_allocation_interval_number_check
DEL ir.model.constraint: hr_holidays.constraint_hr_leave_allocation_number_per_interval_check
# DONE: pre-migration: safely delete constraints

NEW ir.rule: hr_holidays.hr_leave_report_rule_group_holiday_user (noupdate)
NEW ir.rule: hr_holidays.hr_leave_report_rule_group_user (noupdate)
NEW ir.ui.menu: hr_holidays.hr_holidays_accrual_menu_configuration

0 comments on commit 2227ab3

Please sign in to comment.