diff --git a/hr_holidays_public_work_location/README.rst b/hr_holidays_public_work_location/README.rst new file mode 100644 index 00000000..6b831a8c --- /dev/null +++ b/hr_holidays_public_work_location/README.rst @@ -0,0 +1,85 @@ +================================ +HR Holidays Public Work Location +================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:aea1c264c034f69c3f02bb0cd26bc835b1b9fea45ae518dd0eddf8e448fa7c2b + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :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/16.0/hr_holidays_public_work_location + :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-16-0/hr-holidays-16-0-hr_holidays_public_work_location + :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=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds the work location of employees at the public vacation line +level as an extra discriminant. That way, we can have some public vacations +that are only valid for employees working in a specific location, even when +there are more locations in the same country or state. + +The chosen work locations must belong to the public vacation's country, as well +as public vacation line's state, if any. That information is stored in the work +location's address. + +**Table of contents** + +.. contents:: + :local: + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* `ForgeFlow `_: + + * Laura Cazorla + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/hr_holidays_public_work_location/__init__.py b/hr_holidays_public_work_location/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/hr_holidays_public_work_location/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/hr_holidays_public_work_location/__manifest__.py b/hr_holidays_public_work_location/__manifest__.py new file mode 100644 index 00000000..a9edcedc --- /dev/null +++ b/hr_holidays_public_work_location/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "HR Holidays Public Work Location", + "version": "16.0.1.0.0", + "category": "Tools", + "website": "https://github.com/OCA/hr-holidays", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["hr_holidays_public"], + "data": ["views/hr_holidays_public_view.xml"], + "installable": True, + "application": False, +} diff --git a/hr_holidays_public_work_location/i18n/es.po b/hr_holidays_public_work_location/i18n/es.po new file mode 100644 index 00000000..bc413f1f --- /dev/null +++ b/hr_holidays_public_work_location/i18n/es.po @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_holidays_public_work_location +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-01-28 07:54+0000\n" +"PO-Revision-Date: 2025-01-28 07:54+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: hr_holidays_public_work_location +#: model:ir.model,name:hr_holidays_public_work_location.model_hr_holidays_public +msgid "Public Holidays" +msgstr "Festivos" + +#. module: hr_holidays_public_work_location +#: model:ir.model,name:hr_holidays_public_work_location.model_hr_holidays_public_line +msgid "Public Holidays Lines" +msgstr "Líneas de Festivos" + +#. module: hr_holidays_public_work_location +#: model:ir.model.fields,field_description:hr_holidays_public_work_location.field_hr_holidays_public_line__work_location_ids +msgid "Related Work Locations" +msgstr "Ubicaciones de Trabajo Relacionadas" + +#. module: hr_holidays_public_work_location +#: model:ir.model,name:hr_holidays_public_work_location.model_hr_leave +msgid "Time Off" +msgstr "Ausencias" diff --git a/hr_holidays_public_work_location/i18n/hr_holidays_public_work_location.pot b/hr_holidays_public_work_location/i18n/hr_holidays_public_work_location.pot new file mode 100644 index 00000000..614e3d08 --- /dev/null +++ b/hr_holidays_public_work_location/i18n/hr_holidays_public_work_location.pot @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_holidays_public_work_location +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-01-28 07:53+0000\n" +"PO-Revision-Date: 2025-01-28 07:53+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: hr_holidays_public_work_location +#: model:ir.model,name:hr_holidays_public_work_location.model_hr_holidays_public +msgid "Public Holidays" +msgstr "" + +#. module: hr_holidays_public_work_location +#: model:ir.model,name:hr_holidays_public_work_location.model_hr_holidays_public_line +msgid "Public Holidays Lines" +msgstr "" + +#. module: hr_holidays_public_work_location +#: model:ir.model.fields,field_description:hr_holidays_public_work_location.field_hr_holidays_public_line__work_location_ids +msgid "Related Work Locations" +msgstr "" + +#. module: hr_holidays_public_work_location +#: model:ir.model,name:hr_holidays_public_work_location.model_hr_leave +msgid "Time Off" +msgstr "" diff --git a/hr_holidays_public_work_location/models/__init__.py b/hr_holidays_public_work_location/models/__init__.py new file mode 100644 index 00000000..fba3743d --- /dev/null +++ b/hr_holidays_public_work_location/models/__init__.py @@ -0,0 +1,2 @@ +from . import hr_holidays_public +from . import hr_leave diff --git a/hr_holidays_public_work_location/models/hr_holidays_public.py b/hr_holidays_public_work_location/models/hr_holidays_public.py new file mode 100644 index 00000000..898c3513 --- /dev/null +++ b/hr_holidays_public_work_location/models/hr_holidays_public.py @@ -0,0 +1,73 @@ +# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class HrHolidaysPublic(models.Model): + _inherit = "hr.holidays.public" + + def _get_domain_states_filter( + self, pholidays, start_dt, end_dt, employee_id=None, partner_id=None + ): + domain = super()._get_domain_states_filter( + pholidays=pholidays, + start_dt=start_dt, + end_dt=end_dt, + employee_id=employee_id, + partner_id=partner_id, + ) + # To check for holidays in work locations, we must use the employee's + # information instead of the partner's information + employee_id = employee_id or self.env.context.get("employee_id", False) + employee = self.env["hr.employee"].browse(employee_id) if employee_id else False + # We check if the employee has a work location set, and we add that + # restriction to the domain + if employee and employee.work_location_id: + domain += [ + "|", + ("work_location_ids", "=", False), + ("work_location_ids", "=", employee.work_location_id.id), + ] + else: + domain.append(("work_location_ids", "=", False)) + return domain + + +class HrHolidaysPublicLine(models.Model): + _inherit = "hr.holidays.public.line" + + work_location_ids = fields.Many2many( + "hr.work.location", + "hr_holiday_public_work_location_rel", + "line_id", + "work_location_id", + "Related Work Locations", + ) + + @api.constrains("work_location_ids") + def _check_date_state_work_location_ids(self): + self._check_date_state() + + @api.constrains("work_location_ids") + def _update_calendar_event_work_location_ids(self): + self._update_calendar_event() + + def _get_domain_check_date_state_one_state_ids(self): + domain = super()._get_domain_check_date_state_one_state_ids() + if self.work_location_ids: + domain += [("work_location_ids", "!=", False)] + return domain + + def _get_domain_check_date_state_one(self): + domain = super()._get_domain_check_date_state_one() + domain += [("work_location_ids", "=", False)] + return domain + + def _prepare_holidays_meeting_values(self): + res = super()._prepare_holidays_meeting_values() + if self.work_location_ids: + res["description"] += ": " + ", ".join( + self.work_location_ids.mapped("name") + ) + return res diff --git a/hr_holidays_public_work_location/models/hr_leave.py b/hr_holidays_public_work_location/models/hr_leave.py new file mode 100644 index 00000000..16392f3d --- /dev/null +++ b/hr_holidays_public_work_location/models/hr_leave.py @@ -0,0 +1,31 @@ +# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class HrLeave(models.Model): + _inherit = "hr.leave" + + def _get_domain_from_get_unusual_days(self, date_from, date_to=None): + domain = super()._get_domain_from_get_unusual_days( + date_from=date_from, date_to=date_to + ) + # Use the employee of the user or the one who has the context + employee_id = self.env.context.get("employee_id", False) + employee = ( + self.env["hr.employee"].browse(employee_id) + if employee_id + else self.env.user.employee_id + ) + # Add work location domain + work_location = employee.work_location_id.id + if work_location: + domain.extend( + [ + "|", + ("work_location_ids", "=", work_location), + ("work_location_ids", "=", False), + ] + ) + return domain diff --git a/hr_holidays_public_work_location/readme/CONTRIBUTORS.rst b/hr_holidays_public_work_location/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..5689de76 --- /dev/null +++ b/hr_holidays_public_work_location/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `ForgeFlow `_: + + * Laura Cazorla diff --git a/hr_holidays_public_work_location/readme/DESCRIPTION.rst b/hr_holidays_public_work_location/readme/DESCRIPTION.rst new file mode 100644 index 00000000..d3dff676 --- /dev/null +++ b/hr_holidays_public_work_location/readme/DESCRIPTION.rst @@ -0,0 +1,8 @@ +This module adds the work location of employees at the public vacation line +level as an extra discriminant. That way, we can have some public vacations +that are only valid for employees working in a specific location, even when +there are more locations in the same country or state. + +The chosen work locations must belong to the public vacation's country, as well +as public vacation line's state, if any. That information is stored in the work +location's address. diff --git a/hr_holidays_public_work_location/static/description/index.html b/hr_holidays_public_work_location/static/description/index.html new file mode 100644 index 00000000..c26375af --- /dev/null +++ b/hr_holidays_public_work_location/static/description/index.html @@ -0,0 +1,432 @@ + + + + + +HR Holidays Public Work Location + + + +
+

HR Holidays Public Work Location

+ + +

Beta License: AGPL-3 OCA/hr-holidays Translate me on Weblate Try me on Runboat

+

This module adds the work location of employees at the public vacation line +level as an extra discriminant. That way, we can have some public vacations +that are only valid for employees working in a specific location, even when +there are more locations in the same country or state.

+

The chosen work locations must belong to the public vacation’s country, as well +as public vacation line’s state, if any. That information is stored in the work +location’s address.

+

Table of contents

+ +
+

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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ForgeFlow
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/hr_holidays_public_work_location/tests/__init__.py b/hr_holidays_public_work_location/tests/__init__.py new file mode 100644 index 00000000..8b16ef2e --- /dev/null +++ b/hr_holidays_public_work_location/tests/__init__.py @@ -0,0 +1,2 @@ +from . import test_holidays_calculation +from . import test_holidays_public diff --git a/hr_holidays_public_work_location/tests/test_holidays_calculation.py b/hr_holidays_public_work_location/tests/test_holidays_calculation.py new file mode 100644 index 00000000..1cbc6db0 --- /dev/null +++ b/hr_holidays_public_work_location/tests/test_holidays_calculation.py @@ -0,0 +1,24 @@ +# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.addons.hr_holidays_public.tests import test_holidays_calculation + + +class TestHolidaysComputeDays(test_holidays_calculation.TestHolidaysComputeDays): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.work_location_model = cls.env["hr.work.location"] + cls.work_location_a = cls.work_location_model.create( + { + "name": "Work Location A (ES)", + "address_id": cls.address_2.id, + } + ) + + cls.employee_1.write({"address_home_id": cls.address_1.id}) + cls.employee_2.write({"address_home_id": cls.address_2.id}) + cls.employee_2.write({"work_location_id": cls.work_location_a.id}) + cls.public_holiday_country.line_ids.work_location_ids = cls.work_location_a.ids + + # Run all tests of hr_holidays_public diff --git a/hr_holidays_public_work_location/tests/test_holidays_public.py b/hr_holidays_public_work_location/tests/test_holidays_public.py new file mode 100644 index 00000000..a8c759b8 --- /dev/null +++ b/hr_holidays_public_work_location/tests/test_holidays_public.py @@ -0,0 +1,132 @@ +# Copyright 2025 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.addons.hr_holidays_public.tests import test_holidays_public + + +class TestHolidaysPublicBase(test_holidays_public.TestHolidaysPublicBase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.work_location_model = cls.env["hr.work.location"] + cls.work_location_a = cls.work_location_model.create( + { + "name": "Work Location A (US)", + "address_id": cls.env.company.partner_id.id, + } + ) + cls.work_location_b = cls.work_location_model.create( + { + "name": "Work Location B (US)", + "address_id": cls.env.company.partner_id.id, + } + ) + + +class TestHolidaysPublic(TestHolidaysPublicBase): + def assertPublicHolidayIsUnusualDay( + self, expected, country_id=None, state_ids=False, work_location_ids=False + ): + self.assertFalse( + self.leave_model.with_user(self.env.ref("base.user_demo").id) + .get_unusual_days("2019-07-01", date_to="2019-07-31") + .get("2019-07-30", False) + ) + holiday = self.holiday_model.create({"year": 2019, "country_id": country_id}) + self.holiday_model_line.create( + { + "name": "holiday x", + "date": "2019-07-30", + "year_id": holiday.id, + "state_ids": state_ids, + "work_location_ids": work_location_ids, + } + ) + self.assertEqual( + self.leave_model.with_user( + self.env.ref("base.user_demo").id + ).get_unusual_days("2019-07-01", date_to="2019-07-31")["2019-07-30"], + expected, + ) + + def test_public_holidays_context(self): + self.env.ref("base.user_demo").employee_id.address_id.country_id = False + self.env.ref("base.user_demo").employee_id.address_id.state_id = False + self.env.ref("base.user_demo").employee_id.work_location_id = False + self.employee.address_id.country_id = self.env.ref("base.us") + self.employee.address_id.state_id = self.env.ref("base.state_us_4") + self.employee.work_location_id = self.work_location_a + + self.leave_model = self.leave_model.with_context(employee_id=self.employee.id) + self.assertPublicHolidayIsUnusualDay( + True, + country_id=self.env.ref( + "base.user_demo" + ).employee_id.address_id.country_id.id, + state_ids=[(6, 0, [self.employee.address_id.state_id.id])], + work_location_ids=[(6, 0, [self.employee.work_location_id.id])], + ) + + def test_get_unusual_days_return_public_holidays_same_state_same_work_location( + self, + ): + demo_user_empl_addr = self.env.ref("base.user_demo").employee_id.address_id + demo_user_empl = self.env.ref("base.user_demo").employee_id + demo_user_empl_addr.country_id = self.env.ref("base.us") + demo_user_empl_addr.state_id = self.env.ref("base.state_us_4") + demo_user_empl.work_location_id = self.work_location_a + self.assertPublicHolidayIsUnusualDay( + True, + country_id=self.env.ref( + "base.user_demo" + ).employee_id.address_id.country_id.id, + state_ids=[(6, 0, [demo_user_empl_addr.state_id.id])], + work_location_ids=[(6, 0, [demo_user_empl.work_location_id.id])], + ) + + def test_get_unusual_days_return_public_holidays_same_state_different_work_location( + self, + ): + demo_user_empl_addr = self.env.ref("base.user_demo").employee_id.address_id + demo_user_empl = self.env.ref("base.user_demo").employee_id + demo_user_empl_addr.country_id = self.env.ref("base.us") + demo_user_empl_addr.state_id = self.env.ref("base.state_us_4") + demo_user_empl.work_location_id = self.work_location_a + self.assertPublicHolidayIsUnusualDay( + False, + country_id=self.env.ref( + "base.user_demo" + ).employee_id.address_id.country_id.id, + state_ids=[(6, 0, [demo_user_empl_addr.state_id.id])], + work_location_ids=[(6, 0, [self.work_location_b.id])], + ) + + def test_get_unusual_days_return_public_holidays_no_state_same_work_location(self): + demo_user_empl_addr = self.env.ref("base.user_demo").employee_id.address_id + demo_user_empl = self.env.ref("base.user_demo").employee_id + demo_user_empl_addr.country_id = self.env.ref("base.us") + demo_user_empl_addr.state_id = self.env.ref("base.state_us_4") + demo_user_empl.work_location_id = self.work_location_a + self.assertPublicHolidayIsUnusualDay( + True, + country_id=self.env.ref( + "base.user_demo" + ).employee_id.address_id.country_id.id, + work_location_ids=[(6, 0, [demo_user_empl.work_location_id.id])], + ) + + def test_get_unusual_days_return_public_holidays_no_state_different_work_location( + self, + ): + demo_user_empl_addr = self.env.ref("base.user_demo").employee_id.address_id + demo_user_empl = self.env.ref("base.user_demo").employee_id + demo_user_empl_addr.country_id = self.env.ref("base.us") + demo_user_empl_addr.state_id = self.env.ref("base.state_us_4") + demo_user_empl.work_location_id = self.work_location_a + self.assertPublicHolidayIsUnusualDay( + True, + country_id=self.env.ref( + "base.user_demo" + ).employee_id.address_id.country_id.id, + work_location_ids=[(6, 0, [demo_user_empl.work_location_id.id])], + ) diff --git a/hr_holidays_public_work_location/views/hr_holidays_public_view.xml b/hr_holidays_public_work_location/views/hr_holidays_public_view.xml new file mode 100644 index 00000000..d0fc17c2 --- /dev/null +++ b/hr_holidays_public_work_location/views/hr_holidays_public_view.xml @@ -0,0 +1,17 @@ + + + + hr.holidays.public.form + hr.holidays.public + + + + + + + + diff --git a/setup/hr_holidays_public_work_location/odoo/addons/hr_holidays_public_work_location b/setup/hr_holidays_public_work_location/odoo/addons/hr_holidays_public_work_location new file mode 120000 index 00000000..519bf18e --- /dev/null +++ b/setup/hr_holidays_public_work_location/odoo/addons/hr_holidays_public_work_location @@ -0,0 +1 @@ +../../../../hr_holidays_public_work_location \ No newline at end of file diff --git a/setup/hr_holidays_public_work_location/setup.py b/setup/hr_holidays_public_work_location/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/hr_holidays_public_work_location/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)