Skip to content

Commit

Permalink
raise AccessError if no employee is found for current user
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardoalso committed Jul 17, 2024
1 parent 00f87c8 commit aaf723c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion hr_attendance_overtime/models/hr_employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from dateutil.relativedelta import relativedelta
from pytz import timezone, utc

from odoo import SUPERUSER_ID, api, fields, models
from odoo import SUPERUSER_ID, _, api, fields, models
from odoo.exceptions import UserError
from odoo.osv import expression


Expand All @@ -17,6 +18,8 @@ def todays_working_times(self, empl_domain):
"""Method used by my attendance/kiosk view in order
to display employee planning and working times"""
employee = self.search(empl_domain)
if not employee:
raise UserError(_("Employee not found or not created for current user"))
employee.ensure_one()
now = fields.Datetime.now()
tz = timezone(employee.tz)
Expand Down
13 changes: 13 additions & 0 deletions hr_attendance_overtime/tests/test_attendance_overtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from odoo.tests.common import TransactionCase
from odoo.tools import mute_logger
from odoo.exceptions import UserError


class TestHrAttendanceOverTime(TransactionCase):
Expand Down Expand Up @@ -610,6 +611,18 @@ def test_check_in_on_out_time(self):
self.assertFalse(attendance.is_overtime)
self.assertFalse(attendance.attendance_reason_ids)

def test_todays_working_times_user_without_employee(self):
user = self.env["res.users"].create(
{
"name": "Test User",
"login": "test_user",
"email": "[email protected]",
"tz": "UTC",
}
)
with self.assertRaises(UserError):
self.employee.todays_working_times([("id", "=", user.id)])

def test_todays_working_times(self):
self.maxDiff = None
with freeze_time("2021-12-13 05:01", tz_offset=0):
Expand Down

0 comments on commit aaf723c

Please sign in to comment.