From d3da03c1ac05efecfed63542f2aade8a0aa7dd43 Mon Sep 17 00:00:00 2001 From: CristianoMafraJunior Date: Wed, 24 Sep 2025 10:01:01 -0300 Subject: [PATCH] [ADD] hr_payroll_attendance_report: payroll attendance report --- hr_payroll_attendance_report/README.rst | 78 ++++ hr_payroll_attendance_report/__init__.py | 3 + hr_payroll_attendance_report/__manifest__.py | 18 + .../i18n/hr_payroll_attendance_report.pot | 61 +++ .../models/__init__.py | 3 + .../models/hr_payslip.py | 30 ++ hr_payroll_attendance_report/pyproject.toml | 3 + .../readme/CONTRIBUTORS.rst | 3 + .../readme/DESCRIPTION.rst | 1 + .../report/report_hr_payroll_attendance.xml | 66 +++ .../static/description/icon.png | Bin 0 -> 2873 bytes .../static/description/index.html | 423 ++++++++++++++++++ .../tests/__init__.py | 1 + .../tests/test_attendance_on_payslip.py | 66 +++ .../odoo/addons/hr_payroll_attendance_report | 1 + setup/hr_payroll_attendance_report/setup.py | 6 + 16 files changed, 763 insertions(+) create mode 100644 hr_payroll_attendance_report/README.rst create mode 100644 hr_payroll_attendance_report/__init__.py create mode 100644 hr_payroll_attendance_report/__manifest__.py create mode 100644 hr_payroll_attendance_report/i18n/hr_payroll_attendance_report.pot create mode 100644 hr_payroll_attendance_report/models/__init__.py create mode 100644 hr_payroll_attendance_report/models/hr_payslip.py create mode 100644 hr_payroll_attendance_report/pyproject.toml create mode 100644 hr_payroll_attendance_report/readme/CONTRIBUTORS.rst create mode 100644 hr_payroll_attendance_report/readme/DESCRIPTION.rst create mode 100644 hr_payroll_attendance_report/report/report_hr_payroll_attendance.xml create mode 100644 hr_payroll_attendance_report/static/description/icon.png create mode 100644 hr_payroll_attendance_report/static/description/index.html create mode 100644 hr_payroll_attendance_report/tests/__init__.py create mode 100644 hr_payroll_attendance_report/tests/test_attendance_on_payslip.py create mode 120000 setup/hr_payroll_attendance_report/odoo/addons/hr_payroll_attendance_report create mode 100644 setup/hr_payroll_attendance_report/setup.py diff --git a/hr_payroll_attendance_report/README.rst b/hr_payroll_attendance_report/README.rst new file mode 100644 index 000000000..f9206707a --- /dev/null +++ b/hr_payroll_attendance_report/README.rst @@ -0,0 +1,78 @@ +========================= +Payroll Attendance Report +========================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:feeb4c350afe5ddb6efb4be0891f8a31c814abb0f3aa92d9b67b4c19476314ca + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fpayroll-lightgray.png?logo=github + :target: https://github.com/OCA/payroll/tree/16.0/hr_payroll_attendance_report + :alt: OCA/payroll +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/payroll-16-0/payroll-16-0-hr_payroll_attendance_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/payroll&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Attendance Control on Payslip + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Escodoo + +Contributors +~~~~~~~~~~~~ + +* `Escodoo `_: + + * Cristiano Mafra Junior + +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/payroll `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/hr_payroll_attendance_report/__init__.py b/hr_payroll_attendance_report/__init__.py new file mode 100644 index 000000000..ed65565dc --- /dev/null +++ b/hr_payroll_attendance_report/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2025 - TODAY, Cristiano Mafra Junior +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import models diff --git a/hr_payroll_attendance_report/__manifest__.py b/hr_payroll_attendance_report/__manifest__.py new file mode 100644 index 000000000..1580f67f4 --- /dev/null +++ b/hr_payroll_attendance_report/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2025 - TODAY, Cristiano Mafra Junior +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Payroll Attendance Report", + "summary": "Payslip Attendance on Report", + "version": "16.0.1.0.0", + "author": "Escodoo ,Odoo Community Association (OCA)", + "license": "AGPL-3", + "website": "https://github.com/OCA/payroll", + "depends": [ + "payroll", + "hr_attendance", + ], + "data": [ + "report/report_hr_payroll_attendance.xml", + ], + "installable": True, +} diff --git a/hr_payroll_attendance_report/i18n/hr_payroll_attendance_report.pot b/hr_payroll_attendance_report/i18n/hr_payroll_attendance_report.pot new file mode 100644 index 000000000..f0381267f --- /dev/null +++ b/hr_payroll_attendance_report/i18n/hr_payroll_attendance_report.pot @@ -0,0 +1,61 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_payroll_attendance_report +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-09-24 12:54+0000\n" +"PO-Revision-Date: 2025-09-24 12:54+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_payroll_attendance_report +#: model_terms:ir.ui.view,arch_db:hr_payroll_attendance_report.report_hr_payroll_attendance_report +msgid "Total in Period:" +msgstr "" + +#. module: hr_payroll_attendance_report +#: model:ir.model.fields,field_description:hr_payroll_attendance_report.field_hr_payslip__attendance_ids +msgid "Attendance" +msgstr "" + +#. module: hr_payroll_attendance_report +#: model_terms:ir.ui.view,arch_db:hr_payroll_attendance_report.report_hr_payroll_attendance_report +msgid "Check In" +msgstr "" + +#. module: hr_payroll_attendance_report +#: model_terms:ir.ui.view,arch_db:hr_payroll_attendance_report.report_hr_payroll_attendance_report +msgid "Check Out" +msgstr "" + +#. module: hr_payroll_attendance_report +#: model_terms:ir.ui.view,arch_db:hr_payroll_attendance_report.report_hr_payroll_attendance_report +msgid "Date" +msgstr "" + +#. module: hr_payroll_attendance_report +#: model:ir.model,name:hr_payroll_attendance_report.model_hr_payslip +msgid "Payslip" +msgstr "" + +#. module: hr_payroll_attendance_report +#: model_terms:ir.ui.view,arch_db:hr_payroll_attendance_report.report_hr_payroll_attendance_report +msgid "Total" +msgstr "" + +#. module: hr_payroll_attendance_report +#: model:ir.model.fields,field_description:hr_payroll_attendance_report.field_hr_payslip__total_worked_hours +msgid "Total Worked Hours" +msgstr "" + +#. module: hr_payroll_attendance_report +#: model_terms:ir.ui.view,arch_db:hr_payroll_attendance_report.report_hr_payroll_attendance_report +msgid "Worked Hours" +msgstr "" diff --git a/hr_payroll_attendance_report/models/__init__.py b/hr_payroll_attendance_report/models/__init__.py new file mode 100644 index 000000000..47c74fb36 --- /dev/null +++ b/hr_payroll_attendance_report/models/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2025 - TODAY, Cristiano Mafra Junior +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import hr_payslip diff --git a/hr_payroll_attendance_report/models/hr_payslip.py b/hr_payroll_attendance_report/models/hr_payslip.py new file mode 100644 index 000000000..622be458a --- /dev/null +++ b/hr_payroll_attendance_report/models/hr_payslip.py @@ -0,0 +1,30 @@ +# Copyright 2025 - TODAY, Cristiano Mafra Junior +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class HrPayslip(models.Model): + _inherit = "hr.payslip" + + attendance_ids = fields.One2many( + comodel_name="hr.attendance", + compute="_compute_attendance_ids", + ) + total_worked_hours = fields.Float( + compute="_compute_attendance_ids", + ) + + @api.depends("date_from", "date_to", "employee_id") + def _compute_attendance_ids(self): + for slip in self: + attendances = self.env["hr.attendance"].search( + [ + ("employee_id", "=", slip.employee_id.id), + ("check_in", ">=", slip.date_from), + ("check_in", "<=", slip.date_to), + ], + order="check_in ASC", + ) + slip.attendance_ids = attendances + slip.total_worked_hours = sum(att.worked_hours for att in attendances) diff --git a/hr_payroll_attendance_report/pyproject.toml b/hr_payroll_attendance_report/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/hr_payroll_attendance_report/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/hr_payroll_attendance_report/readme/CONTRIBUTORS.rst b/hr_payroll_attendance_report/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..418948a9f --- /dev/null +++ b/hr_payroll_attendance_report/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Escodoo `_: + + * Cristiano Mafra Junior diff --git a/hr_payroll_attendance_report/readme/DESCRIPTION.rst b/hr_payroll_attendance_report/readme/DESCRIPTION.rst new file mode 100644 index 000000000..11060c6cc --- /dev/null +++ b/hr_payroll_attendance_report/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Attendance Control on Payslip diff --git a/hr_payroll_attendance_report/report/report_hr_payroll_attendance.xml b/hr_payroll_attendance_report/report/report_hr_payroll_attendance.xml new file mode 100644 index 000000000..36028d243 --- /dev/null +++ b/hr_payroll_attendance_report/report/report_hr_payroll_attendance.xml @@ -0,0 +1,66 @@ + + + + + diff --git a/hr_payroll_attendance_report/static/description/icon.png b/hr_payroll_attendance_report/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..12ab0051e3b9ac413f0f0016b7cff54f02fc763e GIT binary patch literal 2873 zcmV-93&!+`P)`uGecH7++*a9tqf=D4K3Mya}O@tpzNQ@yQCf@Kr zF!+nnKqBHT7^8%kXfz5&3vvk;1t}w7Z?N*D?A{ zHrd_G%z4iDJn#2;p6~mP`2CNcJjDNjrs?X8sbe)Nav^9t4K(ppCb-d2d)&lZ>k%SMT{9YBg-a+&W{!hd#wDr8Wl{eXS z*$7*96lqpl{PUr=s8^hIiDg}g*f5f1&&S6&>%w7_k{mf$=0jJV!9`c@;PA^Op1%JL zjvcP7X-sQIgb*+?KF9@EjIw?AMgZbC#&KNql%Q6tlgni}^ZZSmdHyEeJ2=g=55CEv zmnMkgHHh!qH~xB6FC&#;=S7>@bLA+-%~=4VD8ltxIF5^^DFQzvj6#%BWV03ng*-|r z04k*>&p&>cm!5nFzZI@poU2BJnbtV_!&|uU$}y~h2|yTz*p5r9WG&z2} zgzMT!DN#yCDn%xfCZEq?8U_G%-Q$HP-sbto4&yXiD<1EPFO7UL&G{c2<=nkn(2e#} z^@9M%@$h}0bjoDo#v;0Q@};9FB8of+1YzLQY&J2?6oo>LOfJpk*PX*9*NpSZGe>#u zk%LT6G*&F`6(eG3TaNRu7-jszVWetTW!G!rx-L-^kx8c+94Mev4;4F(2?8GipD+k; zT^B>w$>nooEsH%@Z0CZHj&bnk*sdZMTrtMhorAOY5aYNW zj^iMu#L8sIWYP#BmUN9U4B9_|Ps?vnt=7opvgGFp>%@^N2Od4dtIr-Kik7z0m!uI& z6O3QDnTtL##=x*O8*qf7`Rm>4UQp;#P5$@Lpq;;yjH>WJ5(YUt#1IdZuydp@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|I<>B8QVEe#MEYn(c+#RUPc3pF87$=+5 z7J?9hjF}>r$?(qG$9Qnxe!?K)oZVxXrh#dixSmI&VWX7ldI$4~kW!%=DbkrV!^1=5 zvKCPkbN_u$@}uwmj#RVArotAaSlN?&;+E@gi@h*;-R%Vp$EGw>VPtfOo4@{f#?KuE zm=)7@Wf>^snVg))^Bj~m+Y<~Fx~KLIzHyYhe((pviouqF5t7bEy+Yh_!)>t_tPT+X zVH7c4t5LNZeDuma+<5b+$>lS|aZJ;8a9xi$0wKY&=FV+48xFs@`$6_U{3>S+??hM0 zOJWkNYDUb5+iFpssh|wS7r%TpS6zECLJ0gIpfpio$BvQi5#pyFe}Q{`wvQom8v~ia zRgVooTS{lS6r>D;ZNrHuU^O2v0>bXk7=45J37f-Kl}rwLv_YC zo`+ar9as$FmK$!5y&##tw_F5a$W*n8-E#TlXD;F5OLueVjrVxyzGpb2xRbQ8a@C+$ zh;Q9+d+e?;5gjxghjO)oP?FJsF}4hhu1g#MTFduVONdVkE1hOTc8IJ|M9GsIt+j&Z z+sJbD{dKvxCUuJG5elhI>q(I({QN z2z?sv45gWOvE4eFE>qZUjkoRBK+sicvFHdR7XOOU0%|W1q%;d9)-MBq*+VWTdKUiy XXqTGI$C0NT00000NkvXXu0mjf?G|(} literal 0 HcmV?d00001 diff --git a/hr_payroll_attendance_report/static/description/index.html b/hr_payroll_attendance_report/static/description/index.html new file mode 100644 index 000000000..3bf151575 --- /dev/null +++ b/hr_payroll_attendance_report/static/description/index.html @@ -0,0 +1,423 @@ + + + + + +Payroll Attendance Report + + + +
+

Payroll Attendance Report

+ + +

Beta License: AGPL-3 OCA/payroll Translate me on Weblate Try me on Runboat

+

Attendance Control on Payslip

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Escodoo
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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/payroll project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/hr_payroll_attendance_report/tests/__init__.py b/hr_payroll_attendance_report/tests/__init__.py new file mode 100644 index 000000000..4ce111d26 --- /dev/null +++ b/hr_payroll_attendance_report/tests/__init__.py @@ -0,0 +1 @@ +from . import test_attendance_on_payslip diff --git a/hr_payroll_attendance_report/tests/test_attendance_on_payslip.py b/hr_payroll_attendance_report/tests/test_attendance_on_payslip.py new file mode 100644 index 000000000..3c65bd55e --- /dev/null +++ b/hr_payroll_attendance_report/tests/test_attendance_on_payslip.py @@ -0,0 +1,66 @@ +# Copyright 2025 - TODAY, Cristiano Mafra Junior +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from datetime import datetime, timedelta + +from odoo.tests.common import TransactionCase + + +class TestPayrollAttendanceReport(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.employee = cls.env["hr.employee"].create( + { + "name": "Test Employee", + } + ) + cls.contract = cls.env["hr.contract"].create( + { + "name": "Contract", + "employee_id": cls.employee.id, + "date_start": datetime(2025, 1, 1), + "wage": 1000, + "state": "open", + } + ) + cls.date_from = datetime(2025, 1, 1) + cls.date_to = datetime(2025, 1, 31) + + cls.payslip = cls.env["hr.payslip"].create( + { + "employee_id": cls.employee.id, + "date_from": cls.date_from, + "date_to": cls.date_to, + "contract_id": cls.contract.id, + } + ) + cls.env["hr.attendance"].create( + { + "employee_id": cls.employee.id, + "check_in": datetime(2025, 1, 10, 9, 0, 0), + "check_out": datetime(2025, 1, 10, 17, 0, 0), + } + ) + cls.env["hr.attendance"].create( + { + "employee_id": cls.employee.id, + "check_in": datetime(2025, 1, 15, 9, 0, 0), + "check_out": datetime(2025, 1, 15, 13, 0, 0), + } + ) + + def test_attendance_links_and_totals(self): + self.payslip.compute_sheet() + slip = self.payslip.with_context(prefetch_fields=False) + self.assertTrue(hasattr(slip, "attendance_ids")) + self.assertTrue(hasattr(slip, "total_worked_hours")) + + self.assertEqual(len(slip.attendance_ids), 2) + + self.assertAlmostEqual(slip.total_worked_hours, 12.0, places=2) + + for att in slip.attendance_ids: + self.assertGreaterEqual(att.check_in, self.date_from) + self.assertLessEqual(att.check_out, self.date_to + timedelta(days=1)) diff --git a/setup/hr_payroll_attendance_report/odoo/addons/hr_payroll_attendance_report b/setup/hr_payroll_attendance_report/odoo/addons/hr_payroll_attendance_report new file mode 120000 index 000000000..a527f17c1 --- /dev/null +++ b/setup/hr_payroll_attendance_report/odoo/addons/hr_payroll_attendance_report @@ -0,0 +1 @@ +../../../../hr_payroll_attendance_report \ No newline at end of file diff --git a/setup/hr_payroll_attendance_report/setup.py b/setup/hr_payroll_attendance_report/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/hr_payroll_attendance_report/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)