Skip to content

Commit

Permalink
[MIG] hr_holidays_public: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviedoanhduy committed Oct 2, 2024
1 parent e0d6e3e commit bcf9a42
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 57 deletions.
13 changes: 7 additions & 6 deletions hr_holidays_public/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,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--holidays-lightgray.png?logo=github
:target: https://github.com/OCA/hr-holidays/tree/17.0/hr_holidays_public
:target: https://github.com/OCA/hr-holidays/tree/18.0/hr_holidays_public
:alt: OCA/hr-holidays
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/hr-holidays-17-0/hr-holidays-17-0-hr_holidays_public
:target: https://translation.odoo-community.org/projects/hr-holidays-18-0/hr-holidays-18-0-hr_holidays_public
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/hr-holidays&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/hr-holidays&target_branch=18.0
:alt: Try me on Runboat

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

- Thao Le <[email protected]>
- Do Anh Duy <[email protected]>

Other credits
-------------

The migration of this module from 16.0 to 17.0 was financially supported
The migration of this module from 17.0 to 18.0 was financially supported
by Camptocamp.

Maintainers
Expand All @@ -174,6 +175,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-holidays <https://github.com/OCA/hr-holidays/tree/17.0/hr_holidays_public>`_ project on GitHub.
This module is part of the `OCA/hr-holidays <https://github.com/OCA/hr-holidays/tree/18.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: 1 addition & 1 deletion hr_holidays_public/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
"name": "HR Holidays Public",
"version": "17.0.1.0.3",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"category": "Human Resources",
"author": "Michael Telahun Makonnen, "
Expand Down
14 changes: 5 additions & 9 deletions hr_holidays_public/models/hr_holidays_public.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import datetime
from datetime import date

from odoo import SUPERUSER_ID, _, api, fields, models
from odoo.exceptions import ValidationError
Expand All @@ -16,7 +15,9 @@ class HrHolidaysPublic(models.Model):
_order = "year"

display_name = fields.Char("Name", compute="_compute_display_name", store=True)
year = fields.Integer("Calendar Year", required=True, default=date.today().year)
year = fields.Integer(
"Calendar Year", required=True, default=fields.Date.today().year
)
line_ids = fields.One2many("hr.holidays.public.line", "year_id", "Holiday Dates")
country_id = fields.Many2one("res.country", "Country")

Expand Down Expand Up @@ -103,8 +104,7 @@ def get_holidays_list(
states_filter = self._get_domain_states_filter(
pholidays, start_dt, end_dt, employee_id
)
hhplo = self.env["hr.holidays.public.line"]
holidays_lines = hhplo.search(states_filter)
holidays_lines = self.env["hr.holidays.public.line"].search(states_filter)
return holidays_lines

@api.model
Expand All @@ -118,11 +118,7 @@ def is_public_holiday(self, selected_date, employee_id=None):
holidays_lines = self.get_holidays_list(
year=selected_date.year, employee_id=employee_id
)
if holidays_lines:
hol_date = holidays_lines.filtered(lambda r: r.date == selected_date)
if hol_date.ids:
return True
return False
return bool(holidays_lines.filtered(lambda r: r.date == selected_date))


class HrHolidaysPublicLine(models.Model):
Expand Down
4 changes: 2 additions & 2 deletions hr_holidays_public/models/hr_leave.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ def action_validate(self):
super(HrLeave, leave).action_validate()
return True

def _get_duration(self, check_leave_type=True, resource_calendar=None):
def _get_durations(self, check_leave_type=True, resource_calendar=None):
if self.holiday_status_id.exclude_public_holidays or not self.holiday_status_id:
instance = self.with_context(
employee_id=self.employee_id.id, exclude_public_holidays=True
)
else:
instance = self
return super(HrLeave, instance)._get_duration(
return super(HrLeave, instance)._get_durations(
check_leave_type, resource_calendar
)

Expand Down
2 changes: 1 addition & 1 deletion hr_holidays_public/models/hr_leave_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ class HrLeaveType(models.Model):

exclude_public_holidays = fields.Boolean(
default=True,
help=("If enabled, public holidays are skipped in leave days calculation."),
help="If enabled, public holidays are skipped in leave days calculation.",
)
3 changes: 2 additions & 1 deletion hr_holidays_public/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
- Iván Todorovich \<<[email protected]>\>
- [Pesol](https://www.pesol.es):
- Pedro Evaristo Gonzalez Sanchez \<<[email protected]>\>
- [Trobz](https://trobz.com):
- [Trobz](https://trobz.com):
- Thao Le \<<[email protected]>\>
- Do Anh Duy \<<[email protected]>\>
2 changes: 1 addition & 1 deletion hr_holidays_public/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
The migration of this module from 16.0 to 17.0 was financially supported by Camptocamp.
The migration of this module from 17.0 to 18.0 was financially supported by Camptocamp.
9 changes: 5 additions & 4 deletions hr_holidays_public/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <h1 class="title">HR Holidays Public</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:9e48583a15773c28f7337bac2983bbe2febc5b6775d3f410139232f20056ec56
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/hr-holidays/tree/17.0/hr_holidays_public"><img alt="OCA/hr-holidays" src="https://img.shields.io/badge/github-OCA%2Fhr--holidays-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/hr-holidays-17-0/hr-holidays-17-0-hr_holidays_public"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/hr-holidays&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/hr-holidays/tree/18.0/hr_holidays_public"><img alt="OCA/hr-holidays" src="https://img.shields.io/badge/github-OCA%2Fhr--holidays-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/hr-holidays-18-0/hr-holidays-18-0-hr_holidays_public"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/hr-holidays&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module handles public holidays.</p>
<p>The calculation of each leave can exclude rest public holiday, depending
on the leave type configuration.</p>
Expand Down Expand Up @@ -449,7 +449,7 @@ <h1><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/hr-holidays/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/hr-holidays/issues/new?body=module:%20hr_holidays_public%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/hr-holidays/issues/new?body=module:%20hr_holidays_public%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -497,13 +497,14 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
</li>
<li><a class="reference external" href="https://trobz.com">Trobz</a>:<ul>
<li>Thao Le &lt;<a class="reference external" href="mailto:thaolt&#64;trobz.com">thaolt&#64;trobz.com</a>&gt;</li>
<li>Do Anh Duy &lt;<a class="reference external" href="mailto:duyda&#64;trobz.com">duyda&#64;trobz.com</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#toc-entry-8">Other credits</a></h2>
<p>The migration of this module from 16.0 to 17.0 was financially supported
<p>The migration of this module from 17.0 to 18.0 was financially supported
by Camptocamp.</p>
</div>
<div class="section" id="maintainers">
Expand All @@ -515,7 +516,7 @@ <h2><a class="toc-backref" href="#toc-entry-9">Maintainers</a></h2>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/hr-holidays/tree/17.0/hr_holidays_public">OCA/hr-holidays</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/hr-holidays/tree/18.0/hr_holidays_public">OCA/hr-holidays</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
11 changes: 5 additions & 6 deletions hr_holidays_public/tests/test_holidays_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_number_days_excluding_employee_1(self):
"employee_id": self.employee_1.id,
}
)
leave_request._compute_duration()

self.assertEqual(leave_request.number_of_days, 4)

def _test_number_days_excluding_employee_2(self):
Expand All @@ -136,7 +136,7 @@ def _test_number_days_excluding_employee_2(self):
"employee_id": self.employee_2.id,
}
)
leave_request._compute_duration()

self.assertEqual(leave_request.number_of_days, 2)

def test_number_days_not_excluding(self):
Expand All @@ -148,7 +148,7 @@ def test_number_days_not_excluding(self):
"employee_id": self.employee_1.id,
}
)
leave_request._compute_duration()

self.assertEqual(leave_request.number_of_days, 5)

def test_number_days_across_year(self):
Expand All @@ -160,7 +160,7 @@ def test_number_days_across_year(self):
"employee_id": self.employee_1.id,
}
)
leave_request._compute_duration()

self.assertEqual(leave_request.number_of_days, 7)

def test_number_days_across_year_2(self):
Expand All @@ -172,7 +172,7 @@ def test_number_days_across_year_2(self):
"employee_id": self.employee_2.id,
}
)
leave_request._compute_duration()

self.assertEqual(leave_request.number_of_days, 5)

def test_number_of_hours_excluding_employee_2(self):
Expand All @@ -187,4 +187,3 @@ def test_number_of_hours_excluding_employee_2(self):
)

self.assertEqual(leave_request.number_of_days, 2)
self.assertEqual(leave_request.number_of_hours_display, 16)
2 changes: 1 addition & 1 deletion hr_holidays_public/tests/test_holidays_public.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_is_holiday(self):
# ensures that correct holidays are identified
self.assertTrue(self.holiday_model.is_public_holiday(date(1995, 10, 14)))

def test_isnot_holiday_in_country(self):
def test_is_not_holiday_in_country(self):
# ensures that correct holidays are identified for a country
self.assertFalse(
self.holiday_model.is_public_holiday(
Expand Down
16 changes: 8 additions & 8 deletions hr_holidays_public/views/hr_holidays_public_view.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_holidays_public_tree" model="ir.ui.view">
<field name="name">hr.holidays.public.tree</field>
<record id="view_holidays_public_list" model="ir.ui.view">
<field name="name">hr.holidays.public.list</field>
<field name="model">hr.holidays.public</field>
<field name="arch" type="xml">
<tree>
<list>
<field name="display_name" />
<field name="country_id" />
</tree>
</list>
</field>
</record>
<record id="view_holidays_public_form" model="ir.ui.view">
Expand All @@ -17,7 +17,7 @@
<form string="Public Holidays">
<group name="group_main">
<group name="group_main_left">
<field name="year" />
<field name="year" options="{'type': 'number'}" />
<field name="country_id" />
</group>
<group name="group_main_right">
Expand All @@ -26,7 +26,7 @@
</group>
<separator string="Public Holidays" name="group_detail" />
<field name="line_ids" nolabel="1">
<tree editable="top">
<list editable="top">
<field
name="date"
readonly="variable_date == False"
Expand All @@ -39,15 +39,15 @@
domain="[('country_id','=',parent.country_id)]"
/>
<field name="variable_date" />
</tree>
</list>
</field>
</form>
</field>
</record>
<record id="open_holidays_public_view" model="ir.actions.act_window">
<field name="name">Public Holidays</field>
<field name="res_model">hr.holidays.public</field>
<field name="view_mode">tree,form</field>
<field name="view_mode">list,form</field>
</record>
<menuitem
id="menu_hr_public_holidays"
Expand Down
23 changes: 7 additions & 16 deletions hr_holidays_public/wizards/holidays_public_next_year_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ class HolidaysPublicNextYearWizard(models.TransientModel):
def create_public_holidays(self):
self.ensure_one()

last_ph_dict = {}

ph_env = self.env["hr.holidays.public"]
pholidays = self.template_ids or ph_env.search([])

if not pholidays:
raise UserError(
_(
Expand All @@ -43,28 +40,22 @@ def create_public_holidays(self):
)
)

last_ph_dict = {}
for ph in pholidays:
last_ph_country = last_ph_dict.get(ph.country_id, False)

if last_ph_country:
if last_ph_country.year < ph.year:
last_ph_dict[ph.country_id] = ph
else:
if (
ph.country_id not in last_ph_dict
or last_ph_dict[ph.country_id].year < ph.year
):
last_ph_dict[ph.country_id] = ph

new_ph_ids = []
for last_ph in last_ph_dict.values():
new_year = self.year or last_ph.year + 1

new_ph_vals = {"year": new_year}

new_ph = last_ph.copy(new_ph_vals)

new_ph = last_ph.copy({"year": new_year})
new_ph_ids.append(new_ph.id)

for last_ph_line in last_ph.line_ids:
feb_29 = last_ph_line.date.month == 2 and last_ph_line.date.day == 29

if feb_29:
# Handling this rare case would mean quite a lot of
# complexity because previous or next day might also be a
Expand All @@ -89,7 +80,7 @@ def create_public_holidays(self):
action = {
"type": "ir.actions.act_window",
"name": "New public holidays",
"view_mode": "tree,form",
"view_mode": "list,form",
"res_model": "hr.holidays.public",
"domain": domain,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</div>
<group>
<field name="template_ids" />
<field name="year" />
<field name="year" options="{'type': 'number'}" />
</group>
</page>
</notebook>
Expand Down

0 comments on commit bcf9a42

Please sign in to comment.