Skip to content

Commit

Permalink
[MIG] report_qweb_signer to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
benwillig committed Apr 22, 2024
1 parent 3e2edd2 commit 30257d2
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 33 deletions.
12 changes: 6 additions & 6 deletions report_qweb_signer/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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|
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.
2 changes: 1 addition & 1 deletion report_qweb_signer/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
33 changes: 18 additions & 15 deletions report_qweb_signer/models/ir_actions_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -117,13 +117,13 @@ def _attach_signed_write(self, res_ids, certificate, signed):
"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):
Expand Down Expand Up @@ -195,28 +195,31 @@ def pdf_sign(self, pdf, certificate):
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.")
Expand Down
3 changes: 0 additions & 3 deletions report_qweb_signer/models/report_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ def _default_company(self):
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(
Expand Down Expand Up @@ -67,7 +65,6 @@ def _default_company(self):
signing_method = fields.Selection(
selection=[("java", "Java"), ("endesive", "Endesive")],
default="java",
string="Signing Method",
required=True,
)
endesive_certificate_mail = fields.Char(
Expand Down
8 changes: 4 additions & 4 deletions report_qweb_signer/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ <h1 class="title">Qweb PDF reports signer</h1>
!! 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>
Expand Down Expand Up @@ -467,7 +467,7 @@ <h1><a class="toc-backref" href="#toc-entry-6">Bug Tracker</a></h1>
<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">
Expand Down Expand Up @@ -525,7 +525,7 @@ <h2><a class="toc-backref" href="#toc-entry-13">Maintainers</a></h2>
<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>
Expand Down
10 changes: 6 additions & 4 deletions report_qweb_signer/tests/test_report_qweb_signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ def setUp(self):
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)
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# generated from manifests external_dependencies
cryptography
endesive
mock
openpyxl
py3o.formats
Expand Down
1 change: 1 addition & 0 deletions setup/report_qweb_signer/odoo/addons/report_qweb_signer
6 changes: 6 additions & 0 deletions setup/report_qweb_signer/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 30257d2

Please sign in to comment.