Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] hr_holidays_public: Migration to 12.0
- Loading branch information
1 parent
f305330
commit 68c9e8a
Showing
20 changed files
with
212 additions
and
164 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import models | ||
from . import wizards |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
from . import hr_holidays | ||
from . import hr_holidays_status | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import hr_leave | ||
from . import hr_leave_type | ||
from . import hr_holidays_public | ||
from . import resource | ||
from . import resource_calendar |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright 2017-2018 Tecnativa - Pedro M. Baeza | ||
# Copyright 2018 Brainbean Apps | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, models | ||
|
||
|
||
class HrLeave(models.Model): | ||
_inherit = 'hr.leave' | ||
|
||
def _get_number_of_days(self, date_from, date_to, employee_id): | ||
if (self.holiday_status_id.exclude_public_holidays or | ||
not self.holiday_status_id): | ||
instance = self.with_context( | ||
employee_id=employee_id, | ||
exclude_public_holidays=True, | ||
) | ||
else: | ||
instance = self | ||
return super(HrLeave, instance)._get_number_of_days( | ||
date_from, | ||
date_to, | ||
employee_id, | ||
) | ||
|
||
def _onchange_employee_id(self): | ||
super()._onchange_employee_id() | ||
self._onchange_leave_dates() | ||
|
||
@api.onchange('holiday_status_id') | ||
def _onchange_holiday_status_id(self): | ||
self._onchange_leave_dates() |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2017-2018 Tecnativa - Pedro M. Baeza | ||
# Copyright 2018 Brainbean Apps | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class HrLeaveType(models.Model): | ||
_inherit = 'hr.leave.type' | ||
|
||
exclude_public_holidays = fields.Boolean( | ||
string='Exclude Public Holidays', | ||
default=True, | ||
help=( | ||
'If enabled, public holidays are skipped in leave days' | ||
' calculation.' | ||
), | ||
) |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright 2017-2018 Tecnativa - Pedro M. Baeza | ||
# Copyright 2018 Brainbean Apps | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, models | ||
from odoo.addons.resource.models.resource import Intervals | ||
|
||
from datetime import datetime, time | ||
from dateutil import rrule | ||
|
||
|
||
class ResourceCalendar(models.Model): | ||
_inherit = 'resource.calendar' | ||
|
||
def _public_holidays_leave_intervals(self, start_dt, end_dt, employe_id): | ||
"""Get the public holidays for the current employee and given dates in | ||
the format expected by resource methods. | ||
:param: start_dt: Initial datetime. | ||
:param: end_dt: End datetime. | ||
:param: employee_id: Employee ID. It can be false. | ||
:return: List of tuples with (start_date, end_date) as elements. | ||
""" | ||
HrHolidaysPublic = self.env['hr.holidays.public'] | ||
leaves = [] | ||
for day in rrule.rrule(rrule.YEARLY, dtstart=start_dt, until=end_dt): | ||
lines = HrHolidaysPublic.get_holidays_list( | ||
day.year, employee_id=employe_id, | ||
) | ||
for line in lines: | ||
leaves.append( | ||
( | ||
datetime.combine(line.date, time.min), | ||
datetime.combine(line.date, time.max), | ||
('hr.holidays.public.line', line.id) | ||
), | ||
) | ||
return Intervals(leaves) | ||
|
||
@api.multi | ||
def _leave_intervals(self, start_dt, end_dt, resource=None, domain=None): | ||
res = super()._leave_intervals( | ||
start_dt=start_dt, | ||
end_dt=end_dt, | ||
resource=resource, | ||
domain=domain, | ||
) | ||
if self.env.context.get('exclude_public_holidays'): | ||
res += self._public_holidays_leave_intervals( | ||
start_dt, end_dt, | ||
self.env.context.get('employee_id', False), | ||
) | ||
return res |
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.