-
-
Notifications
You must be signed in to change notification settings - Fork 708
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a148644
commit f9c7449
Showing
3 changed files
with
120 additions
and
138 deletions.
There are no files selected for viewing
60 changes: 26 additions & 34 deletions
60
openupgrade_scripts/scripts/hr_holidays/15.0.1.5/post-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,39 @@ | ||
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"}) | ||
def fill_hr_leave_type_requires_allocation(env): | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE hr_leave_type | ||
SET requires_allocation = 'no' | ||
WHERE allocation_type = 'no'""", | ||
) | ||
|
||
|
||
_check_allocation_id._original_method = HolidaysRequest._check_allocation_id | ||
HolidaysRequest._check_allocation_id = _check_allocation_id | ||
def _map_hr_leave_state(env): | ||
openupgrade.map_values( | ||
env.cr, | ||
openupgrade.get_legacy_name("state"), | ||
"state", | ||
[("cancel", "refuse")], | ||
table="hr_leave", | ||
) | ||
|
||
|
||
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), | ||
] | ||
def _map_hr_leave_allocation_state(env): | ||
env["hr.leave.allocation"].search([("state", "=", "validate1")]).activity_update() | ||
openupgrade.map_values( | ||
env.cr, | ||
openupgrade.get_legacy_name("state"), | ||
"state", | ||
[("validate1", "confirm")], | ||
table="hr_leave_allocation", | ||
) | ||
leaves._compute_from_holiday_status_id() | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
_fill_hr_leave_holiday_allocation_id(env) | ||
_map_hr_leave_state(env) | ||
_map_hr_leave_allocation_state(env) | ||
openupgrade.load_data(env.cr, "hr_holidays", "15.0.1.5/noupdate_changes.xml") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.