diff --git a/hr_payroll_document/README.rst b/hr_payroll_document/README.rst index d8023bfd5..5664b74c8 100644 --- a/hr_payroll_document/README.rst +++ b/hr_payroll_document/README.rst @@ -30,6 +30,9 @@ 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:: @@ -58,6 +61,9 @@ Contributors * Antoni Marroig Campomar * Miquel Alzanillas Monserrat +* `PyTech `_: + + * Simone Rubino Maintainers ~~~~~~~~~~~ diff --git a/hr_payroll_document/__manifest__.py b/hr_payroll_document/__manifest__.py index 62648d123..9142203f1 100644 --- a/hr_payroll_document/__manifest__.py +++ b/hr_payroll_document/__manifest__.py @@ -13,5 +13,7 @@ "wizard/payroll_management_wizard.xml", "security/ir.model.access.csv", "data/email_payroll_employee.xml", + "views/hr_employee_views.xml", + "views/res_users_views.xml", ], } diff --git a/hr_payroll_document/models/__init__.py b/hr_payroll_document/models/__init__.py index 9fa86bfb9..b4048b8c9 100644 --- a/hr_payroll_document/models/__init__.py +++ b/hr_payroll_document/models/__init__.py @@ -1,3 +1,4 @@ from . import ir_attachment_payroll_custom from . import ir_attachment from . import hr_employee +from . import res_users diff --git a/hr_payroll_document/models/hr_employee.py b/hr_payroll_document/models/hr_employee.py index 8d9e38892..e691911f7 100644 --- a/hr_payroll_document/models/hr_employee.py +++ b/hr_payroll_document/models/hr_employee.py @@ -1,10 +1,18 @@ -from odoo import _, models +from odoo import _, fields, models from odoo.exceptions import ValidationError 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.", + ) + def write(self, vals): res = super().write(vals) if "identification_id" in vals and not self.env["res.partner"].simple_vat_check( diff --git a/hr_payroll_document/models/res_users.py b/hr_payroll_document/models/res_users.py new file mode 100644 index 000000000..7d990e946 --- /dev/null +++ b/hr_payroll_document/models/res_users.py @@ -0,0 +1,18 @@ +# 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, + ) diff --git a/hr_payroll_document/readme/CONTRIBUTORS.rst b/hr_payroll_document/readme/CONTRIBUTORS.rst index 08488d3fa..fc832defa 100644 --- a/hr_payroll_document/readme/CONTRIBUTORS.rst +++ b/hr_payroll_document/readme/CONTRIBUTORS.rst @@ -1,2 +1,5 @@ * Antoni Marroig Campomar * Miquel Alzanillas Monserrat +* `PyTech `_: + + * Simone Rubino diff --git a/hr_payroll_document/readme/DESCRIPTION.rst b/hr_payroll_document/readme/DESCRIPTION.rst index a4011cb52..5cfc18087 100644 --- a/hr_payroll_document/readme/DESCRIPTION.rst +++ b/hr_payroll_document/readme/DESCRIPTION.rst @@ -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 f9e203549..b918cd9ba 100644 --- a/hr_payroll_document/static/description/index.html +++ b/hr_payroll_document/static/description/index.html @@ -1,4 +1,3 @@ - @@ -9,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -275,7 +275,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -301,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -371,6 +371,8 @@

HR - Payroll Document

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

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

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +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.

diff --git a/hr_payroll_document/tests/test_hr_payroll_document.py b/hr_payroll_document/tests/test_hr_payroll_document.py index 1259a74a4..dc0bf59de 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 @@ -105,3 +108,35 @@ def test_send_payrolls_correctly(self): }, }, ) + + 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 new file mode 100644 index 000000000..fc4976da3 --- /dev/null +++ b/hr_payroll_document/views/hr_employee_views.xml @@ -0,0 +1,20 @@ + + + + + hr.employee.form + hr.employee + + + + + + + + + + + diff --git a/hr_payroll_document/views/res_users_views.xml b/hr_payroll_document/views/res_users_views.xml new file mode 100644 index 000000000..4befd79f6 --- /dev/null +++ b/hr_payroll_document/views/res_users_views.xml @@ -0,0 +1,27 @@ + + + + + Add Payroll fields to User profile form view + res.users + + +
+ + + +
+
+
+
diff --git a/hr_payroll_document/wizard/payroll_management_wizard.py b/hr_payroll_document/wizard/payroll_management_wizard.py index 208753033..ab9734516 100644 --- a/hr_payroll_document/wizard/payroll_management_wizard.py +++ b/hr_payroll_document/wizard/payroll_management_wizard.py @@ -54,8 +54,9 @@ 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)