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_attendance_overtime_hours #175

Open
wants to merge 6 commits into
base: 17.0
Choose a base branch
from
Open
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
86 changes: 86 additions & 0 deletions hr_attendance_overtime_hours/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
============================
HR Attendance Overtime Hours
============================

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

.. |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_attendance_overtime_hours
: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_attendance_overtime_hours
: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|

Add Planned Hours/Worked Hours columns to the Overtime list view

**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_attendance_overtime_hours%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_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_attendance_overtime_hours>`_ 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_attendance_overtime_hours/__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_attendance_overtime_hours/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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 Attendance Overtime Hours",
"summary": """
Show planned and worked hours in overtime view.
""",
"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_attendance"],
"data": ["views/hr_attendance_overtime.xml"],
"installable": True,
"application": False,
"auto_install": False,
"images": ["images/screen.png"],
}
31 changes: 31 additions & 0 deletions hr_attendance_overtime_hours/i18n/de.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * hr_attendance_overtime_hours
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-03-14 16:59+0000\n"
"PO-Revision-Date: 2023-03-14 16:59+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_attendance_overtime_hours
#: model:ir.model,name:hr_attendance_overtime_hours.model_hr_attendance_overtime
msgid "Attendance Overtime"
msgstr "Anwesenheit Überstunden"

#. module: hr_attendance_overtime_hours
#: model:ir.model.fields,field_description:hr_attendance_overtime_hours.field_hr_attendance_overtime__planned_hours
msgid "Planned Hours"
msgstr "Geplante Stunden"

#. module: hr_attendance_overtime_hours
#: model:ir.model.fields,field_description:hr_attendance_overtime_hours.field_hr_attendance_overtime__worked_hours
msgid "Worked Hours"
msgstr "Gearbeitete Stunden"
Binary file added hr_attendance_overtime_hours/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_attendance_overtime_hours/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import hr_attendance_overtime
65 changes: 65 additions & 0 deletions hr_attendance_overtime_hours/models/hr_attendance_overtime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 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

from odoo import api, fields, models


class HrAttendanceOvertime(models.Model):
_inherit = "hr.attendance.overtime"

planned_hours = fields.Float(compute="_compute_planned_hours", store=True)
worked_hours = fields.Float(compute="_compute_worked_hours", store=True)

@api.depends("date")
def _compute_planned_hours(self):
for overtime in self:
# Get work hours from calendar
planned_hours = (
overtime.employee_id.resource_calendar_id.get_work_hours_count(
datetime.combine(overtime.date, time.min),
datetime.combine(overtime.date, time.max),
True,
)
)
overtime.planned_hours = planned_hours

@api.depends("duration")
def _compute_worked_hours(self):
for overtime in self:
# Convert to UTC
(
datetime_check_in,
datetime_check_out,
) = overtime.convert_check_in_check_out_to_utc(overtime.date)
# Get sum of attendance entries
attendance_ids = overtime.env["hr.attendance"].search(
[
("employee_id", "=", overtime.employee_id.id),
("check_in", ">=", datetime_check_in),
("check_out", "<=", datetime_check_out),
]
)
overtime.worked_hours = sum(attendance_ids.mapped("worked_hours"))

def convert_check_in_check_out_to_utc(self, date_to_convert):
tz = (
self.employee_id.resource_calendar_id.tz
or self.employee_id.tz
or self.env.user.tz
)
datetime_tz_check_in = datetime.combine(date_to_convert, time.min)
datetime_tz_check_out = datetime.combine(date_to_convert, time.max)
datetime_check_in = self._convert_str_to_datetime(datetime_tz_check_in, tz)
datetime_check_out = self._convert_str_to_datetime(datetime_tz_check_out, tz)
return datetime_check_in, datetime_check_out

def _convert_str_to_datetime(self, datetime_to_tz, tz):
return fields.Datetime.from_string(
self.env["ir.fields.converter"]
.with_context(tz=tz)
._str_to_datetime(None, None, datetime_to_tz.replace(tzinfo=None))[0]
)
3 changes: 3 additions & 0 deletions hr_attendance_overtime_hours/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_attendance_overtime_hours/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Janik von Rotz <[email protected]>
* Do Anh Duy <[email protected]>
4 changes: 4 additions & 0 deletions hr_attendance_overtime_hours/readme/CREDITS.md
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_hours

This module has been ported to the OCA with their agreement.
1 change: 1 addition & 0 deletions hr_attendance_overtime_hours/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add Planned Hours/Worked Hours columns to the Overtime list view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions hr_attendance_overtime_hours/static/description/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!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-attendance-overtime-hours">
<h1>HR Attendance Overtime Hours</h1>
<p>Show planned and worked hours in overtime view.</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="usage">
<h2>Usage</h2>
<p>Clone module into Odoo addon directory.</p>
<pre data-language="bash">git clone [email protected]:mint-system/odoo-app-hr-attendance-overtime-hours.git ./addons/hr_attendance_overtime_hours</pre>
</section>
<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_attendance_overtime_hours/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_hr_attendance_overtime
75 changes: 75 additions & 0 deletions hr_attendance_overtime_hours/tests/test_hr_attendance_overtime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# 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

from odoo import fields
from odoo.tests.common import TransactionCase


class TestHRAttendanceOvertime(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.calendar = cls.env["resource.calendar"].create(
{
"name": "Test Calendar",
"attendance_ids": [
(
0,
0,
{
"name": "Monday Morning",
"dayofweek": "0",
"hour_from": 8,
"hour_to": 12,
},
),
(
0,
0,
{
"name": "Monday Afternoon",
"dayofweek": "0",
"hour_from": 13,
"hour_to": 17,
},
),
],
}
)
cls.employee = cls.env["hr.employee"].create(
{
"name": "Test Employee",
"resource_calendar_id": cls.calendar.id,
}
)
cls.overtime = cls.env["hr.attendance.overtime"].create(
{
"employee_id": cls.employee.id,
"date": fields.Date.today(),
}
)

def test_compute_planned_hours(self):
self.overtime._compute_planned_hours()
self.assertEqual(self.overtime.planned_hours, 8.0)

def test_compute_worked_hours(self):
self.env["hr.attendance"].create(
[
{
"employee_id": self.employee.id,
"check_in": datetime.combine(self.overtime.date, time(8, 0)),
"check_out": datetime.combine(self.overtime.date, time(12, 0)),
},
{
"employee_id": self.employee.id,
"check_in": datetime.combine(self.overtime.date, time(13, 0)),
"check_out": datetime.combine(self.overtime.date, time(17, 0)),
},
]
)
self.overtime._compute_worked_hours()
self.assertEqual(self.overtime.worked_hours, 8.0)
18 changes: 18 additions & 0 deletions hr_attendance_overtime_hours/views/hr_attendance_overtime.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="view_attendance_overtime_tree" model="ir.ui.view">
<field
name="name"
>hr_attendance_overtime_hours.view_attendance_overtime_tree</field>
<field name="model">hr.attendance.overtime</field>
<field name="inherit_id" ref="hr_attendance.view_attendance_overtime_tree" />
<field name="arch" type="xml">
<field name="duration" position="before">
<field name="planned_hours" widget="float_time" />
<field name="worked_hours" widget="float_time" />
</field>
</field>
</record>

</odoo>
Loading