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

[17.0][ADD] hr_holidays_remaining_leaves #127

Closed
wants to merge 20 commits 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ addon | version | maintainers | summary
--- | --- | --- | ---
[hr_holidays_public](hr_holidays_public/) | 17.0.1.0.1 | | Manage Public Holidays
[hr_holidays_public_city](hr_holidays_public_city/) | 17.0.1.0.0 | [![victoralmau](https://github.com/victoralmau.png?size=30px)](https://github.com/victoralmau) | HR Holidays Public City
[hr_holidays_remaining_leaves](hr_holidays_remaining_leaves/) | 17.0.1.0.0 | | HR Holidays Remaining Leaves

[//]: # (end addons)

Expand Down
87 changes: 87 additions & 0 deletions hr_holidays_remaining_leaves/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
============================
HR Holidays Remaining Leaves
============================

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

.. |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/17.0/hr_holidays_remaining_leaves
: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-17-0/hr-holidays-17-0-hr_holidays_remaining_leaves
: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=17.0
:alt: Try me on Runboat

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

Show remaining leaves per employee in allocation overview.

**Table of contents**

.. contents::
:local:

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

* Mint System GmbH
* Camptocamp

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

- Janik von Rotz [email protected]
- Son Ho [email protected]

Other credits
-------------

The original development of this module has been done by Mint System. It
can be found in:
https://github.com/Mint-System/Odoo-Apps-HR/tree/16.0/hr_holidays_remaining_leaves

This module has been ported to the OCA with their agreement.

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-holidays <https://github.com/OCA/hr-holidays/tree/17.0/hr_holidays_remaining_leaves>`_ 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_remaining_leaves/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions hr_holidays_remaining_leaves/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2024 Janik von Rotz <[email protected]>
# Copyright 2024 Camptocamp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "HR Holidays Remaining Leaves",
"summary": """
Show remaining leaves per employee in allocation overview.
""",
"author": "Mint System GmbH, Camptocamp, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/hr-holidays",
"category": "Human Resources",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"depends": ["hr_holidays"],
"data": ["views/hr_leave_allocation.xml"],
"installable": True,
"application": False,
"auto_install": False,
"images": ["images/screen.png"],
}
65 changes: 65 additions & 0 deletions hr_holidays_remaining_leaves/i18n/de.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * hr_holidays_remaining_leaves
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-03-08 09:45+0000\n"
"PO-Revision-Date: 2023-03-08 09:45+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: hr_holidays_remaining_leaves
#: model:ir.model.fields,field_description:hr_holidays_remaining_leaves.field_hr_leave_allocation__remaining_leaves_current_display
msgid "Current Remaining"
msgstr "Aktuell Verbleibend"

#. module: hr_holidays_remaining_leaves
#: model:ir.model.fields,field_description:hr_holidays_remaining_leaves.field_hr_leave_allocation__remaining_leaves_display
msgid "Remaining"
msgstr "Verbleibend"

#. module: hr_holidays_remaining_leaves
#: model:ir.model.fields,field_description:hr_holidays_remaining_leaves.field_hr_leave_allocation__remaining_leaves_current_days
msgid "Remaining Leaves Current Days"
msgstr ""

#. module: hr_holidays_remaining_leaves
#: model:ir.model.fields,field_description:hr_holidays_remaining_leaves.field_hr_leave_allocation__remaining_leaves_current_hours
msgid "Remaining Leaves Current Hours"
msgstr ""

#. module: hr_holidays_remaining_leaves
#: model:ir.model.fields,field_description:hr_holidays_remaining_leaves.field_hr_leave_allocation__remaining_leaves_days
msgid "Remaining Leaves Days"
msgstr ""

#. module: hr_holidays_remaining_leaves
#: model:ir.model.fields,field_description:hr_holidays_remaining_leaves.field_hr_leave_allocation__remaining_leaves_hours
msgid "Remaining Leaves Hours"
msgstr ""

#. module: hr_holidays_remaining_leaves
#: model:ir.model,name:hr_holidays_remaining_leaves.model_hr_leave_allocation
msgid "Time Off Allocation"
msgstr "Zuweisung Abwesenheit"

#. module: hr_holidays_remaining_leaves
#: code:addons/hr_holidays_remaining_leaves/models/hr_leave.py:0
#: code:addons/hr_holidays_remaining_leaves/models/hr_leave.py:0
#, python-format
msgid "days"
msgstr ""

#. module: hr_holidays_remaining_leaves
#: code:addons/hr_holidays_remaining_leaves/models/hr_leave.py:0
#: code:addons/hr_holidays_remaining_leaves/models/hr_leave.py:0
#, python-format
msgid "hours"
msgstr ""
65 changes: 65 additions & 0 deletions hr_holidays_remaining_leaves/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * hr_holidays_remaining_leaves
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-03-08 09:48+0000\n"
"PO-Revision-Date: 2023-03-08 09:48+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: hr_holidays_remaining_leaves
#: model:ir.model.fields,field_description:hr_holidays_remaining_leaves.field_hr_leave_allocation__remaining_leaves_current_display
msgid "Current Remaining"
msgstr "Actuel Restant"

#. module: hr_holidays_remaining_leaves
#: model:ir.model.fields,field_description:hr_holidays_remaining_leaves.field_hr_leave_allocation__remaining_leaves_display
msgid "Remaining"
msgstr "Restant"

#. module: hr_holidays_remaining_leaves
#: model:ir.model.fields,field_description:hr_holidays_remaining_leaves.field_hr_leave_allocation__remaining_leaves_current_days
msgid "Remaining Leaves Current Days"
msgstr ""

#. module: hr_holidays_remaining_leaves
#: model:ir.model.fields,field_description:hr_holidays_remaining_leaves.field_hr_leave_allocation__remaining_leaves_current_hours
msgid "Remaining Leaves Current Hours"
msgstr ""

#. module: hr_holidays_remaining_leaves
#: model:ir.model.fields,field_description:hr_holidays_remaining_leaves.field_hr_leave_allocation__remaining_leaves_days
msgid "Remaining Leaves Days"
msgstr ""

#. module: hr_holidays_remaining_leaves
#: model:ir.model.fields,field_description:hr_holidays_remaining_leaves.field_hr_leave_allocation__remaining_leaves_hours
msgid "Remaining Leaves Hours"
msgstr ""

#. module: hr_holidays_remaining_leaves
#: model:ir.model,name:hr_holidays_remaining_leaves.model_hr_leave_allocation
msgid "Time Off Allocation"
msgstr ""

#. module: hr_holidays_remaining_leaves
#: code:addons/hr_holidays_remaining_leaves/models/hr_leave.py:0
#: code:addons/hr_holidays_remaining_leaves/models/hr_leave.py:0
#, python-format
msgid "days"
msgstr ""

#. module: hr_holidays_remaining_leaves
#: code:addons/hr_holidays_remaining_leaves/models/hr_leave.py:0
#: code:addons/hr_holidays_remaining_leaves/models/hr_leave.py:0
#, python-format
msgid "hours"
msgstr ""
Binary file added hr_holidays_remaining_leaves/images/screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions hr_holidays_remaining_leaves/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import hr_leave
92 changes: 92 additions & 0 deletions hr_holidays_remaining_leaves/models/hr_leave.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Copyright 2024 Janik von Rotz <[email protected]>
# Copyright 2024 Camptocamp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging

from odoo import _, fields, models
from odoo.tools.float_utils import float_round

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

_logger = logging.getLogger(__name__)


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

remaining_leaves_hours = fields.Float(compute="_compute_remaining_leaves")
remaining_leaves_days = fields.Float(compute="_compute_remaining_leaves")
remaining_leaves_display = fields.Char(
"Remaining", compute="_compute_remaining_leaves_display"
)
remaining_leaves_current_hours = fields.Float(compute="_compute_remaining_leaves")
remaining_leaves_current_days = fields.Float(compute="_compute_remaining_leaves")
remaining_leaves_current_display = fields.Char(
"Current Remaining", compute="_compute_remaining_leaves_display"
)

def _get_number_of_days_and_hours(self, date_from, date_to, employee_id):
employee = self.env["hr.employee"].browse(employee_id)
domain = [
(
"company_id",
"in",
self.env.company.ids + self.env.context.get("allowed_company_ids", []),
)
]
return employee._get_work_days_data_batch(
date_from, date_to, domain=domain, compute_leaves=False
)[employee.id]

def _compute_remaining_leaves(self):
all_consumed_leaves = self.employee_id._get_consumed_leaves(
self.holiday_status_id
)[0]
all_consumed_leaves_current = self.employee_id._get_consumed_leaves(
self.holiday_status_id, ignore_future=True
)[0]
for allocation in self:
consumes_allo = all_consumed_leaves[allocation.employee_id][
allocation.holiday_status_id
][allocation]
consumes_allo_current = all_consumed_leaves_current[allocation.employee_id][
allocation.holiday_status_id
][allocation]
allocation_calendar = (
allocation.holiday_status_id.company_id.resource_calendar_id
)
if allocation.holiday_type == "employee" and allocation.employee_id:
allocation_calendar = allocation.employee_id.sudo().resource_calendar_id
allocation.remaining_leaves_days = consumes_allo["remaining_leaves"]
allocation.remaining_leaves_hours = consumes_allo["remaining_leaves"] * (
allocation_calendar.hours_per_day or HOURS_PER_DAY
)
allocation.remaining_leaves_current_days = consumes_allo_current[
"remaining_leaves"
]
allocation.remaining_leaves_current_hours = consumes_allo_current[
"remaining_leaves"
] * (allocation_calendar.hours_per_day or HOURS_PER_DAY)

def _compute_remaining_leaves_display(self):
for allocation in self:
allocation.remaining_leaves_display = "{} {}".format(
float_round(allocation.remaining_leaves_hours, precision_digits=2)
if allocation.type_request_unit == "hour"
else float_round(allocation.remaining_leaves_days, precision_digits=2),
_("hours") if allocation.type_request_unit == "hour" else _("days"),
)

allocation.remaining_leaves_current_display = "{} {}".format(
(
float_round(
allocation.remaining_leaves_current_hours,
precision_digits=2,
)
if allocation.type_request_unit == "hour"
else float_round(
allocation.remaining_leaves_current_days, precision_digits=2
)
),
_("hours") if allocation.type_request_unit == "hour" else _("days"),
)
3 changes: 3 additions & 0 deletions hr_holidays_remaining_leaves/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_holidays_remaining_leaves/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Janik von Rotz <[email protected]>
* Son Ho <[email protected]>
5 changes: 5 additions & 0 deletions hr_holidays_remaining_leaves/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

The original development of this module has been done by Mint System.
It can be found in: https://github.com/Mint-System/Odoo-Apps-HR/tree/16.0/hr_holidays_remaining_leaves

This module has been ported to the OCA with their agreement.
1 change: 1 addition & 0 deletions hr_holidays_remaining_leaves/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Show remaining leaves per employee in allocation overview.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions hr_holidays_remaining_leaves/static/description/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body><a href="http://www.gnu.org/licenses/gpl-3.0-standalone.html">
<img alt="License: GPL-3" src="https://img.shields.io/badge/licence-GPL--3-blue.svg" />
</a>
<section id="hr-holidays-remaining-leaves">
<h1>HR Holidays Remaining Leaves</h1>
<p>Show remaining leaves per employee in allocation overview.</p>
<p>For a detailed documentation have a look at <a href="https://www.odoo-wiki.org/">https://www.odoo-wiki.org/</a>.</p>
<img height="100" width="100" alt="Icon" src="https://raw.githubusercontent.com/Mint-System/Wiki/master/assets/icon-box.png" />
<section id="configuration">
<h2>Configuration</h2>
<ul>
<li>No additional configurations needed</li>
</ul>
<section id="maintainer">
<h3>Maintainer</h3>
<a href="https://www.mint-system.ch">
<img src="https://raw.githubusercontent.com/Mint-System/Wiki/master/assets/mint-system-logo.png" alt="" />
</a>
<p>This module is maintained by Mint System GmbH.</p>
<p>For support and more information, please visit <a href="https://www.mint-system.ch">our Website</a>.</p>
</section>
</section>
</section>
</body>
</html>
1 change: 1 addition & 0 deletions hr_holidays_remaining_leaves/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_hr_holidays_remaining_leaves
Loading
Loading