Skip to content
Open
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
122 changes: 122 additions & 0 deletions hr_attendance_resource_calendar/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
===============================
Hr Attendance Resource Calendar
===============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:5b02242f5dbe90213a92d0d2632daa7f4c6b7553a8057302a5ab4f1f79657f90
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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--attendance-lightgray.png?logo=github
:target: https://github.com/OCA/hr-attendance/tree/17.0/hr_attendance_resource_calendar
:alt: OCA/hr-attendance
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/hr-attendance-17-0/hr-attendance-17-0-hr_attendance_resource_calendar
: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-attendance&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows you to block attendance based on the employee's work
schedule.

**Table of contents**

.. contents::
:local:

Usage
=====

Validate work date according to assigned schedule
-------------------------------------------------

Kiosk Mode:

1. Go to *Attendances* > *Kiosk Mode* or Go to assistance icon marked in
the upper right corner and then click on the button that appears.
2. Select the way to identify yourself
3. Select the employee
4. When you select an employee or click the button, if the current day
or time doesn't match their work schedule, a message will be
displayed notifying them of this, and they won't be able to clock in
at that time. This validation is taken into account at the entrance.

|ATTENDANCE_MENU|

|KIOSK_MODE|

Allow entry before a certain time
---------------------------------

1. Go to *Employees* > *Configuration* > *Working Schedules*
2. Create a new working schedule
3. Define in the *Attendance Before* field a time that allows the user
to perform attendance before the actual time.
4. Save

Example: Morning: 8:00 - 12:00 Afternoon: 1:00 - 5:00

Time allowed before: 1:05

This means that the employee can clock in 1 hour and 5 minutes before
08:00 y 13:00

|ATTENDANCE_BEFORE|

.. |ATTENDANCE_MENU| image:: https://raw.githubusercontent.com/OCA/hr-attendance/17.0/hr_attendance_resource_calendar/static/img/readme/ATTENDANCE_MENU.png
.. |KIOSK_MODE| image:: https://raw.githubusercontent.com/OCA/hr-attendance/17.0/hr_attendance_resource_calendar/static/img/readme/KIOSK_MODE.png
.. |ATTENDANCE_BEFORE| image:: https://raw.githubusercontent.com/OCA/hr-attendance/17.0/hr_attendance_resource_calendar/static/img/readme/ATTENDANCE_BEFORE.png

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr-attendance/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 <https://github.com/OCA/hr-attendance/issues/new?body=module:%20hr_attendance_resource_calendar%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* Binhex

Contributors
------------

- [Binhex] (https://www.binhex.cloud):

- Edilio Escalona Almira e.escalona@binhex.cloud

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-attendance <https://github.com/OCA/hr-attendance/tree/17.0/hr_attendance_resource_calendar>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 5 additions & 0 deletions hr_attendance_resource_calendar/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2025 Binhex <https://www.binhex.cloud>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
from . import wizard
18 changes: 18 additions & 0 deletions hr_attendance_resource_calendar/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2025 Binhex <https://www.binhex.cloud>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Hr Attendance Resource Calendar",
"summary": "Employee attendance according to the established schedule.",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"author": "Binhex,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/hr-attendance",
"depends": [
"hr_attendance",
],
"data": [
"views/resource_calendar.xml",
"wizard/res_config_settings.xml",
],
}
5 changes: 5 additions & 0 deletions hr_attendance_resource_calendar/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2025 Binhex <https://www.binhex.cloud>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import hr_employee
from . import resource_calendar
84 changes: 84 additions & 0 deletions hr_attendance_resource_calendar/models/hr_employee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Copyright 2025 Binhex <https://www.binhex.cloud>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from datetime import datetime

import pytz

from odoo import _, models
from odoo.exceptions import UserError

from odoo.addons.resource.models.utils import float_to_time


class HrEmployee(models.Model):
_inherit = "hr.employee"

def _valid_attendance_working_hours(self):
tz = pytz.timezone(self.resource_calendar_id.tz or "UTC")
now_tz = datetime.now(tz)
day_week = str(now_tz.weekday())
float_time = now_tz.hour + now_tz.minute / 60 + now_tz.second / 3600
attendances = self.env["resource.calendar.attendance"].search(
[
("calendar_id", "=", self.resource_calendar_id.id),
("dayofweek", "=", day_week),
("day_period", "!=", "lunch"),
]
)
if attendances:
allow_attendance = False
for attendance in attendances:
attendance_before = (
attendance.hour_from - self.resource_calendar_id.attendance_before
)
if (
attendance.hour_from <= float_time <= attendance.hour_to
or attendance_before <= float_time <= attendance.hour_from
):
allow_attendance = True
break

if not allow_attendance:

def _get_interval_attendance(attendance):
hour_from = float_to_time(
attendance.hour_from
- self.resource_calendar_id.attendance_before
)
return (
f"\t{attendance.day_period.capitalize()}: "
f"{hour_from} - {float_to_time(attendance.hour_to)}"
)

raise UserError(
_(
"It's not yet possible to register your attendance because "
"your assigned workday hasn't started yet. You can do so from "
"the start time of your shift. Thank you for your punctuality "
"and understanding!\n\n Schedules: \n%(shedules)s"
)
% {
"shedules": "\n".join(
attendances.mapped(_get_interval_attendance)
),
}
)
else:
raise UserError(
_(
"We're unable to register your attendance at this time. "
"Please check your assigned work schedule for today."
)
)

def _attendance_action_change(self, geo_information=None):
res = super()._attendance_action_change(geo_information)
apply_restriction = (
self.env["ir.config_parameter"]
.sudo()
.get_param("hr_attendance_resource_calendar.restriction_working_schdules")
)
if self.attendance_state == "checked_in" and apply_restriction:
self._valid_attendance_working_hours()
return res
22 changes: 22 additions & 0 deletions hr_attendance_resource_calendar/models/resource_calendar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2025 Binhex <https://www.binhex.cloud>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models


class ResourceCalendar(models.Model):
_inherit = "resource.calendar"

attendance_before = fields.Float(
help="This value indicates how much earlier than the scheduled "
"start time a person can check in. "
"Enter the time in decimal hours: "
"for example, 0.25 equals 15 minutes, 0.50 equals 30 minutes, "
"and 1.00 equals 1 hour early. Only within this range "
"will clocking in before the actual start time be allowed.\n"
"Example:\n"
"\t\tMorning: 08:00 - 12:00\n"
"\t\tAfternoon: 13:00 - 17:00\n"
"\t\tTime allowed before: 01:05\n"
"\t\tThis means that the employee can clock in 1 hour "
"and 5 minutes before 08:00 y 13:00"
)
3 changes: 3 additions & 0 deletions hr_attendance_resource_calendar/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions hr_attendance_resource_calendar/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [Binhex] (https://www.binhex.cloud):
- Edilio Escalona Almira <e.escalona@binhex.cloud>
1 change: 1 addition & 0 deletions hr_attendance_resource_calendar/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allows you to block attendance based on the employee's work schedule.
36 changes: 36 additions & 0 deletions hr_attendance_resource_calendar/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Validate work date according to assigned schedule
---------------

Kiosk Mode:

1. Go to *Attendances* > *Kiosk Mode* or Go to assistance icon marked in the upper right
corner and then click on the button that appears.
2. Select the way to identify yourself
3. Select the employee
4. When you select an employee or click the button, if the current day or time doesn't match
their work schedule, a message will be displayed notifying them of this, and they won't
be able to clock in at that time.
This validation is taken into account at the entrance.

![ATTENDANCE_MENU](../static/img/readme/ATTENDANCE_MENU.png)

![KIOSK_MODE](../static/img/readme/KIOSK_MODE.png)


Allow entry before a certain time
----------------------------
1. Go to *Employees* > *Configuration* > *Working Schedules*
2. Create a new working schedule
3. Define in the *Attendance Before* field a time that allows
the user to perform attendance before the actual time.
4. Save

Example:
Morning: 8:00 - 12:00
Afternoon: 1:00 - 5:00

Time allowed before: 1:05

This means that the employee can clock in 1 hour and 5 minutes before 08:00 y 13:00

![ATTENDANCE_BEFORE](../static/img/readme/ATTENDANCE_BEFORE.png)
Loading
Loading