-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] hr_attendance_sheet_compensatory - Refactor of hr_attendance_va…
…lidation to make it works with hr_attendance_sheet
- Loading branch information
1 parent
097b5d4
commit 8817add
Showing
28 changed files
with
2,124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
================================ | ||
HR Attendance Sheet Compensatory | ||
================================ | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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/14.0/hr_attendance_sheet_compensatory | ||
: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-14-0/hr-attendance-14-0-hr_attendance_sheet_compensatory | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/hr-attendance&target_branch=14.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This is based on `hr_attendance_sheet` which add a validation mechanism | ||
to review employee attendance with an auto-lunch calculation. | ||
This allows to generate compensatory hours (allocated leaves) that can | ||
be used later as day off or to regulate credits leaves as | ||
this module is compatible with `hr_holidays_credit` module. | ||
|
||
This is based on the `hr_attendance_overtime` module which | ||
mark rows as "overtime" those rows are not due by default | ||
as it could came from possible mist check-out. So manager can | ||
decide to add or not those overtime attendance lines or not and | ||
compute or adjust compensatory/leaves hours to generate. | ||
|
||
This module is **incompatible** with hr_attendance_validation | ||
because it implements the same feature and especially generates | ||
errors during hr.attendance validation | ||
|
||
..note:: | ||
|
||
If you are allowing flexible hours - check-in/check-out range | ||
are bigger than average hours per day - So you can generate | ||
compensatory hours from lines that are not marked as overtime. | ||
|
||
Once review is validated attendance lines are locked on that period. | ||
|
||
At the end managers can check holidays allocation per year and | ||
by employee to make sure allowed employee compensatory hours are | ||
not over. | ||
|
||
Employees can: | ||
- access to validated sheets to review hours taken account | ||
- see current week hours on check-in view | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Configuration | ||
============= | ||
|
||
* Ensure employee weeks are properly set | ||
* Set the leave type to use by generating compensatory | ||
hours from attendance review (to be done in hr attendance configuration) | ||
* once all leaves and attendances has been recorded you can generate leave reviews | ||
by setting up a cron job running every monday morning to generate the previous week | ||
with the following code on `hr.attendance.sheet` model:: | ||
|
||
model.generate_reviews() | ||
|
||
Usage | ||
===== | ||
|
||
* Once review has been generate by ir cron manager are able to | ||
open each one on Attenances > Manager > Attendance validation | ||
* On each form decide if recorded overtime are due or not | ||
* change the amount of allocated compensatory hours to generate | ||
* validate the review to generate the allocation | ||
|
||
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 smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/hr-attendance/issues/new?body=module:%20hr_attendance_sheet_compensatory%0Aversion:%2014.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 | ||
~~~~~~~ | ||
|
||
* Odoo S.A. | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Pierre Verkest <[email protected]> | ||
* Maxime Franco <[email protected]> | ||
|
||
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/14.0/hr_attendance_sheet_compensatory>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright 2021 Pierre Verkest | ||
# Copyright 2023 ACSONE SA/NV | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
{ | ||
"name": "HR Attendance Sheet Compensatory", | ||
"version": "14.0.1.0.3", | ||
"category": "Human Resources", | ||
"summary": "Group attendances into attendance sheets.", | ||
"website": "https://github.com/OCA/hr-attendance", | ||
"author": "Odoo S.A., Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"installable": True, | ||
"depends": [ | ||
"hr_attendance", | ||
"hr_attendance_sheet", | ||
"hr_attendance_overtime", | ||
"hr_attendance_reason", | ||
"hr_attendance_modification_tracking", | ||
"hr_holidays", | ||
], | ||
"data": [ | ||
"security/hr_attendance_sheet_rule.xml", | ||
"views/assets.xml", | ||
"views/hr_attendance.xml", | ||
"views/hr_attendance_sheet.xml", | ||
"views/res_config_settings_views.xml", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from . import hr_attendance | ||
from . import hr_attendance_sheet | ||
from . import hr_employee | ||
from . import hr_leave | ||
from . import res_company | ||
from . import res_config | ||
from . import resource_calendar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Copyright 2021 Pierre Verkest | ||
# Copyright 2023 ACSONE SA/NV | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
from odoo import SUPERUSER_ID, _, api, fields, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class HrAttendance(models.Model): | ||
_inherit = "hr.attendance" | ||
|
||
is_overtime_due = fields.Boolean( | ||
string="Is overtime due", | ||
default=False, | ||
help="Whether the overtime is due or not. " | ||
"By default overtime is not due until a manager validates it.", | ||
) | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
attendances = super().create(vals_list) | ||
for attendance in attendances: | ||
if attendance._is_validated_employee_week(): | ||
raise ValidationError( | ||
_( | ||
"Cannot create new attendance for employee %s. " | ||
"Attendance for the day of the check in %s " | ||
"has already been reviewed and validated." | ||
) | ||
% ( | ||
attendance.employee_id.name, | ||
attendance.check_in.date(), | ||
) | ||
) | ||
return attendances | ||
|
||
def unlink(self): | ||
for record in self: | ||
if record.attendance_sheet_id.state == "done": | ||
raise ValidationError( | ||
_( | ||
"Can not remove this attendance (%s, %s) " | ||
"which has been already reviewed and validated." | ||
) | ||
% ( | ||
record.employee_id.name, | ||
record.check_in.date(), | ||
) | ||
) | ||
return super().unlink() | ||
|
||
def write(self, vals): | ||
allowed_fields = {"auto_lunch"} | ||
is_allowed_fields = allowed_fields.issuperset(vals.keys()) | ||
for record in self: | ||
if record.attendance_sheet_id.state == "done" and not is_allowed_fields: | ||
raise ValidationError( | ||
_( | ||
"Can not change this attendance (%s, %s) " | ||
"which has been already reviewed and validated." | ||
) | ||
% ( | ||
record.employee_id.name, | ||
record.check_in.date(), | ||
) | ||
) | ||
res = super().write(vals) | ||
for record in self: | ||
if record._is_validated_employee_week() and not is_allowed_fields: | ||
raise ValidationError( | ||
_( | ||
"Can not change this attendance (%s, %s) " | ||
"which would be moved to a validated day." | ||
) | ||
% ( | ||
record.employee_id.name, | ||
record.check_in.date(), | ||
) | ||
) | ||
return res | ||
|
||
def _is_validated_employee_week(self): | ||
validated_week = ( | ||
self.env["hr.attendance.sheet"] | ||
.with_user(SUPERUSER_ID) | ||
.search_count( | ||
[ | ||
("employee_id", "=", self.employee_id.id), | ||
("state", "=", "done"), | ||
("date_start", "<=", self.check_in.date()), | ||
("date_end", ">=", self.check_in.date()), | ||
] | ||
) | ||
) | ||
return validated_week > 0 |
Oops, something went wrong.