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
19 changes: 15 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
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 All @@ -19,10 +21,16 @@ class PayrollManagamentWizard(models.TransientModel):
"ir.attachment", "payrol_rel", "doc_id", "attach_id3", copy=False, required=True
)

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 send_payrolls(self):
not_found = set()
self.merge_pdfs()
reader = PdfReader("/tmp/merged-pdf.pdf")
reader = PdfReader(f"{self._get_temp_path()}merged-pdf.pdf")
employees = set()

# Validate if company have country
Expand All @@ -48,7 +56,9 @@ def send_payrolls(self):
# Save pdf with payrolls of employee
pdfWriter.add_page(page)

path = "/tmp/" + self.env._("Payroll ") + employee.name + ".pdf"
path = (
self._get_temp_path() + self.env._("Payroll ") + employee.name + ".pdf"
)

if not employee.no_payroll_encryption:
# Encrypt the payroll file
Expand Down Expand Up @@ -96,13 +106,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(self.env._("Missing pdf file signature"))
f = open("/tmp/" + file.name, "wb")
f = open(self._get_temp_path() + file.name, "wb")
f.write(btes)
f.close()
pdfs.append(f.name)
Expand All @@ -112,7 +123,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
92 changes: 92 additions & 0 deletions hr_payroll_document_queue/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
=============================
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/18.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-18-0/payroll-18-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=18.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:%2018.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/18.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": "18.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/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_payroll_document_queue/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [PyTech](https://www.pytech.it):
- Simone Rubino \<simone.rubino@pytech.it\>
7 changes: 7 additions & 0 deletions hr_payroll_document_queue/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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
Loading