diff --git a/hr_payroll_document/README.rst b/hr_payroll_document/README.rst index c707f4f5e..0adfd6615 100644 --- a/hr_payroll_document/README.rst +++ b/hr_payroll_document/README.rst @@ -1,7 +1,3 @@ -.. 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 ===================== @@ -11,13 +7,13 @@ HR - Payroll Document !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:8541f32cab0e71108ff8c422d602825bb599e0141fe69b9342c16742bee0b915 + !! source digest: sha256:3f9b184eea79f0c56b920d38a9ed320b6a41331383aa18c126b2583f13c30e2e !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |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 +.. |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 @@ -35,6 +31,10 @@ HR - Payroll Document This module have a wizard view to manage the different payrolls of employees which is identified by the identification_id attribute. +By default, the employee's payroll is encrypted using their +identification number. This behavior can be changed by the employee in +their profile or by HR in the employee's form. + **Table of contents** .. contents:: @@ -66,6 +66,10 @@ Contributors - Antoni Marroig - Miquel Alzanillas +- `PyTech `__: + + - Simone Rubino + Maintainers ----------- diff --git a/hr_payroll_document/models/hr_employee.py b/hr_payroll_document/models/hr_employee.py index 74c9cdc67..cd6e1a072 100644 --- a/hr_payroll_document/models/hr_employee.py +++ b/hr_payroll_document/models/hr_employee.py @@ -5,6 +5,14 @@ class Employee(models.Model): _inherit = "hr.employee" + no_payroll_encryption = fields.Boolean( + string="Disable payrolls encryption", + help="If this is disabled (default), " + "the PDF payrolls are encrypted using the Identification No.\n" + "Only future payrolls are affected by this change, " + "existing payrolls will not change their encryption status.", + ) + payroll_count = fields.Integer( compute="_compute_payroll_count", ) diff --git a/hr_payroll_document/models/res_users.py b/hr_payroll_document/models/res_users.py index f85626c47..4cfcebc30 100644 --- a/hr_payroll_document/models/res_users.py +++ b/hr_payroll_document/models/res_users.py @@ -1,9 +1,22 @@ -from odoo import models +# Copyright 2025 Simone Rubino - PyTech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + +from odoo.addons.hr.models.res_users import HR_WRITABLE_FIELDS + +HR_WRITABLE_FIELDS.append("no_payroll_encryption") class ResUsers(models.Model): _inherit = "res.users" + no_payroll_encryption = fields.Boolean( + related="employee_id.no_payroll_encryption", + readonly=False, + related_sudo=False, + ) + def action_get_attachment_tree_view(self): action = self.env.ref("base.action_attachment").sudo().read()[0] action["context"] = { diff --git a/hr_payroll_document/readme/CONTRIBUTORS.md b/hr_payroll_document/readme/CONTRIBUTORS.md index 4098d2040..b89abc610 100644 --- a/hr_payroll_document/readme/CONTRIBUTORS.md +++ b/hr_payroll_document/readme/CONTRIBUTORS.md @@ -1,3 +1,5 @@ - [APSL-Nagarro](https://www.apsl.tech): - Antoni Marroig \<\> - Miquel Alzanillas \<\> +- [PyTech](https://www.pytech.it): + - Simone Rubino \<\> diff --git a/hr_payroll_document/readme/DESCRIPTION.md b/hr_payroll_document/readme/DESCRIPTION.md index a4011cb52..5cfc18087 100644 --- a/hr_payroll_document/readme/DESCRIPTION.md +++ b/hr_payroll_document/readme/DESCRIPTION.md @@ -1 +1,4 @@ This module have a wizard view to manage the different payrolls of employees which is identified by the identification_id attribute. + +By default, the employee's payroll is encrypted using their identification number. +This behavior can be changed by the employee in their profile or by HR in the employee's form. diff --git a/hr_payroll_document/static/description/index.html b/hr_payroll_document/static/description/index.html index 0e20318d9..1625fd368 100644 --- a/hr_payroll_document/static/description/index.html +++ b/hr_payroll_document/static/description/index.html @@ -3,7 +3,7 @@ -README.rst +HR - Payroll Document -
+
+

HR - Payroll Document

- - -Odoo Community Association - -
-

HR - Payroll Document

-

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

+

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

This module have a wizard view to manage the different payrolls of employees which is identified by the identification_id attribute.

+

By default, the employee’s payroll is encrypted using their +identification number. This behavior can be changed by the employee in +their profile or by HR in the employee’s form.

Table of contents

    @@ -390,7 +388,7 @@

    HR - Payroll Document

-

Bug Tracker

+

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 @@ -398,25 +396,29 @@

Bug Tracker

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

-

Credits

+

Credits

-

Authors

+

Authors

  • APSL
-

Contributors

+

Contributors

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association @@ -431,6 +433,5 @@

Maintainers

-
diff --git a/hr_payroll_document/tests/test_hr_payroll_document.py b/hr_payroll_document/tests/test_hr_payroll_document.py index 0d92c00dc..6bcd7d3e6 100644 --- a/hr_payroll_document/tests/test_hr_payroll_document.py +++ b/hr_payroll_document/tests/test_hr_payroll_document.py @@ -1,4 +1,7 @@ import base64 +import io + +import pypdf from odoo import _ from odoo.exceptions import UserError, ValidationError @@ -107,3 +110,35 @@ def test_send_payrolls_correctly(self): self.wizard.send_payrolls()["params"]["message"], _("Payrolls sent to employees correctly"), ) + + def test_optional_encryption(self): + """The employee's payroll can be not encrypted.""" + # Arrange + self.fill_company_id() + employee = self.employee_emp + employee.update( + { + "identification_id": "51000278D", + "no_payroll_encryption": True, + } + ) + # pre-condition + self.assertTrue(employee.no_payroll_encryption) + + # Act + self.wizard.send_payrolls() + + # Assert + payroll = ( + self.env["ir.attachment.payroll.custom"] + .search( + [ + ("identification_id", "=", employee.identification_id), + ] + ) + .attachment_id + ) + self.assertTrue(payroll) + payroll_content = base64.b64decode(payroll.datas) + payroll_pdf = pypdf.PdfReader(io.BytesIO(payroll_content)) + self.assertFalse(payroll_pdf.is_encrypted) diff --git a/hr_payroll_document/views/hr_employee_views.xml b/hr_payroll_document/views/hr_employee_views.xml index e0f568b41..b4b70f77e 100644 --- a/hr_payroll_document/views/hr_employee_views.xml +++ b/hr_payroll_document/views/hr_employee_views.xml @@ -1,107 +1,130 @@ + - - payroll.view.tree - ir.attachment.payroll.custom - - - - - - - - - - - + + + + + - - hr.res_user.view.form.inherit.document - res.users - - -
- -
-
-
+ Payrolls + +
+
+ + + +
+ + + + + hr.employee.form + hr.employee + + + + + + + + + + diff --git a/hr_payroll_document/wizard/payroll_management_wizard.py b/hr_payroll_document/wizard/payroll_management_wizard.py index 585584fa5..012ad1a26 100644 --- a/hr_payroll_document/wizard/payroll_management_wizard.py +++ b/hr_payroll_document/wizard/payroll_management_wizard.py @@ -50,9 +50,10 @@ def send_payrolls(self): path = "/tmp/" + _("Payroll ") + employee.name + ".pdf" - # Encrypt the payroll file with the identification identifier - # of the employee - pdfWriter.encrypt(employee.identification_id, algorithm="AES-256") + if not employee.no_payroll_encryption: + # Encrypt the payroll file + # with the identification identifier of the employee + pdfWriter.encrypt(employee.identification_id, algorithm="AES-256") f = open(path, "wb") pdfWriter.write(f)