Skip to content

Commit

Permalink
[MIG] hr_holidays_public: Migration to 12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-pelykh committed Dec 29, 2018
1 parent f305330 commit 68c9e8a
Show file tree
Hide file tree
Showing 20 changed files with 212 additions and 164 deletions.
13 changes: 8 additions & 5 deletions hr_holidays_public/README.rst
Expand Up @@ -14,13 +14,13 @@ HR Holidays Public
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhr-lightgray.png?logo=github
:target: https://github.com/OCA/hr/tree/11.0/hr_holidays_public
:target: https://github.com/OCA/hr/tree/12.0/hr_holidays_public
:alt: OCA/hr
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/hr-11-0/hr-11-0-hr_holidays_public
:target: https://translation.odoo-community.org/projects/hr-12-0/hr-12-0-hr_holidays_public
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/116/11.0
:target: https://runbot.odoo-community.org/runbot/116/12.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -69,7 +69,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/hr/issues/new?body=module:%20hr_holidays_public%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/hr/issues/new?body=module:%20hr_holidays_public%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -96,6 +96,9 @@ Contributors
* `Tecnativa <https://www.tecnativa.com>`__:

* Pedro M. Baeza
* `Brainbean Apps <https://brainbeanapps.com>`__:

* Alexey Pelykh <alexey.pelykh@brainbeanapps.com>

Maintainers
~~~~~~~~~~~
Expand All @@ -110,6 +113,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/hr <https://github.com/OCA/hr/tree/11.0/hr_holidays_public>`_ project on GitHub.
This module is part of the `OCA/hr <https://github.com/OCA/hr/tree/12.0/hr_holidays_public>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions hr_holidays_public/__init__.py
@@ -1,2 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
from . import wizards
8 changes: 4 additions & 4 deletions hr_holidays_public/__manifest__.py
@@ -1,9 +1,9 @@
# © 2015 2011,2013 Michael Telahun Makonnen <mmakonnen@gmail.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# Copyright 2015 2011,2013 Michael Telahun Makonnen <mmakonnen@gmail.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
'name': 'HR Holidays Public',
'version': '11.0.1.0.0',
'version': '12.0.1.0.0',
'license': 'AGPL-3',
'category': 'Human Resources',
'author': "Michael Telahun Makonnen, "
Expand All @@ -18,7 +18,7 @@
'data': [
'security/ir.model.access.csv',
'views/hr_holidays_public_view.xml',
'views/hr_holidays_status_views.xml',
'views/hr_leave_type.xml',
'wizards/holidays_public_next_year_wizard.xml',
],
'installable': True,
Expand Down
8 changes: 5 additions & 3 deletions hr_holidays_public/models/__init__.py
@@ -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
28 changes: 0 additions & 28 deletions hr_holidays_public/models/hr_holidays.py

This file was deleted.

56 changes: 33 additions & 23 deletions hr_holidays_public/models/hr_holidays_public.py
@@ -1,10 +1,10 @@
# © 2015 2011,2013 Michael Telahun Makonnen <mmakonnen@gmail.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# Copyright 2015 2011,2013 Michael Telahun Makonnen <mmakonnen@gmail.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from datetime import date

from odoo import api, fields, models, _
from odoo.exceptions import UserError
from odoo.exceptions import ValidationError


class HrHolidaysPublic(models.Model):
Expand All @@ -16,7 +16,6 @@ class HrHolidaysPublic(models.Model):
display_name = fields.Char(
"Name",
compute="_compute_display_name",
readonly=True,
store=True,
)
year = fields.Integer(
Expand Down Expand Up @@ -50,17 +49,21 @@ def _check_year_one(self):
('country_id', '=', False),
('id', '!=', self.id)]
if self.search_count(domain):
raise UserError(_('You can\'t create duplicate public holiday '
'per year and/or country'))
raise ValidationError(_(
'You can\'t create duplicate public holiday per year and/or'
' country'
))
return True

@api.multi
@api.depends('year', 'country_id')
def _compute_display_name(self):
for line in self:
if line.country_id:
line.display_name = '%s (%s)' % (line.year,
line.country_id.name)
line.display_name = '%s (%s)' % (
line.year,
line.country_id.name
)
else:
line.display_name = line.year

Expand Down Expand Up @@ -148,8 +151,11 @@ class HrHolidaysPublicLine(models.Model):
'Calendar Year',
required=True,
)
variable_date = fields.Boolean('Date may change', oldname='variable',
default=True)
variable_date = fields.Boolean(
'Date may change',
oldname='variable',
default=True,
)
state_ids = fields.Many2many(
'res.country.state',
'hr_holiday_public_state_rel',
Expand All @@ -165,29 +171,33 @@ def _check_date_state(self):
line._check_date_state_one()

def _check_date_state_one(self):
if fields.Date.from_string(self.date).year != self.year_id.year:
raise UserError(_(
'Dates of holidays should be the same year '
'as the calendar year they are being assigned to'
if self.date.year != self.year_id.year:
raise ValidationError(_(
'Dates of holidays should be the same year as the calendar'
' year they are being assigned to'
))

if self.state_ids:
domain = [('date', '=', self.date),
('year_id', '=', self.year_id.id),
('state_ids', '!=', False),
('id', '!=', self.id)]
domain = [
('date', '=', self.date),
('year_id', '=', self.year_id.id),
('state_ids', '!=', False),
('id', '!=', self.id),
]
holidays = self.search(domain)

for holiday in holidays:

if self.state_ids & holiday.state_ids:
raise UserError(_('You can\'t create duplicate public '
'holiday per date %s and one of the '
'country states.') % self.date)
raise ValidationError(_(
'You can\'t create duplicate public holiday per date'
' %s and one of the country states.'
) % self.date)
domain = [('date', '=', self.date),
('year_id', '=', self.year_id.id),
('state_ids', '=', False)]
if self.search_count(domain) > 1:
raise UserError(_('You can\'t create duplicate public holiday '
'per date %s.') % self.date)
raise ValidationError(_(
'You can\'t create duplicate public holiday per date %s.'
) % self.date)
return True
15 changes: 0 additions & 15 deletions hr_holidays_public/models/hr_holidays_status.py

This file was deleted.

32 changes: 32 additions & 0 deletions hr_holidays_public/models/hr_leave.py
@@ -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()
18 changes: 18 additions & 0 deletions hr_holidays_public/models/hr_leave_type.py
@@ -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.'
),
)
47 changes: 0 additions & 47 deletions hr_holidays_public/models/resource.py

This file was deleted.

53 changes: 53 additions & 0 deletions hr_holidays_public/models/resource_calendar.py
@@ -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
3 changes: 3 additions & 0 deletions hr_holidays_public/readme/CONTRIBUTORS.rst
Expand Up @@ -8,3 +8,6 @@
* `Tecnativa <https://www.tecnativa.com>`__:

* Pedro M. Baeza
* `Brainbean Apps <https://brainbeanapps.com>`__:

* Alexey Pelykh <alexey.pelykh@brainbeanapps.com>

0 comments on commit 68c9e8a

Please sign in to comment.