- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 716
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
1f0465f
commit 2227ab3
Showing
3 changed files
with
26 additions
and
53 deletions.
There are no files selected for viewing
41 changes: 0 additions & 41 deletions
41
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,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") |
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
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