diff --git a/hr_holidays_calendar_event_privacy/README.rst b/hr_holidays_calendar_event_privacy/README.rst new file mode 100644 index 00000000..fa6c1a08 --- /dev/null +++ b/hr_holidays_calendar_event_privacy/README.rst @@ -0,0 +1 @@ +to auto generate diff --git a/hr_holidays_calendar_event_privacy/__init__.py b/hr_holidays_calendar_event_privacy/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/hr_holidays_calendar_event_privacy/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/hr_holidays_calendar_event_privacy/__manifest__.py b/hr_holidays_calendar_event_privacy/__manifest__.py new file mode 100644 index 00000000..36aac35e --- /dev/null +++ b/hr_holidays_calendar_event_privacy/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +{ + "name": "Hr holidays calendar events privacy", + "summary": "Define privacy level of calendar events from Time off requests", + "version": "15.0.1.0.0", + "development_status": "Alpha", + "category": "Human Resources", + "website": "https://github.com/OCA/hr-holidays", + "author": "Camptocamp, Odoo Community Association (OCA)", + "maintainers": ["grindtildeath"], + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "hr_holidays", + ], + "data": [ + "views/hr_leave_type.xml", + ], +} diff --git a/hr_holidays_calendar_event_privacy/models/__init__.py b/hr_holidays_calendar_event_privacy/models/__init__.py new file mode 100644 index 00000000..7c444ff5 --- /dev/null +++ b/hr_holidays_calendar_event_privacy/models/__init__.py @@ -0,0 +1,2 @@ +from . import hr_leave_type +from . import hr_leave diff --git a/hr_holidays_calendar_event_privacy/models/hr_leave.py b/hr_holidays_calendar_event_privacy/models/hr_leave.py new file mode 100644 index 00000000..afcbe1b1 --- /dev/null +++ b/hr_holidays_calendar_event_privacy/models/hr_leave.py @@ -0,0 +1,18 @@ +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import models +from odoo.tools import groupby + + +class HrLeave(models.Model): + _inherit = "hr.leave" + + def _prepare_holidays_meeting_values(self): + """Set calendar events privacy for hr leaves according to type""" + res = super()._prepare_holidays_meeting_values() + for user, holidays in groupby(self, lambda h: h.user_id): + for holiday, meeting_vals in zip(holidays, res.get(user.id)): + meeting_vals[ + "privacy" + ] = holiday.holiday_status_id.calendar_event_privacy + return res diff --git a/hr_holidays_calendar_event_privacy/models/hr_leave_type.py b/hr_holidays_calendar_event_privacy/models/hr_leave_type.py new file mode 100644 index 00000000..fbb61c5a --- /dev/null +++ b/hr_holidays_calendar_event_privacy/models/hr_leave_type.py @@ -0,0 +1,17 @@ +# Copyright 2023 Camptocamp SA +# 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" + + calendar_event_privacy = fields.Selection( + [ + ("public", "Public"), + ("private", "Private"), + ("confidential", "Only internal users"), + ], + default="confidential", + help="Defines privacy of calendar events created for this Time Off Type", + ) diff --git a/hr_holidays_calendar_event_privacy/readme/CONFIGURATION.rst b/hr_holidays_calendar_event_privacy/readme/CONFIGURATION.rst new file mode 100644 index 00000000..31087991 --- /dev/null +++ b/hr_holidays_calendar_event_privacy/readme/CONFIGURATION.rst @@ -0,0 +1,3 @@ +In Time Off > Configuration > Time Off Types, you can define +the privacy level that will be used to create calendar events +for Time Off Requests of this type. diff --git a/hr_holidays_calendar_event_privacy/readme/CONTRIBUTORS.rst b/hr_holidays_calendar_event_privacy/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..e31e2f0c --- /dev/null +++ b/hr_holidays_calendar_event_privacy/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Akim Juillerat diff --git a/hr_holidays_calendar_event_privacy/readme/DESCRIPTION.rst b/hr_holidays_calendar_event_privacy/readme/DESCRIPTION.rst new file mode 100644 index 00000000..1d783d96 --- /dev/null +++ b/hr_holidays_calendar_event_privacy/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module allows to redefine the privacy level of calendar +events created from Time off requests. diff --git a/hr_holidays_calendar_event_privacy/tests/__init__.py b/hr_holidays_calendar_event_privacy/tests/__init__.py new file mode 100644 index 00000000..fa2178a0 --- /dev/null +++ b/hr_holidays_calendar_event_privacy/tests/__init__.py @@ -0,0 +1 @@ +from . import test_hr_leave_calendar_event diff --git a/hr_holidays_calendar_event_privacy/tests/test_hr_leave_calendar_event.py b/hr_holidays_calendar_event_privacy/tests/test_hr_leave_calendar_event.py new file mode 100644 index 00000000..8792c55c --- /dev/null +++ b/hr_holidays_calendar_event_privacy/tests/test_hr_leave_calendar_event.py @@ -0,0 +1,37 @@ +# Copyright 2023 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from datetime import timedelta + +from odoo import fields +from odoo.tests import Form, TransactionCase + + +class TestHrLeaveCalendarEvent(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.admin_user = cls.env.ref("base.user_admin") + cls.leave_type = cls.env.ref("hr_holidays.holiday_status_cl") + + @classmethod + def _new_leave_request(cls, date_from, date_to): + leave_form = Form(cls.env["hr.leave"].with_user(cls.admin_user)) + leave_form.holiday_status_id = cls.leave_type + leave_form.date_from = date_from + leave_form.date_to = date_to + return leave_form.save() + + def test_calendar_event_privacy(self): + self.assertEqual(self.leave_type.calendar_event_privacy, "confidential") + leave = self._new_leave_request( + fields.Date.today(), fields.Date.today() + timedelta(days=1) + ) + leave.action_validate() + self.assertEqual(leave.meeting_id.privacy, "confidential") + self.leave_type.calendar_event_privacy = "public" + leave = self._new_leave_request( + fields.Date.today() + timedelta(days=3), + fields.Date.today() + timedelta(days=4), + ) + leave.action_validate() + self.assertEqual(leave.meeting_id.privacy, "public") diff --git a/hr_holidays_calendar_event_privacy/views/hr_leave_type.xml b/hr_holidays_calendar_event_privacy/views/hr_leave_type.xml new file mode 100644 index 00000000..288acfb6 --- /dev/null +++ b/hr_holidays_calendar_event_privacy/views/hr_leave_type.xml @@ -0,0 +1,13 @@ + + + + hr.leave.type.form.inherit + hr.leave.type + + + + + + + + diff --git a/setup/hr_holidays_calendar_event_privacy/odoo/addons/hr_holidays_calendar_event_privacy b/setup/hr_holidays_calendar_event_privacy/odoo/addons/hr_holidays_calendar_event_privacy new file mode 120000 index 00000000..eb1e1f04 --- /dev/null +++ b/setup/hr_holidays_calendar_event_privacy/odoo/addons/hr_holidays_calendar_event_privacy @@ -0,0 +1 @@ +../../../../hr_holidays_calendar_event_privacy \ No newline at end of file diff --git a/setup/hr_holidays_calendar_event_privacy/setup.py b/setup/hr_holidays_calendar_event_privacy/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/hr_holidays_calendar_event_privacy/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)