From 30257d2327803468a146e5099b31e12aef477b43 Mon Sep 17 00:00:00 2001 From: Benjamin Willig Date: Wed, 10 Jan 2024 09:35:19 +0100 Subject: [PATCH] [MIG] report_qweb_signer to 16.0 --- report_qweb_signer/README.rst | 12 +++---- report_qweb_signer/__manifest__.py | 2 +- .../models/ir_actions_report.py | 33 ++++++++++--------- .../models/report_certificate.py | 3 -- .../static/description/index.html | 8 ++--- .../tests/test_report_qweb_signer.py | 10 +++--- requirements.txt | 2 ++ .../odoo/addons/report_qweb_signer | 1 + setup/report_qweb_signer/setup.py | 6 ++++ 9 files changed, 44 insertions(+), 33 deletions(-) create mode 120000 setup/report_qweb_signer/odoo/addons/report_qweb_signer create mode 100644 setup/report_qweb_signer/setup.py diff --git a/report_qweb_signer/README.rst b/report_qweb_signer/README.rst index 9eed30a1a..b3f26972f 100644 --- a/report_qweb_signer/README.rst +++ b/report_qweb_signer/README.rst @@ -7,7 +7,7 @@ Qweb PDF reports signer !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:316684138df7dbf39caf3570053cc282df4a19feb5971dbfc04869e6ca4a634a + !! source digest: sha256:026c79ef044bbcbbb84c90102fa6717fe7fad31842a931eb0e9025513c07ebfe !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -17,13 +17,13 @@ Qweb PDF reports signer :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github - :target: https://github.com/OCA/reporting-engine/tree/14.0/report_qweb_signer + :target: https://github.com/OCA/reporting-engine/tree/16.0/report_qweb_signer :alt: OCA/reporting-engine .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/reporting-engine-14-0/reporting-engine-14-0-report_qweb_signer + :target: https://translation.odoo-community.org/projects/reporting-engine-16-0/reporting-engine-16-0-report_qweb_signer :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/reporting-engine&target_branch=14.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/reporting-engine&target_branch=16.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -113,7 +113,7 @@ 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -167,6 +167,6 @@ 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. -This module is part of the `OCA/reporting-engine `_ project on GitHub. +This module is part of the `OCA/reporting-engine `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/report_qweb_signer/__manifest__.py b/report_qweb_signer/__manifest__.py index 085e148b7..220a36abe 100644 --- a/report_qweb_signer/__manifest__.py +++ b/report_qweb_signer/__manifest__.py @@ -6,7 +6,7 @@ { "name": "Qweb PDF reports signer", "summary": "Sign Qweb PDFs usign a PKCS#12 certificate", - "version": "14.0.2.0.3", + "version": "16.0.1.0.0", "category": "Reporting", "website": "https://github.com/OCA/reporting-engine", "author": "Tecnativa, " "Odoo Community Association (OCA)", diff --git a/report_qweb_signer/models/ir_actions_report.py b/report_qweb_signer/models/ir_actions_report.py index cb88ec02b..77a85693c 100644 --- a/report_qweb_signer/models/ir_actions_report.py +++ b/report_qweb_signer/models/ir_actions_report.py @@ -34,31 +34,31 @@ def _normalize_filepath(path): class IrActionsReport(models.Model): _inherit = "ir.actions.report" - def _certificate_get(self, res_ids): + def _certificate_get(self, report, res_ids): """Obtain the proper certificate for the report and the conditions.""" - if self.report_type != "qweb-pdf": + if report.report_type != "qweb-pdf": return False company_id = self.env.company.id if res_ids: if isinstance(res_ids, int): res_ids = [res_ids] - obj = self.env[self.model].browse(res_ids[0]) + obj = self.env[report.model].browse(res_ids[0]) if "company_id" in obj: company_id = obj.company_id.id or company_id certificates = self.env["report.certificate"].search( [ ("company_id", "=", company_id), - ("model_id", "=", self.model), + ("model_id", "=", report.model_id.id), "|", ("action_report_ids", "=", False), - ("action_report_ids", "in", self.id), + ("action_report_ids", "in", report.id), ] ) if not certificates: return False for cert in certificates: # Check allow only one document - if cert.allow_only_one and len(self) > 1: + if cert.allow_only_one and len(res_ids) > 1: _logger.debug( "Certificate '%s' allows only one document, " "but printing %d documents", @@ -117,13 +117,13 @@ class IrActionsReport(models.Model): "res_id": res_ids[0], } ) - except AccessError: + except AccessError as exc: raise UserError( _( "Saving signed report (PDF): " "You do not have enough access rights to save attachments" ) - ) + ) from exc return attachment def _signer_bin(self, opts): @@ -195,28 +195,31 @@ class IrActionsReport(models.Model): if process.returncode: raise UserError( _( - "Signing report (PDF): jPdfSign failed (error code: %s). " - "Message: %s. Output: %s" + "Signing report (PDF): jPdfSign failed (error code: %(error_code)s). " + "Message: %(message)s. Output: %(output)s", + error_code=process.returncode, + message=err, + output=out, ) - % (process.returncode, err, out) ) elif method_used == "endesive": params = self._get_endesive_params(certificate) self._signer_endesive(params, p12, pdf, pdfsigned, passwd) return pdfsigned - def _render_qweb_pdf(self, res_ids=None, data=None): - certificate = self._certificate_get(res_ids) + def _render_qweb_pdf(self, report_ref, res_ids=None, data=None): + report = self._get_report(report_ref) + certificate = self._certificate_get(report, res_ids) if certificate and certificate.attachment: signed_content = self._attach_signed_read(res_ids, certificate) if signed_content: _logger.debug( "The signed PDF document '%s/%s' was loaded from the " "database", - self.report_name, + report.report_name, res_ids, ) return signed_content, "pdf" - content, ext = super(IrActionsReport, self)._render_qweb_pdf(res_ids, data) + content, ext = super()._render_qweb_pdf(report_ref, res_ids=res_ids, data=data) if certificate: # Creating temporary origin PDF pdf_fd, pdf = tempfile.mkstemp(suffix=".pdf", prefix="report.tmp.") diff --git a/report_qweb_signer/models/report_certificate.py b/report_qweb_signer/models/report_certificate.py index 296df838f..943810908 100644 --- a/report_qweb_signer/models/report_certificate.py +++ b/report_qweb_signer/models/report_certificate.py @@ -27,14 +27,12 @@ class ReportCertificate(models.Model): help="Path to certificate password file", ) model_id = fields.Many2one( - string="Model", required=True, comodel_name="ir.model", help="Model where apply this certificate", ondelete="cascade", ) domain = fields.Char( - string="Domain", help="Domain for filtering if sign or not the document", ) action_report_ids = fields.Many2many( @@ -67,7 +65,6 @@ class ReportCertificate(models.Model): signing_method = fields.Selection( selection=[("java", "Java"), ("endesive", "Endesive")], default="java", - string="Signing Method", required=True, ) endesive_certificate_mail = fields.Char( diff --git a/report_qweb_signer/static/description/index.html b/report_qweb_signer/static/description/index.html index bd8704373..5bce6c5e5 100644 --- a/report_qweb_signer/static/description/index.html +++ b/report_qweb_signer/static/description/index.html @@ -367,9 +367,9 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:316684138df7dbf39caf3570053cc282df4a19feb5971dbfc04869e6ca4a634a +!! source digest: sha256:026c79ef044bbcbbb84c90102fa6717fe7fad31842a931eb0e9025513c07ebfe !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

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

+

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

This module extends the functionality of report module to sign PDFs using a PKCS#12 certificate.

Table of contents

@@ -467,7 +467,7 @@ See 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.

+feedback.

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

@@ -525,7 +525,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome

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.

-

This module is part of the OCA/reporting-engine project on GitHub.

+

This module is part of the OCA/reporting-engine project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/report_qweb_signer/tests/test_report_qweb_signer.py b/report_qweb_signer/tests/test_report_qweb_signer.py index a7acc5887..9d5b13294 100644 --- a/report_qweb_signer/tests/test_report_qweb_signer.py +++ b/report_qweb_signer/tests/test_report_qweb_signer.py @@ -11,16 +11,18 @@ class TestReportQwebSigner(HttpCase): self.report = self.env.ref( "report_qweb_signer.partner_demo_report" ).with_context(force_report_rendering=True) + self.report_ref = self.report.report_name def test_report_qweb_signer(self): - self.report._render_qweb_pdf(self.partner.ids) + partner = self.partner + self.report._render_qweb_pdf(self.report_ref, partner.ids) # Reprint again for taking the PDF from attachment IrAttachment = self.env["ir.attachment"] domain = [ - ("res_id", "=", self.partner.id), - ("res_model", "=", self.partner._name), + ("res_id", "=", partner.id), + ("res_model", "=", partner._name), ] num_attachments = IrAttachment.search_count(domain) - self.report._render_qweb_pdf(self.partner.ids) + self.report._render_qweb_pdf(self.report_ref, partner.ids) num_attachments_after = IrAttachment.search_count(domain) self.assertEqual(num_attachments, num_attachments_after) diff --git a/requirements.txt b/requirements.txt index 712db87fe..9f2f6cf5e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,6 @@ # generated from manifests external_dependencies +cryptography +endesive mock openpyxl py3o.formats diff --git a/setup/report_qweb_signer/odoo/addons/report_qweb_signer b/setup/report_qweb_signer/odoo/addons/report_qweb_signer new file mode 120000 index 000000000..d1c373301 --- /dev/null +++ b/setup/report_qweb_signer/odoo/addons/report_qweb_signer @@ -0,0 +1 @@ +../../../../report_qweb_signer \ No newline at end of file diff --git a/setup/report_qweb_signer/setup.py b/setup/report_qweb_signer/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/report_qweb_signer/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)