forked from OCA/hr-attendance
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from miikanissi/HR-Kanban-Attendance-Initial-Ve…
…rsion [ADD] hr_attendance_kanban
- Loading branch information
Showing
31 changed files
with
1,556 additions
and
191 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
==================== | ||
HR Kanban Attendance | ||
==================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:01df6b36e07ee9ce5048dace28f2c62aecea5768d4abd4b1972dd793e1b296d0 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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/16.0/hr_attendance_kanban | ||
: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-16-0/hr-attendance-16-0-hr_attendance_kanban | ||
: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=16.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows employees to check-in or check-out by moving their avatar on a kanban board. | ||
|
||
The kanban board also shows a quick overview of all employees, grouped by attendance type, | ||
such as: | ||
|
||
* 👋 Absent | ||
* 🏢 Office | ||
* 🏠 Home-Office | ||
* 🚋 Travelling | ||
|
||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
#. Go to *Attendances > Configuration > Attendance Types* | ||
#. Adjust the attendance types to your needs | ||
#. The employees can use *Attendances > Employees Kanban* | ||
|
||
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_kanban%0Aversion:%2016.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 | ||
~~~~~~~ | ||
|
||
* Sozialinfo | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* `Sozialinfo <https://sozialinfo.ch>`_: | ||
|
||
* David Brühlmeier <[email protected]> | ||
|
||
* Miika Nissi <[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/16.0/hr_attendance_kanban>`_ 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import models | ||
from . import models, wizard | ||
from .hooks import post_init_hook |
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,13 @@ | ||
# Copyright 2023 Verein sozialinfo.ch | ||
# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html | ||
|
||
from odoo import SUPERUSER_ID, api | ||
|
||
|
||
def post_init_hook(cr, registry): | ||
env = api.Environment(cr, SUPERUSER_ID, {}) | ||
# Recompute employee attendance type post install to ensure absent employees get | ||
# the default absent type | ||
env.add_to_compute( | ||
env["hr.employee"]._fields["attendance_type_id"], env["hr.employee"].search([]) | ||
) |
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 |
---|---|---|
@@ -1,3 +1 @@ | ||
from . import hr_attendance_type | ||
from . import hr_attendance | ||
from . import hr_employee | ||
from . import hr_attendance, hr_attendance_type, hr_employee, hr_employee_public |
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 |
---|---|---|
@@ -1,20 +1,21 @@ | ||
# Copyright 2017 Odoo S.A. | ||
# Copyright 2023 Verein sozialinfo.ch | ||
# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html | ||
|
||
from odoo import fields, models, api | ||
from odoo.exceptions import UserError | ||
from odoo import api, fields, models | ||
|
||
|
||
class HrAttendance(models.Model): | ||
_inherit = "hr.attendance" | ||
|
||
attendance_type_id = fields.Many2one('hr.attendance.type', string='Attendance Type') | ||
comment = fields.Char(string="Comment") | ||
|
||
def write(self, vals): | ||
if 'attendance_type_id' in vals: | ||
pass | ||
return super(HrAttendance, self).write(vals) | ||
attendance_type_id = fields.Many2one( | ||
"hr.attendance.type", | ||
string="Attendance Type", | ||
ondelete="restrict", | ||
help="Represents the type of employee attendance", | ||
group_expand="_read_group_attendance_type_ids", | ||
) | ||
comment = fields.Char(help="Optional comment for attendance") | ||
|
||
@api.model | ||
def _read_group_attendance_type_ids(self, stages, domain, order): | ||
return self.env["hr.attendance.type"].search([]) |
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 |
---|---|---|
@@ -1,41 +1,60 @@ | ||
# Copyright 2017 Odoo S.A. | ||
# Copyright 2023 Verein sozialinfo.ch | ||
# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html | ||
|
||
from odoo import fields, models, api | ||
from odoo import api, fields, models | ||
|
||
|
||
class HrEmployee(models.Model): | ||
_inherit = "hr.employee" | ||
|
||
attendance_type_id = fields.Many2one('hr.attendance.type', string='Attendance Type', group_expand='_read_attendance_type_ids', compute='_compute_hr_attendance_type', store=True) | ||
|
||
@api.depends_context('hr.attendance') | ||
def _compute_hr_attendance_type(self): | ||
|
||
attendance_type_id = fields.Many2one( | ||
"hr.attendance.type", | ||
string="Attendance Type", | ||
group_expand="_read_attendance_type_ids", | ||
compute="_compute_attendance_type_id", | ||
inverse="_inverse_attendance_type_id", | ||
store=True, | ||
readonly=False, | ||
groups="hr_attendance.group_hr_attendance_kiosk,hr_attendance.group_hr_attendance,hr.group_hr_user", # noqa:B950 | ||
) | ||
last_attendance_comment = fields.Char( | ||
related="last_attendance_id.comment", | ||
store=True, | ||
groups="hr_attendance.group_hr_attendance_user,hr.group_hr_user", | ||
) | ||
|
||
@api.depends( | ||
"last_attendance_id.check_in", | ||
"last_attendance_id.check_out", | ||
"last_attendance_id", | ||
) | ||
def _compute_attendance_type_id(self): | ||
"""Gets the employee attendance type from the last attendance if it's not yet | ||
checked out,otherwise employee is absent.""" | ||
absent_att_type = self.env["hr.attendance.type"].search( | ||
[("absent", "=", True)], limit=1 | ||
) | ||
for employee in self: | ||
|
||
# Get the current check-in for the employee. There should always only be one record where the check-out date is empty (Odoo standard) | ||
latest_attendance = self.env['hr.attendance'].search( | ||
[('employee_id', '=', employee.id), | ||
('check_out', '=', False)], | ||
limit=1 | ||
att = employee.last_attendance_id.sudo() | ||
employee.attendance_type_id = ( | ||
employee.last_attendance_id.attendance_type_id | ||
if att and not att.check_out | ||
else absent_att_type | ||
) | ||
|
||
if latest_attendance: | ||
# A record was found. This means the employee is present. Return the attendance type. | ||
employee.attendance_type_id = latest_attendance.attendance_type_id | ||
else: | ||
# No record was found. This means the employee is absent. Return the attendance type which is marked as 'absent' | ||
absent_attendance_type_id = self.env['hr.attendance.type'].search( | ||
[('absent', '=', True)], | ||
limit=1 | ||
) | ||
employee.attendance_type_id = absent_attendance_type_id | ||
|
||
def _inverse_attendance_type_id(self): | ||
"""Sets the attendance type of the current attendance if checked in.""" | ||
for employee in self: | ||
if ( | ||
employee.attendance_type_id | ||
and not employee.attendance_type_id.absent | ||
and employee.attendance_state == "checked_in" | ||
): | ||
employee.last_attendance_id.attendance_type_id = ( | ||
employee.attendance_type_id | ||
) | ||
|
||
# Make sure all attendance types are displayed in the kanban board | ||
@api.model | ||
def _read_attendance_type_ids(self,stages,domain,order): | ||
attendance_type_ids = self.env['hr.attendance.type'].search([]) | ||
def _read_attendance_type_ids(self, stages, domain, order): | ||
attendance_type_ids = self.env["hr.attendance.type"].search([]) | ||
return attendance_type_ids |
Oops, something went wrong.