-
-
Notifications
You must be signed in to change notification settings - Fork 118
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_leave_dashboard_extra_time #177
Open
xaviedoanhduy
wants to merge
5
commits into
OCA:17.0
Choose a base branch
from
xaviedoanhduy:17.0-mig-hr_attendance_overtime_negative_hours
base: 17.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cb284e7
[hr_attendance_overtime_negative_hours] init
c900c0d
update linting config files
janikvonrotz 1ea250d
[IMP] hr_attendance_overtime_negative_hours: pre-commit auto fixes
xaviedoanhduy 267c30c
[MIG] hr_attendance_overtime_negative_hours: Migration to 17.0
xaviedoanhduy 3257f11
[MOV] hr_attendance_overtime_nagative_hours: rename to hr_leave_dashb…
xaviedoanhduy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,89 @@ | ||
============================= | ||
HR Leave Dashboard Extra Time | ||
============================= | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:2c90bc9e12f014d49678e4e4a81f627ba6965799a6fc44915f10fb0c1bb1539a | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
||
.. |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/17.0/hr_leave_dashboard_extra_time | ||
: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_leave_dashboard_extra_time | ||
: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| | ||
|
||
Display an additional card at the top of the Time Off Dashboard: Extra | ||
Hours, informing the employee about the number of extra hours he has | ||
been working and thus the number of hours available for him to take as a | ||
compensation leave. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
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_leave_dashboard_extra_time%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 | ||
|
||
Contributors | ||
------------ | ||
|
||
- Janik von Rotz [email protected] | ||
- Do Anh Duy [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/blob/15.0/hr_attendance_overtime_negative_hours | ||
|
||
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-attendance <https://github.com/OCA/hr-attendance/tree/17.0/hr_leave_dashboard_extra_time>`_ 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,22 @@ | ||
# Copyright 2023 Janik von Rotz <[email protected]> | ||
# Copyright 2024 Camptocamp | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
{ | ||
"name": "HR Leave Dashboard Extra Time", | ||
"summary": """ | ||
Display an additional card at the top of the Time Off Dashboard: | ||
Extra Hours, informing the employee about the number of extra hours | ||
he has been working and thus the number of hours available | ||
for him to take as a compensation leave | ||
""", | ||
"author": "Mint System GmbH, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/hr-attendance", | ||
"category": "Human Resources", | ||
"version": "17.0.1.0.0", | ||
"license": "AGPL-3", | ||
"depends": ["hr_holidays_attendance"], | ||
"installable": True, | ||
"application": False, | ||
"auto_install": False, | ||
"images": ["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.
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 hr_leave_type |
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,170 @@ | ||
# Copyright 2023 Janik von Rotz <[email protected]> | ||
# Copyright 2024 Camptocamp | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from datetime import datetime, time | ||
|
||
import pytz | ||
|
||
from odoo import api, fields, models | ||
from odoo.tools import format_date | ||
|
||
|
||
class HrLeaveType(models.Model): | ||
_inherit = "hr.leave.type" | ||
|
||
@api.model | ||
def get_allocation_data_request(self, target_date=None): | ||
"""Always include the extra hours leave type in the allocation data.""" | ||
extra_hours_time_off_type = self.env.ref( | ||
"hr_holidays_attendance.holiday_status_extra_hours", | ||
raise_if_not_found=False, | ||
) | ||
|
||
allocation_data = super().get_allocation_data_request(target_date) | ||
|
||
extra_hours_in_data = any( | ||
leave_type[3] == extra_hours_time_off_type.id | ||
for leave_type in allocation_data | ||
) | ||
|
||
if extra_hours_time_off_type and not extra_hours_in_data: | ||
employee = extra_hours_time_off_type.env[ | ||
"hr.employee" | ||
]._get_contextual_employee() | ||
extra_hours_data = extra_hours_time_off_type._prepare_extra_hours_data( | ||
employee, target_date | ||
) | ||
allocation_data.append(extra_hours_data) | ||
return allocation_data | ||
|
||
def _prepare_lt_info_detail(self): | ||
return { | ||
"remaining_leaves": 0, | ||
"virtual_remaining_leaves": 0, | ||
"max_leaves": 0, | ||
"accrual_bonus": 0, | ||
"leaves_taken": 0, | ||
"virtual_leaves_taken": 0, | ||
"leaves_requested": 0, | ||
"leaves_approved": 0, | ||
"closest_allocation_remaining": 0, | ||
"closest_allocation_expire": False, | ||
"holds_changes": False, | ||
"total_virtual_excess": 0, | ||
"virtual_excess_data": {}, | ||
"exceeding_duration": 0, | ||
"request_unit": self.request_unit, | ||
"icon": self.sudo().icon_id.url, | ||
"allows_negative": self.allows_negative, | ||
"max_allowed_negative": self.max_allowed_negative, | ||
} | ||
|
||
def _prepare_extra_hours_data(self, employee, target_date): | ||
if target_date and isinstance(target_date, str): | ||
target_date = datetime.fromisoformat(target_date).date() | ||
elif target_date and isinstance(target_date, datetime): | ||
target_date = target_date.date() | ||
elif not target_date: | ||
target_date = fields.Date.today() | ||
allocations_leaves_consumed, extra_data = employee.with_context( | ||
ignored_leave_ids=self.env.context.get("ignored_leave_ids") | ||
)._get_consumed_leaves(self, target_date) | ||
lt_info = self._prepare_lt_info_detail() | ||
lt_info["exceeding_duration"] = extra_data[employee][self]["exceeding_duration"] | ||
for excess_date, excess_days in extra_data[employee][self][ | ||
"excess_days" | ||
].items(): | ||
amount = excess_days["amount"] | ||
lt_info["virtual_excess_data"][ | ||
excess_date.strftime("%Y-%m-%d") | ||
] = excess_days | ||
lt_info["total_virtual_excess"] += amount | ||
if not self.allows_negative: | ||
continue | ||
lt_info["virtual_leaves_taken"] += amount | ||
lt_info["virtual_remaining_leaves"] -= amount | ||
if excess_days["is_virtual"]: | ||
lt_info["leaves_requested"] += amount | ||
else: | ||
lt_info["leaves_approved"] += amount | ||
lt_info["leaves_taken"] += amount | ||
lt_info["remaining_leaves"] -= amount | ||
allocations_now = self.env["hr.leave.allocation"] | ||
allocations_date = self.env["hr.leave.allocation"] | ||
allocations_with_remaining_leaves = self.env["hr.leave.allocation"] | ||
today = fields.Date.today() | ||
for allocation, data in allocations_leaves_consumed[employee][self].items(): | ||
if allocation: | ||
if allocation.date_from <= today and ( | ||
not allocation.date_to or allocation.date_to >= today | ||
): | ||
allocations_now |= allocation | ||
if allocation.date_from <= target_date and ( | ||
not allocation.date_to or allocation.date_to >= target_date | ||
): | ||
allocations_date |= allocation | ||
if allocation.date_from > target_date: | ||
continue | ||
if allocation.date_to and allocation.date_to < target_date: | ||
continue | ||
lt_info["remaining_leaves"] += data["remaining_leaves"] | ||
lt_info["virtual_remaining_leaves"] += data["virtual_remaining_leaves"] | ||
lt_info["max_leaves"] += data["max_leaves"] | ||
lt_info["accrual_bonus"] += data["accrual_bonus"] | ||
lt_info["leaves_taken"] += data["leaves_taken"] | ||
lt_info["virtual_leaves_taken"] += data["virtual_leaves_taken"] | ||
lt_info["leaves_requested"] += ( | ||
data["virtual_leaves_taken"] - data["leaves_taken"] | ||
) | ||
lt_info["leaves_approved"] += data["leaves_taken"] | ||
if data["virtual_remaining_leaves"] > 0: | ||
allocations_with_remaining_leaves |= allocation | ||
closest_allocation = ( | ||
allocations_with_remaining_leaves[0] | ||
if allocations_with_remaining_leaves | ||
else self.env["hr.leave.allocation"] | ||
) | ||
closest_allocations = allocations_with_remaining_leaves.filtered( | ||
lambda ca: ca.date_to == closest_allocation.date_to | ||
) | ||
closest_allocation_remaining = sum( | ||
allocations_leaves_consumed[employee][self][ca]["virtual_remaining_leaves"] | ||
for ca in closest_allocations | ||
) | ||
if closest_allocation.date_to: | ||
closest_allocation_expire = format_date( | ||
self.env, closest_allocation.date_to | ||
) | ||
calendar = ( | ||
employee.resource_calendar_id | ||
or employee.company_id.resource_calendar_id | ||
) | ||
closest_allocation_duration = ( | ||
calendar._attendance_intervals_batch( | ||
datetime.combine(closest_allocation.date_to, time.min).replace( | ||
tzinfo=pytz.UTC | ||
), | ||
datetime.combine(target_date, time.max).replace(tzinfo=pytz.UTC), | ||
) | ||
if self.request_unit == "hour" | ||
else (closest_allocation.date_to - target_date).days + 1 | ||
) | ||
else: | ||
closest_allocation_expire = False | ||
closest_allocation_duration = False | ||
holds_changes = ( | ||
lt_info["accrual_bonus"] > 0 | ||
or bool(allocations_date - allocations_now) | ||
or bool(allocations_now - allocations_date) | ||
) and target_date != fields.Date.today() | ||
|
||
lt_info.update( | ||
{ | ||
"closest_allocation_remaining": closest_allocation_remaining, | ||
"closest_allocation_expire": closest_allocation_expire, | ||
"closest_allocation_duration": closest_allocation_duration, | ||
"holds_changes": holds_changes, | ||
} | ||
) | ||
return self.name, lt_info, self.requires_allocation, self.id |
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,3 @@ | ||
[build-system] | ||
requires = ["whool"] | ||
build-backend = "whool.buildapi" |
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,2 @@ | ||
* Janik von Rotz <[email protected]> | ||
* Do Anh Duy <[email protected]> |
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,4 @@ | ||
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/blob/15.0/hr_attendance_overtime_negative_hours | ||
|
||
This module has been ported to the OCA with their agreement. |
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 @@ | ||
Display an additional card at the top of the Time Off Dashboard: Extra Hours, informing the employee about the number of extra hours he has been working and thus the number of hours available for him to take as a compensation leave. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this image. Its our default background image for the Odoo app store.