Skip to content

Commit

Permalink
[18.0][MIG] hr_attendance_reason
Browse files Browse the repository at this point in the history
  • Loading branch information
TomTietze committed Nov 28, 2024
1 parent b791104 commit 563ab38
Show file tree
Hide file tree
Showing 38 changed files with 3,025 additions and 0 deletions.
104 changes: 104 additions & 0 deletions hr_attendance_reason/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
====================
HR Attendance Reason
====================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:1efc21ca72875c847f215f0527a36c5bf1bef11334f475fa794486791eea004f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-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_reason
: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_reason
: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 to define reasons why the attendance is not what
expected. Some example reasons are

- Could not access the system: Visit a customer
- Leave soon to pick up children
- The Hr manager amended the attendance and needs to tell

**Table of contents**

.. contents::
:local:

Usage
=====

1. Go to *Attendances > Configuration*.
2. Create the reasons that may cause attendances to be shorter or longer
than normal
3. When that situation occurs employees can justify the reason

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_reason%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
-------

* Odoo S.A.
* Tecnativa

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

- Odoo S.A.
- Aaron Henriquez <[email protected]>
- Damien Crier <[email protected]>
- Saran Lim. <[email protected]>
- David Alonso <[email protected]>
- Juany Davila <[email protected]>
- `Tecnativa <https://www.tecnativa.com>`__:

- Víctor Martínez
- Carlos Lopez

- Dhara Solanki <[email protected]>
- `manaTec <https://www.manatec.de/>`__:

- Tom Tietze

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_reason>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions hr_attendance_reason/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import controllers
32 changes: 32 additions & 0 deletions hr_attendance_reason/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2017 Odoo S.A.
# Copyright 2018 ForgeFlow, S.L.
# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html

{
"name": "HR Attendance Reason",
"version": "18.0.1.0.0",
"category": "Human Resources",
"website": "https://github.com/OCA/hr-attendance",
"author": "Odoo S.A., Tecnativa, Odoo Community Association (OCA)",
"license": "LGPL-3",
"installable": True,
"depends": ["hr_attendance"],
"data": [
"security/ir.model.access.csv",
"security/security.xml",
"views/hr_attendance_reason_view.xml",
"views/hr_attendance_view.xml",
"views/res_config_settings_view.xml",
],
"demo": [
"demo/hr_attendance_reason_demo.xml",
],
"assets": {
"web.assets_backend": [
"hr_attendance_reason/static/src/**/*",
],
"hr_attendance.assets_public_attendance": [
"hr_attendance_reason/static/src/**/*",
],
},
}
1 change: 1 addition & 0 deletions hr_attendance_reason/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
114 changes: 114 additions & 0 deletions hr_attendance_reason/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Copyright 2024 Tecnativa - Carlos Lopez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import http
from odoo.http import request, route

from odoo.addons.hr_attendance.controllers.main import HrAttendance


class HrAttendance(HrAttendance):
# inherited routes
@route("/hr_attendance/attendance_user_data", type="json", auth="user")
def user_attendance_data(self):
response = super().user_attendance_data()

Check warning on line 14 in hr_attendance_reason/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_reason/controllers/main.py#L14

Added line #L14 was not covered by tests
# try to get the company of the employee to show the correct reasons from
# the employees company
company = (

Check warning on line 17 in hr_attendance_reason/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_reason/controllers/main.py#L17

Added line #L17 was not covered by tests
request.env.user.employee_id.company_id
if request.env.user.employee_id
else request.env.company
)
response.update(self._get_attendance_reason_settings(company))

Check warning on line 22 in hr_attendance_reason/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_reason/controllers/main.py#L22

Added line #L22 was not covered by tests
# get available reasons for employee company
reasons = []

Check warning on line 24 in hr_attendance_reason/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_reason/controllers/main.py#L24

Added line #L24 was not covered by tests
if response.get("attendance_state", False):
if response.get("attendance_state", False) == "checked_out":
action_type = "sign_in"

Check warning on line 27 in hr_attendance_reason/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_reason/controllers/main.py#L27

Added line #L27 was not covered by tests
else:
action_type = "sign_out"
reasons = self._get_attendance_reasons(action_type, company)
response.update({"reasons": reasons})
return response

Check warning on line 32 in hr_attendance_reason/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_reason/controllers/main.py#L29-L32

Added lines #L29 - L32 were not covered by tests

@route("/hr_attendance/systray_check_in_out", type="json", auth="user")
def systray_attendance(self, latitude=False, longitude=False):
if request.params.get("attendance_reason_id"):
request.update_context(

Check warning on line 37 in hr_attendance_reason/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_reason/controllers/main.py#L37

Added line #L37 was not covered by tests
attendance_reason_id=request.params.get("attendance_reason_id")
)
return super().systray_attendance(latitude=latitude, longitude=longitude)

Check warning on line 40 in hr_attendance_reason/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_reason/controllers/main.py#L40

Added line #L40 was not covered by tests

@http.route("/hr_attendance/manual_selection", type="json", auth="public")
def manual_selection_with_geolocation(
self, token, employee_id, pin_code, latitude=False, longitude=False
):
if request.params.get("attendance_reason_id"):
request.update_context(

Check warning on line 47 in hr_attendance_reason/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_reason/controllers/main.py#L47

Added line #L47 was not covered by tests
attendance_reason_id=request.params.get("attendance_reason_id")
)
return super().manual_selection_with_geolocation(

Check warning on line 50 in hr_attendance_reason/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_reason/controllers/main.py#L50

Added line #L50 was not covered by tests
token, employee_id, pin_code, latitude, longitude
)

# new routes
@route("/hr_attendance_reason/get_reasons", type="json", auth="public")
def attendance_get_reasons(self, token, employee_id, pin_code):
company = self._get_company(token)

Check warning on line 57 in hr_attendance_reason/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_reason/controllers/main.py#L57

Added line #L57 was not covered by tests
if company:
employee = request.env["hr.employee"].sudo().browse(employee_id)

Check warning on line 59 in hr_attendance_reason/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_reason/controllers/main.py#L59

Added line #L59 was not covered by tests
if employee.company_id == company and (
(not company.attendance_kiosk_use_pin) or (employee.pin == pin_code)
):
res = self._get_employee_info_response(employee)
action_type = (

Check warning on line 64 in hr_attendance_reason/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_reason/controllers/main.py#L63-L64

Added lines #L63 - L64 were not covered by tests
"sign_out"
if res.get("attendance_state") == "checked_in"
else "sign_in"
)
res.update(

Check warning on line 69 in hr_attendance_reason/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_reason/controllers/main.py#L69

Added line #L69 was not covered by tests
{
"reasons": self._get_attendance_reasons(action_type, company),
**self._get_attendance_reason_settings(company),
}
)
return res
return {}

Check warning on line 76 in hr_attendance_reason/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_reason/controllers/main.py#L75-L76

Added lines #L75 - L76 were not covered by tests

@route("/hr_attendance_reason/reason_settings", type="json", auth="public")
def kiosk_reason_settings(self, token):
company = self._get_company(token)

Check warning on line 80 in hr_attendance_reason/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_reason/controllers/main.py#L80

Added line #L80 was not covered by tests
if company:
return self._get_attendance_reason_settings(company)
return {}

Check warning on line 83 in hr_attendance_reason/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_reason/controllers/main.py#L82-L83

Added lines #L82 - L83 were not covered by tests

def _get_attendance_reason_settings(self, company):
show_reason = company.show_reason_on_attendance_screen
required_reason = company.required_reason_on_attendance_screen
default_sign_in_reason_id = (

Check warning on line 88 in hr_attendance_reason/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_reason/controllers/main.py#L86-L88

Added lines #L86 - L88 were not covered by tests
company.reason_on_attendance_screen_default_sign_in.id
)
default_sign_out_reason_id = (

Check warning on line 91 in hr_attendance_reason/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_reason/controllers/main.py#L91

Added line #L91 was not covered by tests
company.reason_on_attendance_screen_default_sign_out.id
)
return {

Check warning on line 94 in hr_attendance_reason/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_reason/controllers/main.py#L94

Added line #L94 was not covered by tests
"show_reason_on_attendance_screen": show_reason,
"required_reason_on_attendance_screen": required_reason,
"default_sign_in_reason_id": default_sign_in_reason_id,
"default_sign_out_reason_id": default_sign_out_reason_id,
}

def _get_attendance_reasons(self, action_type, company):
"""
Get the attendance reasons to show on the attendance screen.
:param action_type: sign_in or sign_out.
"""
AttendanceReason = request.env["hr.attendance.reason"].sudo()
return AttendanceReason.search_read(

Check warning on line 107 in hr_attendance_reason/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_reason/controllers/main.py#L106-L107

Added lines #L106 - L107 were not covered by tests
domain=[
("show_on_attendance_screen", "=", True),
("action_type", "=", action_type),
("company_id", "in", [False, company.id]),
],
fields=["name", "action_type"],
)
29 changes: 29 additions & 0 deletions hr_attendance_reason/demo/hr_attendance_reason_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="hr_act_reason_1" model="hr.attendance.reason">
<field name="name">Manager Manual Amend</field>
<field name="code">MMA</field>
</record>
<record id="hr_act_reason_2" model="hr.attendance.reason">
<field name="name">Felt Sick</field>
<field name="code">FS</field>
<field name="action_type">sign_out</field>
<field name="show_on_attendance_screen" eval="True" />
</record>
<record id="hr_act_reason_3" model="hr.attendance.reason">
<field name="name">Visit Customer</field>
<field name="code">VS</field>
<field name="action_type">sign_in</field>
<field name="show_on_attendance_screen" eval="True" />
</record>
<record id="hr_act_reason_4" model="hr.attendance.reason">
<field name="name">Bad Weather</field>
<field name="code">BW</field>
</record>
<record id="hr_act_reason_5" model="hr.attendance.reason">
<field name="name">Public Transport Strike</field>
<field name="code">PTS</field>
<field name="action_type">sign_in</field>
<field name="show_on_attendance_screen" eval="True" />
</record>
</odoo>
Loading

0 comments on commit 563ab38

Please sign in to comment.