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

[16.0][ADD] hr_attendance_leave_report_rest: In "Attendances And Abse… #146

Open
wants to merge 1 commit into
base: 16.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
34 changes: 34 additions & 0 deletions hr_attendance_leave_report_rest/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

===============================
Hr attendance leave report rest
===============================

* In "Attendances And Absences" new field "rest_hours" with the sum of
attendances that are rest.
* If the rest time is longer than 15 minutes: hours worked = hours worked -
(rest time - 15 minutes).
* If the rest time is longer than 15 minutes: Non Remunerated Hours =
Non Remunerated Hours + (rest time - 15 minutes).


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

Bugs are tracked on `GitHub Issues
<https://github.com/avanzosc/hr-addons/issues>`_. In case of trouble,
please check there if your issue has already been reported. If you spotted
it first, help us smash it by providing detailed and welcomed feedback.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

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

* Ana Juaristi <anajuaristi@avanzosc.es>
* Alfredo de la Fuente <alfredodelafuente@avanzosc.es>
14 changes: 14 additions & 0 deletions hr_attendance_leave_report_rest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from . import models
from odoo import api, SUPERUSER_ID


def _post_install_put_dates_without_hour(cr, registry):
"""
This method will set the production cost on already done manufacturing orders.
"""
env = api.Environment(cr, SUPERUSER_ID, {})
admin_user = env.ref("base.user_admin")
env["hr.attendance"].with_user(admin_user)._put_dates_without_hour()
env["resource.calendar.leaves"].with_user(admin_user)._put_dates_without_hour()
env["hr.leave"].with_user(admin_user)._put_dates_without_hour()
env["hr.contract"].with_user(admin_user)._post_install_hr_leave_attendance()
13 changes: 13 additions & 0 deletions hr_attendance_leave_report_rest/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2025 Alfredo de la Fuente - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Hr Attendance Leave Report Rest",
"version": "16.0.1.0.0",
"category": "Human Resources/Attendances",
"license": "AGPL-3",
"author": "AvanzOSC",
"website": "https://github.com/avanzosc/hr-addons",
"depends": ["hr_attendance_leave_report", "hr_attendance_reason_rest"],
"data": ["views/hr_attendance_leave_views.xml"],
"installable": True,
}
31 changes: 31 additions & 0 deletions hr_attendance_leave_report_rest/i18n/es.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_leave_report_rest
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-02-24 13:48+0000\n"
"PO-Revision-Date: 2025-02-24 13: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_attendance_leave_report_rest
#: model:ir.model,name:hr_attendance_leave_report_rest.model_hr_attendance_leave
msgid "Attendances And Absences"
msgstr "Asistencias y ausencias"

#. module: hr_attendance_leave_report_rest
#: model:ir.model.fields,field_description:hr_attendance_leave_report_rest.field_hr_attendance_leave__rest_hours
msgid "Rest Hours"
msgstr "Horas descanso"

#. module: hr_attendance_leave_report_rest
#: model_terms:ir.ui.view,arch_db:hr_attendance_leave_report_rest.hr_attendance_leave_tree_view
msgid "Total Rest Hours"
msgstr "Total horas descanso"
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_leave_report_rest
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-02-24 13:47+0000\n"
"PO-Revision-Date: 2025-02-24 13:47+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_leave_report_rest
#: model:ir.model,name:hr_attendance_leave_report_rest.model_hr_attendance_leave
msgid "Attendances And Absences"
msgstr ""

#. module: hr_attendance_leave_report_rest
#: model:ir.model.fields,field_description:hr_attendance_leave_report_rest.field_hr_attendance_leave__rest_hours
msgid "Rest Hours"
msgstr ""

#. module: hr_attendance_leave_report_rest
#: model_terms:ir.ui.view,arch_db:hr_attendance_leave_report_rest.hr_attendance_leave_tree_view
msgid "Total Rest Hours"
msgstr ""
1 change: 1 addition & 0 deletions hr_attendance_leave_report_rest/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import hr_attendance_leave
59 changes: 59 additions & 0 deletions hr_attendance_leave_report_rest/models/hr_attendance_leave.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2025 Alfredo de la Fuente - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import fields, models


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

rest_hours = fields.Float(default=0.0, copy=False)

def _initialize_vals(self, employee, work_date):
contract, vals = super()._initialize_vals(employee, work_date)
rest_hours = self._catch_rest_hours_on_work_date(employee, work_date)
vals["rest_hours"] = rest_hours
if rest_hours > 0.25:
diff = rest_hours - 0.25
vals["worked_hours"] = vals.get("worked_hours") - diff
vals["extra_hours"] = vals.get("extra_hours") - diff
return contract, vals

def _catch_worked_hours_on_work_date(self, employee, work_date):
worked_attendances = self.env["hr.attendance"]
super()._catch_worked_hours_on_work_date(employee, work_date)
attendances = employee.attendance_ids.filtered(
lambda x: x.check_in_without_hour == work_date and x.check_out_without_hour
)
if not attendances:
return 0
for attendance in attendances:
if attendance.attendance_reason_ids and not any(
[x.is_rest for x in attendance.attendance_reason_ids]
):
worked_attendances += attendance
if not worked_attendances:
return 0
return sum(worked_attendances.mapped("worked_hours"))

def _catch_rest_hours_on_work_date(self, employee, work_date):
rest_attendances = self.env["hr.attendance"]
attendances = employee.attendance_ids.filtered(
lambda x: x.check_in_without_hour == work_date and x.check_out_without_hour
)
if not attendances:
return 0
for attendance in attendances:
if attendance.attendance_reason_ids and any(
[x.is_rest for x in attendance.attendance_reason_ids]
):
rest_attendances += attendance
if not rest_attendances:
return 0
return sum(rest_attendances.mapped("worked_hours"))

def _get_leave(self, contract, work_date, vals):
vals = super()._get_leave(contract, work_date, vals)
if vals.get("rest_hours") > 0.25:
diff = vals.get("rest_hours") - 0.25
vals["non_remunerated_hours"] = vals.get("non_remunerated_hours") + diff
return vals
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record model="ir.ui.view" id="hr_attendance_leave_tree_view">
<field name="model">hr.attendance.leave</field>
<field
name="inherit_id"
ref="hr_attendance_leave_report.hr_attendance_leave_tree_view"
/>
<field name="arch" type="xml">
<field name="worked_hours" position="after">
<field
name="rest_hours"
widget="float_time"
optional="show"
sum="Total Rest Hours"
/>
</field>
</field>
</record>

<record model="ir.ui.view" id="hr_attendance_leave_form_view">
<field name="model">hr.attendance.leave</field>
<field
name="inherit_id"
ref="hr_attendance_leave_report.hr_attendance_leave_form_view"
/>
<field name="arch" type="xml">
<field name="worked_hours" position="after">
<field name="rest_hours" readonly="1" widget="float_time" />
</field>
</field>
</record>

<record model="ir.ui.view" id="hr_attendance_leave_calendar_view">
<field name="model">hr.attendance.leave</field>
<field
name="inherit_id"
ref="hr_attendance_leave_report.hr_attendance_leave_calendar_view"
/>
<field name="arch" type="xml">
<field name="worked_hours" position="after">
<field name="rest_hours" widget="float_time" />
</field>
</field>
</record>
</odoo>
6 changes: 6 additions & 0 deletions setup/hr_attendance_leave_report_rest/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Loading