Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][ADD]hr_holidays_cumulative_timeoff: new module #137

Closed
wants to merge 1 commit into from
Closed
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
102 changes: 102 additions & 0 deletions hr_holidays_cumulative_timeoff/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
==============================
HR Holidays Cumulative Timeoff
==============================

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

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

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

This module adds a couple of fields showing how many time-off units (days/hours) have
been used at the time of each time-off, separated by time-off type.

**Table of contents**

.. contents::
:local:

Usage
=====

Go to Time Off > Reporting > by Employee > View pivot

In the pivot view you shall see the fields "Cumulative Remaining Timeoff" and
"Cumulative Used Timeoff". These fields show the total amount of used and remaining
days for each period, separated by employee and leave category

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr-holidays/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-holidays/issues/new?body=module:%20hr_holidays_cumulative_timeoff%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
~~~~~~~

* PyTech SRL

Contributors
~~~~~~~~~~~~

* `PyTech SRL <https://www.pytech.it>`_

* Sebastiano Picchi

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.

.. |maintainer-aleuffre| image:: https://github.com/aleuffre.png?size=40px
:target: https://github.com/aleuffre
:alt: aleuffre
.. |maintainer-renda-dev| image:: https://github.com/renda-dev.png?size=40px
:target: https://github.com/renda-dev
:alt: renda-dev
.. |maintainer-PicchiSeba| image:: https://github.com/PicchiSeba.png?size=40px
:target: https://github.com/PicchiSeba
:alt: PicchiSeba

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-aleuffre| |maintainer-renda-dev| |maintainer-PicchiSeba|

This module is part of the `OCA/hr-holidays <https://github.com/OCA/hr-holidays/tree/14.0/hr_holidays_cumulative_timeoff>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions hr_holidays_cumulative_timeoff/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions hr_holidays_cumulative_timeoff/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "HR Holidays Cumulative Timeoff",
"version": "14.0.1.0.0",
"category": "Human Resources",
"website": "https://github.com/OCA/hr-holidays",
"author": "PyTech SRL, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["hr_holidays"],
"data": [
"views/hr_leave_view.xml",
],
"installable": True,
"maintainers": [
"aleuffre",
"renda-dev",
"PicchiSeba",
],
}
2 changes: 2 additions & 0 deletions hr_holidays_cumulative_timeoff/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import hr_leave
from . import hr_leave_allocation
46 changes: 46 additions & 0 deletions hr_holidays_cumulative_timeoff/models/hr_leave.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from odoo import api, fields, models


class HrLeave(models.Model):
_inherit = "hr.leave"

cumulative_remaining_timeoff = fields.Float(
compute="_compute_timeoffs",
store=True,
)
cumulative_used_timeoff = fields.Float(
compute="_compute_timeoffs",
store=True,
)

def _get_plain_unit_value(self):
self.ensure_one()
if self.holiday_status_id.request_unit == "day":
return self.number_of_days_display
else:
return self.number_of_hours_display

@api.depends("state", "date_from", "date_to", "holiday_status_id.request_unit")
def _compute_timeoffs(self):
employees = self.mapped("employee_id")
for employee in employees:
leaves = self.filtered(lambda lv, emp=employee: lv.employee_id == emp)
leave_types = leaves.mapped("holiday_status_id")
for leave_type in leave_types:
if leave_type.allocation_type == "no":
continue
max_leave_time = leave_type.with_context(
employee_id=employee.id
).max_leaves
relevant_leaves = self.search(
[
("employee_id", "=", employee.id),
("holiday_status_id", "=", leave_type.id),
],
order="date_from asc",
)
time_used = 0
for leave in relevant_leaves:
time_used += leave._get_plain_unit_value()
leave.cumulative_used_timeoff = time_used
leave.cumulative_remaining_timeoff = max_leave_time - time_used
40 changes: 40 additions & 0 deletions hr_holidays_cumulative_timeoff/models/hr_leave_allocation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from odoo import models


class HrLeaveAllocation(models.Model):
_inherit = "hr.leave.allocation"

def _propagate_cumulative_timeoff_recompute(self):
HrLeave = self.env["hr.leave"]
to_propagate = HrLeave
for hla in self:
to_propagate += HrLeave.search(
[
("employee_id", "=", hla.employee_id.id),
("holiday_status_id", "=", hla.holiday_status_id.id),
]
)
if to_propagate:
to_propagate._compute_timeoffs()

def action_approve(self):
res = super().action_approve()

valid_allocations = self.filtered(
lambda hla: hla.holiday_status_id.leave_validation_type in ("hr", "manager")
)
if valid_allocations:
valid_allocations._propagate_cumulative_timeoff_recompute()

return res

def action_validate(self):
res = super().action_validate()

valid_allocations = self.filtered(
lambda hla: hla.holiday_status_id.leave_validation_type == "both"
)
if valid_allocations:
valid_allocations._propagate_cumulative_timeoff_recompute()

return res
3 changes: 3 additions & 0 deletions hr_holidays_cumulative_timeoff/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `PyTech SRL <https://www.pytech.it>`_

* Sebastiano Picchi
2 changes: 2 additions & 0 deletions hr_holidays_cumulative_timeoff/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module adds a couple of fields showing how many time-off units (days/hours) have
PicchiSeba marked this conversation as resolved.
Show resolved Hide resolved
been used at the time of each time-off, separated by time-off type.
5 changes: 5 additions & 0 deletions hr_holidays_cumulative_timeoff/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Go to Time Off > Reporting > by Employee > View pivot

In the pivot view you shall see the fields "Cumulative Remaining Timeoff" and
"Cumulative Used Timeoff". These fields show the total amount of used and remaining
days for each period, separated by employee and leave category
Loading
Loading