Skip to content
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
17 changes: 13 additions & 4 deletions hr_payroll_document/wizard/payroll_management_wizard.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
import pathlib
from base64 import b64decode

from pypdf import PdfReader, PdfWriter, errors
Expand All @@ -10,6 +11,7 @@
class PayrollManagamentWizard(models.TransientModel):
_name = "payroll.management.wizard"
_description = "Payroll Management"
_rec_name = "subject"

subject = fields.Char(
help="Enter the title of the payroll whether it is the month, week, day, etc."
Expand Down Expand Up @@ -62,6 +64,12 @@ def _extract_employees(self, pdf_reader, fallback_reader=None):

return employee_to_pages, not_found_ids

def _get_temp_path(self):
self.ensure_one()
path = f"/tmp/{self._table}_{self.id}/"
pathlib.Path(path).mkdir(exist_ok=True)
return path

def _build_employee_payroll(self, file_name, pdf_pages, encryption_key=None):
"""Return the path to the created payroll.

Expand All @@ -71,7 +79,7 @@ def _build_employee_payroll(self, file_name, pdf_pages, encryption_key=None):
for page in pdf_pages:
pdfWriter.add_page(page)

path = "/tmp/" + file_name
path = self._get_temp_path() + file_name

if encryption_key:
pdfWriter.encrypt(encryption_key, algorithm="AES-256")
Expand Down Expand Up @@ -99,7 +107,7 @@ def send_payrolls(self):
if not self.env.company.country_id:
raise UserError(_("You must to filled country field of company"))

reader = PdfReader("/tmp/merged-pdf.pdf")
reader = PdfReader(f"{self._get_temp_path()}merged-pdf.pdf")

try:
employee_to_pages, not_found = self._extract_employees(reader)
Expand Down Expand Up @@ -158,13 +166,14 @@ def send_payrolls(self):

def merge_pdfs(self):
# Merge the pdfs together
temp_path = self._get_temp_path()
pdfs = []
for file in self.payrolls:
b64 = file.datas
btes = b64decode(b64, validate=True)
if btes[0:4] != b"%PDF":
raise ValidationError(_("Missing pdf file signature"))
f = open("/tmp/" + file.name, "wb")
f = open(temp_path + file.name, "wb")
f.write(btes)
f.close()
pdfs.append(f.name)
Expand All @@ -174,7 +183,7 @@ def merge_pdfs(self):
for pdf in pdfs:
merger.append(pdf)

merger.write("/tmp/merged-pdf.pdf")
merger.write(f"{temp_path}merged-pdf.pdf")
merger.close()

def send_mail(self, employee, path):
Expand Down
90 changes: 90 additions & 0 deletions hr_payroll_document_queue/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
=============================
HR - Payroll Document - Queue
=============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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/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_document_queue
: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_document_queue
: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|

Allow to process the payslips asynchronously.

If a payroll is being processed asynchronously, attempting to process it again will show a warning and prevent it from being processed.

When the payroll has been processed, the user is notified according to their Notification preference.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/payroll/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/payroll/issues/new?body=module:%20hr_payroll_document_queue%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.

Credits
=======

Authors
~~~~~~~

* PyTech

Contributors
~~~~~~~~~~~~

* `PyTech <https://www.pytech.it>`_:

* Simone Rubino <simone.rubino@pytech.it>

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 <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-SirPyTech|

This module is part of the `OCA/payroll <https://github.com/OCA/payroll/tree/16.0/hr_payroll_document_queue>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions hr_payroll_document_queue/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import wizards
22 changes: 22 additions & 0 deletions hr_payroll_document_queue/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2026 Simone Rubino - PyTech
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "HR - Payroll Document - Queue",
"summary": "Process a PDF payslip aynchronously.",
"author": "PyTech, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/payroll",
"license": "AGPL-3",
"category": "Payrolls",
"version": "16.0.1.0.0",
"maintainers": [
"SirPyTech",
],
"depends": [
"hr_payroll_document",
"queue_job",
],
"data": [
"wizards/payroll_management_wizard_views.xml",
],
}
3 changes: 3 additions & 0 deletions hr_payroll_document_queue/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `PyTech <https://www.pytech.it>`_:

* Simone Rubino <simone.rubino@pytech.it>
5 changes: 5 additions & 0 deletions hr_payroll_document_queue/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Allow to process the payslips asynchronously.

If a payroll is being processed asynchronously, attempting to process it again will show a warning and prevent it from being processed.

When the payroll has been processed, the user is notified according to their Notification preference.
Loading