Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions portal_holidays/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import hr_leave
from . import hr_leave_allocation
24 changes: 24 additions & 0 deletions portal_holidays/models/hr_leave.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import _, api, models
from odoo.exceptions import AccessError


class HolidaysRequest(models.Model):
_inherit = "hr.leave"

@api.model_create_multi
def create(self, vals_list):
"""
Allows users in the portal holidays group to create leave requests
only for themselves. If the user passes the check, the method runs with
elevated privileges to bypass access restrictions if necessary.
"""
if self.env.user.has_group("portal_holidays.group_portal_backend_holiday"):
user_employee_id = self.env.user.employee_id.id
for vals in vals_list:
if vals.get("employee_id", user_employee_id) != user_employee_id:
raise AccessError(_("You can only create time off requests for yourself."))
self = self.sudo()

return super().create(vals_list)
Loading