[MIG] report_qweb_signer to 16.0

This commit is contained in:
Benjamin Willig
2024-01-10 09:35:19 +01:00
parent 3e2edd285d
commit 30257d2327
9 changed files with 44 additions and 33 deletions

View File

@@ -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 <https://github.com/OCA/reporting-engine/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/reporting-engine/issues/new?body=module:%20report_qweb_signer%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_qweb_signer%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.
@@ -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 <https://github.com/OCA/reporting-engine/tree/14.0/report_qweb_signer>`_ project on GitHub.
This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/16.0/report_qweb_signer>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@@ -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)",

View File

@@ -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.")

View File

@@ -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(

View File

@@ -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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/reporting-engine/tree/14.0/report_qweb_signer"><img alt="OCA/reporting-engine" src="https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/reporting-engine-14-0/reporting-engine-14-0-report_qweb_signer"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/reporting-engine&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/reporting-engine/tree/16.0/report_qweb_signer"><img alt="OCA/reporting-engine" src="https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/reporting-engine-16-0/reporting-engine-16-0-report_qweb_signer"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/reporting-engine&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module extends the functionality of report module to sign
PDFs using a PKCS#12 certificate.</p>
<p><strong>Table of contents</strong></p>
@@ -467,7 +467,7 @@ See <a class="reference external" href="https://github.com/OCA/reporting-engine/
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/reporting-engine/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_qweb_signer%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_qweb_signer%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
@@ -525,7 +525,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/reporting-engine/tree/14.0/report_qweb_signer">OCA/reporting-engine</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/reporting-engine/tree/16.0/report_qweb_signer">OCA/reporting-engine</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>

View File

@@ -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)

View File

@@ -1,4 +1,6 @@
# generated from manifests external_dependencies
cryptography
endesive
mock
openpyxl
py3o.formats

View File

@@ -0,0 +1 @@
../../../../report_qweb_signer

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)