Skip to content

Commit

Permalink
[MIG]hr_attendance_hour_type_report: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
adasatorres committed Dec 31, 2024
1 parent 652d7da commit 0dc9c7a
Show file tree
Hide file tree
Showing 13 changed files with 328 additions and 47 deletions.
21 changes: 16 additions & 5 deletions hr_attendance_hour_type_report/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ HR Attendance hours report
: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/14.0/hr_attendance_hour_type_report
:target: https://github.com/OCA/hr-attendance/tree/16.0/hr_attendance_hour_type_report
: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-14-0/hr-attendance-14-0-hr_attendance_hour_type_report
:target: https://translation.odoo-community.org/projects/hr-attendance-16-0/hr-attendance-16-0-hr_attendance_hour_type_report
: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=14.0
: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|
Expand All @@ -38,6 +38,8 @@ The information of a day being a holiday comes from the configured public holida

This is meant as a helper for people interacting with external payroll systems.

Also, add the option to view overtime hours in the report and weigh nighttime and overtime hours.

**Table of contents**

.. contents::
Expand All @@ -52,6 +54,8 @@ hour at which the night worktime starts and ends. The default is from 10pm to

These hours are expressed in the employee's time zone.

In the attendance settings, there are two options to enable weighting.

Usage
=====

Expand All @@ -61,6 +65,9 @@ Go to Attendances -> Attendances for Payroll, you will see a list view or a pivo
* date type (normal, sunday or holiday)
* daytime work duration
* nighttime work duration
* overtime work duration
* weighting nighttime work duration
* weighting overtime work duration
* total work duration

The list view and pivot view can be exported to a spreadsheet for further processing.
Expand All @@ -71,7 +78,7 @@ 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_hour_type_report%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/hr-attendance/issues/new?body=module:%20hr_attendance_hour_type_report%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.

Expand All @@ -88,6 +95,10 @@ Contributors

* Alexandre Fayolle <[email protected]>

* `Binhex <https://binhex.cloud>`_:

* Adasat Torres de León <[email protected]>

Maintainers
~~~~~~~~~~~

Expand All @@ -101,6 +112,6 @@ 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/14.0/hr_attendance_hour_type_report>`_ project on GitHub.
This module is part of the `OCA/hr-attendance <https://github.com/OCA/hr-attendance/tree/16.0/hr_attendance_hour_type_report>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion hr_attendance_hour_type_report/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "HR Attendance hours report",
"version": "14.0.1.0.0",
"version": "16.0.1.0.0",
"category": "Human Resources",
"website": "https://github.com/OCA/hr-attendance",
"author": "Camptocamp, Odoo Community Association (OCA)",
Expand Down
80 changes: 70 additions & 10 deletions hr_attendance_hour_type_report/models/hr_attendance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2021 Camptocamp SA
# Copyright 2024 Binhex - Adasat Torres de León
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import datetime as dt
import logging
Expand All @@ -22,8 +23,15 @@ class HrAttendance(models.Model):
store=True,
readonly=True,
)

worked_hours_overtime = fields.Float(
string="Overtime hours",
compute="_compute_worked_hours",
store=True,
readonly=True,
)

date = fields.Date(
string="Date",
help="date of the attendance, from the payroll point of view",
compute="_compute_date",
store=True,
Expand All @@ -34,6 +42,44 @@ class HrAttendance(models.Model):
store=True,
)

company_id = fields.Many2one(
comodel_name="res.company",
default=lambda self: self.env.company,
)

hr_attendance_overtime = fields.Boolean(related="company_id.hr_attendance_overtime")

allow_weighting_nighttime_hours = fields.Boolean(
related="company_id.allow_weighting_nighttime_hours"
)

allow_weighting_overtime_hours = fields.Boolean(
related="company_id.allow_weighting_overtime_hours"
)

weighting_worked_nighttime_hours = fields.Float(
compute="_compute_weighting_hours",
store=True,
)
weighting_worked_overtime_hours = fields.Float(
compute="_compute_weighting_hours",
store=True,
)

@api.depends(
"company_id.weighting_nighttime_hours", "company_id.weighting_overtime_hours"
)
def _compute_weighting_hours(self):
for rec in self:
nighttime_hours = rec.worked_hours_nighttime
overtime_hours = rec.worked_hours_overtime
if rec.allow_weighting_nighttime_hours:
nighttime_hours *= rec.company_id.weighting_nighttime_hours
if rec.allow_weighting_overtime_hours:
overtime_hours *= rec.company_id.weighting_overtime_hours
rec.weighting_worked_nighttime_hours = nighttime_hours
rec.weighting_worked_overtime_hours = overtime_hours

@api.depends("date")
def _compute_date_type(self):
for rec in self:
Expand All @@ -48,20 +94,21 @@ def _compute_date_type(self):

@api.depends("check_in")
def _compute_date(self):
UTC = pytz.timezone("utc")
for rec in self:
TZ = pytz.timezone(rec.employee_id.tz)
tz = rec.employee_id.tz
check_in = rec.check_in
if not check_in.tzinfo:
check_in = UTC.localize(check_in)
check_in = TZ.localize(check_in)
check_in_tz = check_in.astimezone(pytz.timezone(tz))
rec.date = check_in_tz.date()

@api.depends("check_in", "check_out")
def _compute_worked_hours(self):
super()._compute_worked_hours()
UTC = pytz.timezone("utc")

for rec in self:
TZ = pytz.timezone(rec.employee_id.tz)
rec.worked_hours_nighttime = 0
rec.worked_hours_daytime = 0
if not rec.check_out:
Expand All @@ -77,30 +124,30 @@ def _compute_worked_hours(self):
hour_night_end = int(night_end)
minute_night_end = int(60 * (night_end - hour_night_end))
tz = pytz.timezone(rec.employee_id.tz)
check_in = UTC.localize(rec.check_in)
check_out = UTC.localize(rec.check_out)
check_in = TZ.localize(rec.check_in)
check_out = TZ.localize(rec.check_out)
curr_day_night_start = tz.localize(
dt.datetime.combine(
rec.date, dt.time(hour=hour_night_start, minute=minute_night_start)
)
).astimezone(UTC)
).astimezone(TZ)
curr_day_night_end = tz.localize(
dt.datetime.combine(
rec.date, dt.time(hour=hour_night_end, minute=minute_night_end)
)
).astimezone(UTC)
).astimezone(TZ)
next_day_night_start = tz.localize(
dt.datetime.combine(
rec.date + dt.timedelta(days=1),
dt.time(hour=hour_night_start, minute=minute_night_start),
)
).astimezone(UTC)
).astimezone(TZ)
next_day_night_end = tz.localize(
dt.datetime.combine(
rec.date + dt.timedelta(days=1),
dt.time(hour=hour_night_end, minute=minute_night_end),
)
).astimezone(UTC)
).astimezone(TZ)
rec.worked_hours_nighttime += (
min(check_out, curr_day_night_end) - min(curr_day_night_end, check_in)
).total_seconds() / 3600.0
Expand All @@ -115,3 +162,16 @@ def _compute_worked_hours(self):
if check_out > next_day_night_start:
_logger.warning("very long_shift for employee %s" % rec.employee_id.id)

Check warning on line 163 in hr_attendance_hour_type_report/models/hr_attendance.py

View check run for this annotation

Codecov / codecov/patch

hr_attendance_hour_type_report/models/hr_attendance.py#L163

Added line #L163 was not covered by tests
rec.worked_hours_daytime = rec.worked_hours - rec.worked_hours_nighttime
if (
rec.hr_attendance_overtime
and rec.employee_id.resource_calendar_id
and rec.worked_hours
> rec.employee_id.resource_calendar_id.hours_per_day
):
rec.worked_hours_overtime = (
rec.worked_hours
- rec.employee_id.resource_calendar_id.hours_per_day
)
else:
rec.worked_hours_overtime = 0
return
18 changes: 18 additions & 0 deletions hr_attendance_hour_type_report/models/res_company.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2021 Camptocamp SA
# Copyright 2024 Binhex - Adasat Torres de León
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models

Expand All @@ -12,3 +13,20 @@ class ResCompany(models.Model):
hr_night_work_hour_end = fields.Float(
"End of night work time", default=6, help="expressed in company timezone"
)

allow_weighting_nighttime_hours = fields.Boolean(
string="Allow weighting of nighttime hours."
)

allow_weighting_overtime_hours = fields.Boolean(
string="Allow weighting of overtime hours."
)

weighting_nighttime_hours = fields.Float(
string="Weighting of nighttime hours.",
default=1.00,
)

weighting_overtime_hours = fields.Float(
string="Weighting of overtime hours.", default=1.00
)
25 changes: 25 additions & 0 deletions hr_attendance_hour_type_report/models/res_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2021 Camptocamp SA
# Copyright 2024 Binhex - Adasat Torres de León
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models

Expand All @@ -12,3 +13,27 @@ class ResConfigSettings(models.TransientModel):
hr_night_work_hour_end = fields.Float(
related="company_id.hr_night_work_hour_end", readonly=False
)

allow_weighting_nighttime_hours = fields.Boolean(
string="Allow weighting of nighttime hours.",
related="company_id.allow_weighting_nighttime_hours",
readonly=False,
)

allow_weighting_overtime_hours = fields.Boolean(
string="Allow weighting of overtime hours.",
related="company_id.allow_weighting_overtime_hours",
readonly=False,
)

weighting_nighttime_hours = fields.Float(
string="Weighting of nighttime hours.",
related="company_id.weighting_nighttime_hours",
readonly=False,
)

weighting_overtime_hours = fields.Float(
string="Weighting of overtime hours.",
related="company_id.weighting_overtime_hours",
readonly=False,
)
2 changes: 2 additions & 0 deletions hr_attendance_hour_type_report/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ hour at which the night worktime starts and ends. The default is from 10pm to
6am.

These hours are expressed in the employee's time zone.

In the attendance settings, there are two options to enable weighting.
4 changes: 4 additions & 0 deletions hr_attendance_hour_type_report/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
* Alexandre Fayolle <[email protected]>

* `Binhex <https://binhex.cloud>`_:

* Adasat Torres de León <[email protected]>
2 changes: 2 additions & 0 deletions hr_attendance_hour_type_report/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ the following categories:
The information of a day being a holiday comes from the configured public holidays from the module hr_holidays_public.

This is meant as a helper for people interacting with external payroll systems.

Also, add the option to view overtime hours in the report and weigh nighttime and overtime hours.
3 changes: 3 additions & 0 deletions hr_attendance_hour_type_report/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Go to Attendances -> Attendances for Payroll, you will see a list view or a pivo
* date type (normal, sunday or holiday)
* daytime work duration
* nighttime work duration
* overtime work duration
* weighting nighttime work duration
* weighting overtime work duration
* total work duration

The list view and pivot view can be exported to a spreadsheet for further processing.
16 changes: 12 additions & 4 deletions hr_attendance_hour_type_report/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -369,7 +368,7 @@ <h1 class="title">HR Attendance hours report</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:ce99258fcffd837ed56010390e15c1865cb4ec2585299cfac06d8d5acd4aaef0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/hr-attendance/tree/14.0/hr_attendance_hour_type_report"><img alt="OCA/hr-attendance" src="https://img.shields.io/badge/github-OCA%2Fhr--attendance-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/hr-attendance-14-0/hr-attendance-14-0-hr_attendance_hour_type_report"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/hr-attendance&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/hr-attendance/tree/16.0/hr_attendance_hour_type_report"><img alt="OCA/hr-attendance" src="https://img.shields.io/badge/github-OCA%2Fhr--attendance-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/hr-attendance-16-0/hr-attendance-16-0-hr_attendance_hour_type_report"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/hr-attendance&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module provides a new report in hr_attendance to display the worked time of employees split in
the following categories:</p>
<ul class="simple">
Expand All @@ -378,6 +377,7 @@ <h1 class="title">HR Attendance hours report</h1>
</ul>
<p>The information of a day being a holiday comes from the configured public holidays from the module hr_holidays_public.</p>
<p>This is meant as a helper for people interacting with external payroll systems.</p>
<p>Also, add the option to view overtime hours in the report and weigh nighttime and overtime hours.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand All @@ -398,6 +398,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
hour at which the night worktime starts and ends. The default is from 10pm to
6am.</p>
<p>These hours are expressed in the employee’s time zone.</p>
<p>In the attendance settings, there are two options to enable weighting.</p>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
Expand All @@ -407,6 +408,9 @@ <h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<li>date type (normal, sunday or holiday)</li>
<li>daytime work duration</li>
<li>nighttime work duration</li>
<li>overtime work duration</li>
<li>weighting nighttime work duration</li>
<li>weighting overtime work duration</li>
<li>total work duration</li>
</ul>
<p>The list view and pivot view can be exported to a spreadsheet for further processing.</p>
Expand All @@ -416,7 +420,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/hr-attendance/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/hr-attendance/issues/new?body=module:%20hr_attendance_hour_type_report%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/hr-attendance/issues/new?body=module:%20hr_attendance_hour_type_report%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -431,6 +435,10 @@ <h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple">
<li>Alexandre Fayolle &lt;<a class="reference external" href="mailto:alexandre.fayolle&#64;camptocamp.com">alexandre.fayolle&#64;camptocamp.com</a>&gt;</li>
<li><a class="reference external" href="https://binhex.cloud">Binhex</a>:<ul>
<li>Adasat Torres de León &lt;<a class="reference external" href="mailto:a.torres&#64;binhex.cloud">a.torres&#64;binhex.cloud</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -440,7 +448,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/hr-attendance/tree/14.0/hr_attendance_hour_type_report">OCA/hr-attendance</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/hr-attendance/tree/16.0/hr_attendance_hour_type_report">OCA/hr-attendance</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Loading

0 comments on commit 0dc9c7a

Please sign in to comment.