From 061cd2f37bc38898a4a291907c69a459dd954a93 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Duy=20=28=C4=90=E1=BB=97=20Anh=29?=
Date: Wed, 2 Oct 2024 15:02:35 +0700
Subject: [PATCH] [MIG] hr_holidays_public: Migration to 18.0
---
hr_holidays_public/README.rst | 13 +++---
hr_holidays_public/__manifest__.py | 2 +-
.../models/hr_holidays_public.py | 43 ++++---------------
hr_holidays_public/models/hr_leave.py | 22 +---------
hr_holidays_public/models/hr_leave_type.py | 2 +-
.../models/resource_calendar.py | 2 +-
hr_holidays_public/readme/CONTRIBUTORS.md | 3 +-
hr_holidays_public/readme/CREDITS.md | 2 +-
.../static/description/index.html | 9 ++--
.../tests/test_holidays_calculation.py | 30 +++++++------
.../tests/test_holidays_public.py | 12 ++++--
.../views/hr_holidays_public_view.xml | 16 +++----
.../holidays_public_next_year_wizard.py | 2 +-
.../holidays_public_next_year_wizard.xml | 2 +-
14 files changed, 65 insertions(+), 95 deletions(-)
diff --git a/hr_holidays_public/README.rst b/hr_holidays_public/README.rst
index 35b4b54a..4b9f7063 100644
--- a/hr_holidays_public/README.rst
+++ b/hr_holidays_public/README.rst
@@ -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|
@@ -104,7 +104,7 @@ Bug Tracker
Bugs are tracked on `GitHub 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 `_.
+`feedback `_.
Do not contact contributors directly about support or help with technical issues.
@@ -154,11 +154,12 @@ Contributors
- `Trobz `__:
- Thao Le
+ - Do Anh Duy
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
@@ -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 `_ project on GitHub.
+This module is part of the `OCA/hr-holidays `_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/hr_holidays_public/__manifest__.py b/hr_holidays_public/__manifest__.py
index 0c8b8e2e..140925bf 100644
--- a/hr_holidays_public/__manifest__.py
+++ b/hr_holidays_public/__manifest__.py
@@ -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, "
diff --git a/hr_holidays_public/models/hr_holidays_public.py b/hr_holidays_public/models/hr_holidays_public.py
index 3b10183e..6d7f4884 100644
--- a/hr_holidays_public/models/hr_holidays_public.py
+++ b/hr_holidays_public/models/hr_holidays_public.py
@@ -3,14 +3,11 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import datetime
-import logging
from datetime import date
from odoo import SUPERUSER_ID, _, api, fields, models
from odoo.exceptions import ValidationError
-_logger = logging.getLogger(__name__)
-
class HrHolidaysPublic(models.Model):
_name = "hr.holidays.public"
@@ -52,10 +49,8 @@ def _compute_display_name(self):
else:
line.display_name = line.year
- def _get_domain_states_filter(
- self, pholidays, start_dt, end_dt, employee_id=None, partner_id=None
- ):
- partner = self._get_partner_deprecated_employee(partner_id, employee_id)
+ def _get_domain_states_filter(self, pholidays, start_dt, end_dt, partner_id=None):
+ partner = self._get_partner(partner_id)
states_filter = [("year_id", "in", pholidays.ids)]
if partner and partner.state_id:
states_filter += [
@@ -71,19 +66,17 @@ def _get_domain_states_filter(
@api.model
@api.returns("hr.holidays.public.line")
- def get_holidays_list(
- self, year=None, start_dt=None, end_dt=None, employee_id=None, partner_id=None
- ):
+ def get_holidays_list(self, year=None, start_dt=None, end_dt=None, partner_id=None):
"""
Returns recordset of hr.holidays.public.line
for the specified year and employee
:param year: year as string (optional if start_dt and end_dt defined)
:param start_dt: start_dt as date
:param end_dt: end_dt as date
- :param employee_id: ID of the employee
+ :param partner_id: ID of the partner
:return: recordset of hr.holidays.public.line
"""
- partner = self._get_partner_deprecated_employee(partner_id, employee_id)
+ partner = self._get_partner(partner_id)
if not start_dt and not end_dt:
start_dt = datetime.date(year, 1, 1)
end_dt = datetime.date(year, 12, 31)
@@ -108,15 +101,14 @@ def get_holidays_list(
return holidays_lines
@api.model
- def is_public_holiday(self, selected_date, employee_id=None, partner_id=None):
+ def is_public_holiday(self, selected_date, partner_id=None):
"""
Returns True if selected_date is a public holiday for the employee
:param selected_date: datetime object
- :param employee_id: ID of the employee
:param partner_id: ID of the partner
:return: bool
"""
- partner = self._get_partner_deprecated_employee(partner_id, employee_id)
+ partner = self._get_partner(partner_id)
partner_id = partner.id if partner else None
holidays_lines = self.get_holidays_list(
year=selected_date.year, partner_id=partner_id
@@ -127,25 +119,8 @@ def is_public_holiday(self, selected_date, employee_id=None, partner_id=None):
return True
return False
- def _get_partner_deprecated_employee(self, partner_id, employee_id):
- # TODO: Drop function in next migration
- employee = False
- partner = False
- if employee_id is not None:
- _logger.warning(
- "Use of employee_id for hr.public.holidays is deprecated. "
- "Please use partner_id instead."
- )
- employee = self.env["hr.employee"].browse(employee_id)
- partner = employee.address_id
- if partner_id:
- if partner:
- _logger.warning(
- "Cannot use both employee_id and address_id in parameters. "
- "Ignoring employee_id."
- )
- partner = self.env["res.partner"].browse(partner_id)
- return partner
+ def _get_partner(self, partner_id):
+ return self.env["res.partner"].browse(partner_id)
class HrHolidaysPublicLine(models.Model):
diff --git a/hr_holidays_public/models/hr_leave.py b/hr_holidays_public/models/hr_leave.py
index 0ee803a6..ec6c9a68 100644
--- a/hr_holidays_public/models/hr_leave.py
+++ b/hr_holidays_public/models/hr_leave.py
@@ -26,35 +26,17 @@ 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
)
- @api.depends("number_of_days")
- def _compute_number_of_hours_display(self):
- """If the leave is validated, no call to `_get_number_of_days` is done, so we
- need to inject the context here for including the public holidays if applicable.
-
- For such cases, we need to serialize the call to super in fragments.
- """
- to_serialize = self.filtered(
- lambda x: x.state == "validate"
- and x.holiday_status_id.exclude_public_holidays
- )
- for leave in to_serialize:
- leave = leave.with_context(
- exclude_public_holidays=True, employee_id=leave.employee_id.id
- )
- super(HrLeave, leave)._compute_number_of_hours_display()
- return super(HrLeave, self - to_serialize)._compute_number_of_hours_display()
-
def _get_domain_from_get_unusual_days(self, date_from, date_to=None):
domain = [("date", ">=", date_from)]
# Use the employee of the user or the one who has the context
diff --git a/hr_holidays_public/models/hr_leave_type.py b/hr_holidays_public/models/hr_leave_type.py
index 1c4a6488..679ee7d3 100644
--- a/hr_holidays_public/models/hr_leave_type.py
+++ b/hr_holidays_public/models/hr_leave_type.py
@@ -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.",
)
diff --git a/hr_holidays_public/models/resource_calendar.py b/hr_holidays_public/models/resource_calendar.py
index c63b28df..1d0088ad 100644
--- a/hr_holidays_public/models/resource_calendar.py
+++ b/hr_holidays_public/models/resource_calendar.py
@@ -20,7 +20,7 @@ def _attendance_intervals_batch_exclude_public_holidays(
.get_holidays_list(
start_dt=start_dt.date(),
end_dt=end_dt.date(),
- employee_id=self.env.context.get("employee_id", False),
+ partner_id=self.env.context.get("partner_id", False),
)
.mapped("date")
)
diff --git a/hr_holidays_public/readme/CONTRIBUTORS.md b/hr_holidays_public/readme/CONTRIBUTORS.md
index 82c4161a..2805c94e 100644
--- a/hr_holidays_public/readme/CONTRIBUTORS.md
+++ b/hr_holidays_public/readme/CONTRIBUTORS.md
@@ -16,5 +16,6 @@
- Iván Todorovich \<\>
- [Pesol](https://www.pesol.es):
- Pedro Evaristo Gonzalez Sanchez \<\>
-- [Trobz](https://trobz.com):
+- [Trobz](https://trobz.com):
- Thao Le \<\>
+ - Do Anh Duy \<\>
diff --git a/hr_holidays_public/readme/CREDITS.md b/hr_holidays_public/readme/CREDITS.md
index 8add88a2..83b3ec91 100644
--- a/hr_holidays_public/readme/CREDITS.md
+++ b/hr_holidays_public/readme/CREDITS.md
@@ -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.
diff --git a/hr_holidays_public/static/description/index.html b/hr_holidays_public/static/description/index.html
index b71e54f7..9e014f60 100644
--- a/hr_holidays_public/static/description/index.html
+++ b/hr_holidays_public/static/description/index.html
@@ -369,7 +369,7 @@ HR Holidays Public
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:9e48583a15773c28f7337bac2983bbe2febc5b6775d3f410139232f20056ec56
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-
+
This module handles public holidays.
The calculation of each leave can exclude rest public holiday, depending
on the leave type configuration.
@@ -449,7 +449,7 @@
Bugs are tracked on GitHub 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.
+feedback.
Do not contact contributors directly about support or help with technical issues.
@@ -497,13 +497,14 @@
Trobz:
-
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.
@@ -515,7 +516,7 @@
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 project on GitHub.
+
This module is part of the OCA/hr-holidays project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/hr_holidays_public/tests/test_holidays_calculation.py b/hr_holidays_public/tests/test_holidays_calculation.py
index 3a1072dc..894d704c 100644
--- a/hr_holidays_public/tests/test_holidays_calculation.py
+++ b/hr_holidays_public/tests/test_holidays_calculation.py
@@ -116,7 +116,9 @@ def setUpClass(cls):
class TestHolidaysComputeDays(TestHolidaysComputeDaysBase):
def test_number_days_excluding_employee_1(self):
- leave_request = self.HrLeave.new(
+ leave_request = self.HrLeave.with_context(
+ partner_id=self.employee_1.address_id.id
+ ).new(
{
"date_from": "1946-12-23 00:00:00", # Monday
"date_to": "1946-12-29 23:59:59", # Sunday
@@ -124,11 +126,12 @@ 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):
- leave_request = self.HrLeave.new(
+ leave_request = self.HrLeave.with_context(
+ partner_id=self.employee_2.address_id.id
+ ).new(
{
"date_from": "1946-12-23 00:00:00", # Monday
"date_to": "1946-12-29 23:59:59", # Sunday
@@ -136,11 +139,12 @@ 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):
- leave_request = self.HrLeave.new(
+ leave_request = self.HrLeave.with_context(
+ partner_id=self.employee_1.address_id.id
+ ).new(
{
"date_from": "1946-12-23 00:00:00", # Monday
"date_to": "1946-12-29 23:59:59", # Sunday
@@ -148,11 +152,12 @@ 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):
- leave_request = self.HrLeave.new(
+ leave_request = self.HrLeave.with_context(
+ partner_id=self.employee_1.address_id.id
+ ).new(
{
"date_from": "1946-12-23 00:00:00", # Monday
"date_to": "1947-01-03 23:59:59", # Friday
@@ -160,11 +165,12 @@ 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):
- leave_request = self.HrLeave.new(
+ leave_request = self.HrLeave.with_context(
+ partner_id=self.employee_2.address_id.id
+ ).new(
{
"date_from": "1946-12-23 00:00:00", # Monday
"date_to": "1947-01-03 23:59:59", # Friday
@@ -172,12 +178,13 @@ 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):
self.holiday_type.request_unit = "hour"
- leave_request = self.HrLeave.new(
+ leave_request = self.HrLeave.with_context(
+ partner_id=self.employee_2.address_id.id
+ ).new(
{
"date_from": "1946-12-23 00:00:00", # Monday
"date_to": "1946-12-29 23:59:59", # Sunday
@@ -187,4 +194,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)
diff --git a/hr_holidays_public/tests/test_holidays_public.py b/hr_holidays_public/tests/test_holidays_public.py
index 3487b6fa..30047dea 100644
--- a/hr_holidays_public/tests/test_holidays_public.py
+++ b/hr_holidays_public/tests/test_holidays_public.py
@@ -110,7 +110,7 @@ def test_isnot_holiday_in_country(self):
# ensures that correct holidays are identified for a country
self.assertFalse(
self.holiday_model.is_public_holiday(
- date(1994, 11, 14), employee_id=self.employee.id
+ date(1994, 11, 14), partner_id=self.employee.address_id.id
)
)
@@ -118,7 +118,7 @@ def test_is_holiday_in_country(self):
# ensures that correct holidays are identified for a country
self.assertTrue(
self.holiday_model.is_public_holiday(
- date(1994, 10, 14), employee_id=self.employee.id
+ date(1994, 10, 14), partner_id=self.employee.address_id.id
)
)
@@ -132,7 +132,9 @@ def test_holiday_line_year(self):
def test_list_holidays_in_list_country_specific(self):
# ensures that correct holidays are identified for a country
- lines = self.holiday_model.get_holidays_list(1994, employee_id=self.employee.id)
+ lines = self.holiday_model.get_holidays_list(
+ 1994, partner_id=self.employee.address_id.id
+ )
res = lines.filtered(lambda r: r.date == date(1994, 10, 14))
self.assertEqual(len(res), 1)
self.assertEqual(len(lines), 1)
@@ -234,7 +236,9 @@ def assertPublicHolidayIsUnusualDay(
def test_public_holidays_context(self):
self.env.ref("base.user_demo").employee_id.address_id.country_id = False
- self.leave_model = self.leave_model.with_context(employee_id=self.employee.id)
+ self.leave_model = self.leave_model.with_context(
+ partner_id=self.employee.address_id.id
+ )
self.assertPublicHolidayIsUnusualDay(
True,
country_id=self.env.ref(
diff --git a/hr_holidays_public/views/hr_holidays_public_view.xml b/hr_holidays_public/views/hr_holidays_public_view.xml
index a4bc8579..39ddbc2c 100644
--- a/hr_holidays_public/views/hr_holidays_public_view.xml
+++ b/hr_holidays_public/views/hr_holidays_public_view.xml
@@ -1,13 +1,13 @@
-
- hr.holidays.public.tree
+
+ hr.holidays.public.list
hr.holidays.public
-
+
-
+
@@ -17,7 +17,7 @@
@@ -47,7 +47,7 @@
Public Holidays
hr.holidays.public
- tree,form
+ list,form