Skip to content

Commit

Permalink
Merge PR #64 into 15.0
Browse files Browse the repository at this point in the history
Signed-off-by dreispt
  • Loading branch information
OCA-git-bot committed Dec 9, 2023
2 parents 6fdb240 + 7c43251 commit 975b0e9
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 0 deletions.
1 change: 1 addition & 0 deletions hr_holidays_calendar_event_privacy/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
to auto generate
1 change: 1 addition & 0 deletions hr_holidays_calendar_event_privacy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
21 changes: 21 additions & 0 deletions hr_holidays_calendar_event_privacy/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
],
}
2 changes: 2 additions & 0 deletions hr_holidays_calendar_event_privacy/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import hr_leave_type
from . import hr_leave
18 changes: 18 additions & 0 deletions hr_holidays_calendar_event_privacy/models/hr_leave.py
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions hr_holidays_calendar_event_privacy/models/hr_leave_type.py
Original file line number Diff line number Diff line change
@@ -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",
)
3 changes: 3 additions & 0 deletions hr_holidays_calendar_event_privacy/readme/CONFIGURATION.rst
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions hr_holidays_calendar_event_privacy/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Akim Juillerat <[email protected]>
2 changes: 2 additions & 0 deletions hr_holidays_calendar_event_privacy/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module allows to redefine the privacy level of calendar
events created from Time off requests.
1 change: 1 addition & 0 deletions hr_holidays_calendar_event_privacy/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_hr_leave_calendar_event
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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() + timedelta(days=12),
fields.Date.today() + timedelta(days=13),
)
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=13),
fields.Date.today() + timedelta(days=14),
)
leave.action_validate()
self.assertEqual(leave.meeting_id.privacy, "public")
13 changes: 13 additions & 0 deletions hr_holidays_calendar_event_privacy/views/hr_leave_type.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version='1.0' encoding='UTF-8' ?>
<odoo>
<record id="edit_holiday_status_form_inherit" model="ir.ui.view">
<field name="name">hr.leave.type.form.inherit</field>
<field name="model">hr.leave.type</field>
<field name="inherit_id" ref="hr_holidays.edit_holiday_status_form" />
<field name="arch" type="xml">
<field name="time_type" position="after">
<field name="calendar_event_privacy" />
</field>
</field>
</record>
</odoo>
6 changes: 6 additions & 0 deletions setup/hr_holidays_calendar_event_privacy/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 975b0e9

Please sign in to comment.