diff --git a/hr_payroll_document_pymupdf/README.rst b/hr_payroll_document_pymupdf/README.rst new file mode 100644 index 000000000..cbb2e9274 --- /dev/null +++ b/hr_payroll_document_pymupdf/README.rst @@ -0,0 +1,84 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +=============================== +HR - Payroll Document - PyMuPDF +=============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:9b97fc250e9f7c34ba848cdc7ac246d98c29cdd4d8f16c1d6ed18fcf14fbc4f8 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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/19.0/hr_payroll_document_pymupdf + :alt: OCA/payroll +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/payroll-19-0/payroll-19-0-hr_payroll_document_pymupdf + :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=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Use the library PyMuPDF (https://github.com/pymupdf/pymupdf) to attempt +reading the PDF 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 +------- + +* PyTech + +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. + +.. |maintainer-SirPyTech| image:: https://github.com/SirPyTech.png?size=40px + :target: https://github.com/SirPyTech + :alt: SirPyTech + +Current `maintainer `__: + +|maintainer-SirPyTech| + +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_document_pymupdf/__init__.py b/hr_payroll_document_pymupdf/__init__.py new file mode 100644 index 000000000..74d71de4b --- /dev/null +++ b/hr_payroll_document_pymupdf/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import wizards diff --git a/hr_payroll_document_pymupdf/__manifest__.py b/hr_payroll_document_pymupdf/__manifest__.py new file mode 100644 index 000000000..6ef63bb43 --- /dev/null +++ b/hr_payroll_document_pymupdf/__manifest__.py @@ -0,0 +1,20 @@ +{ + "name": "HR - Payroll Document - PyMuPDF", + "summary": "Try harder to read a PDF payslip with PyMuPDF.", + "author": "PyTech, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/payroll", + "license": "AGPL-3", + "category": "Payrolls", + "version": "19.0.1.0.0", + "depends": [ + "hr_payroll_document", + ], + "maintainers": [ + "SirPyTech", + ], + "external_dependencies": { + "python": [ + "PyMuPDF", + ], + }, +} diff --git a/hr_payroll_document_pymupdf/i18n/hr_payroll_document_pymupdf.pot b/hr_payroll_document_pymupdf/i18n/hr_payroll_document_pymupdf.pot new file mode 100644 index 000000000..75a717f16 --- /dev/null +++ b/hr_payroll_document_pymupdf/i18n/hr_payroll_document_pymupdf.pot @@ -0,0 +1,26 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_payroll_document_pymupdf +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \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_document_pymupdf +#: model:ir.model,name:hr_payroll_document_pymupdf.model_payroll_management_wizard +msgid "Payroll Management" +msgstr "" + +#. module: hr_payroll_document_pymupdf +#. odoo-python +#: code:addons/hr_payroll_document_pymupdf/tests/test_payroll_management.py:0 +#, python-format +msgid "Payrolls sent" +msgstr "" diff --git a/hr_payroll_document_pymupdf/i18n/it.po b/hr_payroll_document_pymupdf/i18n/it.po new file mode 100644 index 000000000..5bd7b911b --- /dev/null +++ b/hr_payroll_document_pymupdf/i18n/it.po @@ -0,0 +1,29 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_payroll_document_pymupdf +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2026-01-22 09:50+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.15.2\n" + +#. module: hr_payroll_document_pymupdf +#: model:ir.model,name:hr_payroll_document_pymupdf.model_payroll_management_wizard +msgid "Payroll Management" +msgstr "Gestione retribuzione" + +#. module: hr_payroll_document_pymupdf +#. odoo-python +#: code:addons/hr_payroll_document_pymupdf/tests/test_payroll_management.py:0 +#, python-format +msgid "Payrolls sent" +msgstr "Retribuzioni inviate" diff --git a/hr_payroll_document_pymupdf/pyproject.toml b/hr_payroll_document_pymupdf/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/hr_payroll_document_pymupdf/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/hr_payroll_document_pymupdf/readme/DESCRIPTION.md b/hr_payroll_document_pymupdf/readme/DESCRIPTION.md new file mode 100644 index 000000000..6b5cfcab6 --- /dev/null +++ b/hr_payroll_document_pymupdf/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +Use the library PyMuPDF () to +attempt reading the PDF payslip. diff --git a/hr_payroll_document_pymupdf/static/description/icon.png b/hr_payroll_document_pymupdf/static/description/icon.png new file mode 100644 index 000000000..1dcc49c24 Binary files /dev/null and b/hr_payroll_document_pymupdf/static/description/icon.png differ diff --git a/hr_payroll_document_pymupdf/static/description/index.html b/hr_payroll_document_pymupdf/static/description/index.html new file mode 100644 index 000000000..8d71e14ee --- /dev/null +++ b/hr_payroll_document_pymupdf/static/description/index.html @@ -0,0 +1,425 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

HR - Payroll Document - PyMuPDF

+ +

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

+

Use the library PyMuPDF (https://github.com/pymupdf/pymupdf) to attempt +reading the PDF 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

+
    +
  • PyTech
  • +
+
+
+

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.

+

Current maintainer:

+

SirPyTech

+

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_document_pymupdf/tests/__init__.py b/hr_payroll_document_pymupdf/tests/__init__.py new file mode 100644 index 000000000..cbc8cf7e3 --- /dev/null +++ b/hr_payroll_document_pymupdf/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_payroll_management diff --git a/hr_payroll_document_pymupdf/tests/test_broken_image.pdf b/hr_payroll_document_pymupdf/tests/test_broken_image.pdf new file mode 100644 index 000000000..2d08e2145 Binary files /dev/null and b/hr_payroll_document_pymupdf/tests/test_broken_image.pdf differ diff --git a/hr_payroll_document_pymupdf/tests/test_payroll_management.py b/hr_payroll_document_pymupdf/tests/test_payroll_management.py new file mode 100644 index 000000000..f8aa4f442 --- /dev/null +++ b/hr_payroll_document_pymupdf/tests/test_payroll_management.py @@ -0,0 +1,16 @@ +from odoo.addons.hr_payroll_document.tests.common import TestHrPayrollDocument + + +class TestPayrollManagement(TestHrPayrollDocument): + def test_pdf_broken_image(self): + """If the PDF cannot be processed with PyPDF, try with another reader.""" + self.fill_company_id() + identification_code = "xXXXXXXXXXXXXXXX" + with self._mock_valid_identification(self.employee_emp, identification_code): + self.employee_emp.identification_id = identification_code + self.wizard = self._create_wizard( + "Subject", "hr_payroll_document_pymupdf/tests/test_broken_image.pdf" + ) + with self._mock_valid_identification(self.employee_emp, identification_code): + result_action = self.wizard.send_payrolls() + self.assertEqual(result_action["params"]["title"], self.env._("Payrolls sent")) diff --git a/hr_payroll_document_pymupdf/wizards/__init__.py b/hr_payroll_document_pymupdf/wizards/__init__.py new file mode 100644 index 000000000..723401a24 --- /dev/null +++ b/hr_payroll_document_pymupdf/wizards/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import payroll_management_wizard diff --git a/hr_payroll_document_pymupdf/wizards/payroll_management_wizard.py b/hr_payroll_document_pymupdf/wizards/payroll_management_wizard.py new file mode 100644 index 000000000..07572e891 --- /dev/null +++ b/hr_payroll_document_pymupdf/wizards/payroll_management_wizard.py @@ -0,0 +1,35 @@ +# Copyright 2025 Simone Rubino - PyTech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import io + +import pymupdf +import pypdf +from reportlab.pdfgen import canvas + +from odoo import models + + +class PayrollManagamentWizard(models.TransientModel): + _inherit = "payroll.management.wizard" + + def _get_fallback_reader(self, pdf_reader): + reader = super()._get_fallback_reader(pdf_reader) + if not reader: + # Read the file with another reader + doc = pymupdf.Document(stream=pdf_reader.stream) + + # Create a new PDF with only the extracted content + pdf_content = io.BytesIO() + pdf_canvas = canvas.Canvas(pdf_content) + for page_number in range(pdf_reader.get_num_pages()): + page_content = doc[page_number].get_text().split() + # Create a new page with the read content + pdf_canvas.drawString(0, 0, " ".join(page_content)) + pdf_canvas.showPage() + pdf_canvas.save() + + # Return a PyPDF reader for the new PDF, + # that now is readable + reader = pypdf.PdfReader(pdf_content) + return reader diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..0e9fc8cd2 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +# generated from manifests external_dependencies +PyMuPDF diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 000000000..d9450ddba --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo-addon-hr_payroll_document @ git+https://github.com/OCA/payroll@refs/pull/279/head#subdirectory=hr_payroll_document