[MIG] report_qweb_signer: Migration to 13.0
parent
ae6d5a659c
commit
f9b405aa96
|
@ -6,7 +6,7 @@
|
|||
{
|
||||
"name": "Qweb PDF reports signer",
|
||||
"summary": "Sign Qweb PDFs usign a PKCS#12 certificate",
|
||||
"version": "12.0.1.0.1",
|
||||
"version": "13.0.1.0.0",
|
||||
"category": "Reporting",
|
||||
"website": "https://github.com/oca/reporting-engine",
|
||||
"author": "Tecnativa, " "Odoo Community Association (OCA)",
|
||||
|
@ -20,8 +20,5 @@
|
|||
"views/report_certificate_view.xml",
|
||||
"views/res_company_view.xml",
|
||||
],
|
||||
"demo": [
|
||||
"demo/report_partner_demo.xml",
|
||||
"demo/report_certificate_demo.xml",
|
||||
],
|
||||
"demo": ["demo/report_partner_demo.xml", "demo/report_certificate_demo.xml"],
|
||||
}
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
<odoo>
|
||||
<record model="ir.config_parameter" id="report_qweb_signer_java_param">
|
||||
<field name="key">report_qweb_signer.java_parameters</field>
|
||||
<field name="value">-Xms4M -Xmx4M</field>
|
||||
<field name="value">-Xms4M -Xmx4M -XX:CompressedClassSpaceSize=256m</field>
|
||||
</record>
|
||||
</odoo>
|
||||
|
|
|
@ -11,7 +11,6 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|||
<field name="path">test.p12</field>
|
||||
<field name="password_file">test.passwd</field>
|
||||
<field name="model_id" ref="base.model_res_partner" />
|
||||
<field name="domain">[('customer', '=', True)]</field>
|
||||
<field name="allow_only_one" eval="True" />
|
||||
<field
|
||||
name="attachment"
|
||||
|
|
|
@ -10,7 +10,7 @@ import tempfile
|
|||
import time
|
||||
from contextlib import closing
|
||||
|
||||
from odoo import _, api, models
|
||||
from odoo import _, models
|
||||
from odoo.exceptions import AccessError, UserError
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
|
||||
|
@ -58,9 +58,7 @@ class IrActionsReport(models.Model):
|
|||
domain = domain + safe_eval(cert.domain)
|
||||
docs = self.env[cert.model_id.model].search(domain)
|
||||
if not docs:
|
||||
_logger.debug(
|
||||
"Certificate '%s' domain not satisfied", cert.name
|
||||
)
|
||||
_logger.debug("Certificate '%s' domain not satisfied", cert.name)
|
||||
continue
|
||||
# Certificate match!
|
||||
return cert
|
||||
|
@ -80,14 +78,14 @@ class IrActionsReport(models.Model):
|
|||
return False
|
||||
attachment = self.env["ir.attachment"].search(
|
||||
[
|
||||
("datas_fname", "=", filename),
|
||||
("name", "=", filename),
|
||||
("res_model", "=", certificate.model_id.model),
|
||||
("res_id", "=", res_ids[0]),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
if attachment:
|
||||
return base64.decodestring(attachment.datas)
|
||||
return base64.b64decode(attachment.datas)
|
||||
return False
|
||||
|
||||
def _attach_signed_write(self, res_ids, certificate, signed):
|
||||
|
@ -100,8 +98,7 @@ class IrActionsReport(models.Model):
|
|||
attachment = self.env["ir.attachment"].create(
|
||||
{
|
||||
"name": filename,
|
||||
"datas": base64.encodestring(signed),
|
||||
"datas_fname": filename,
|
||||
"datas": base64.b64encode(signed),
|
||||
"res_model": certificate.model_id.model,
|
||||
"res_id": res_ids[0],
|
||||
}
|
||||
|
@ -129,10 +126,7 @@ class IrActionsReport(models.Model):
|
|||
passwd = _normalize_filepath(certificate.password_file)
|
||||
if not (p12 and passwd):
|
||||
raise UserError(
|
||||
_(
|
||||
"Signing report (PDF): "
|
||||
"Certificate or password file not found"
|
||||
)
|
||||
_("Signing report (PDF): " "Certificate or password file not found")
|
||||
)
|
||||
signer_opts = '"{}" "{}" "{}" "{}"'.format(p12, pdf, pdfsigned, passwd)
|
||||
signer = self._signer_bin(signer_opts)
|
||||
|
@ -150,22 +144,18 @@ class IrActionsReport(models.Model):
|
|||
)
|
||||
return pdfsigned
|
||||
|
||||
@api.multi
|
||||
def render_qweb_pdf(self, res_ids=None, data=None):
|
||||
certificate = self._certificate_get(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",
|
||||
"The signed PDF document '%s/%s' was loaded from the " "database",
|
||||
self.report_name,
|
||||
res_ids,
|
||||
)
|
||||
return signed_content, "pdf"
|
||||
content, ext = super(IrActionsReport, self).render_qweb_pdf(
|
||||
res_ids, data
|
||||
)
|
||||
content, ext = super(IrActionsReport, self).render_qweb_pdf(res_ids, data)
|
||||
if certificate:
|
||||
# Creating temporary origin PDF
|
||||
pdf_fd, pdf = tempfile.mkstemp(suffix=".pdf", prefix="report.tmp.")
|
||||
|
|
|
@ -33,8 +33,7 @@ class ReportCertificate(models.Model):
|
|||
help="Model where apply this certificate",
|
||||
)
|
||||
domain = fields.Char(
|
||||
string="Domain",
|
||||
help="Domain for filtering if sign or not the document",
|
||||
string="Domain", help="Domain for filtering if sign or not the document",
|
||||
)
|
||||
allow_only_one = fields.Boolean(
|
||||
string="Allow only one document",
|
||||
|
|
|
@ -7,9 +7,7 @@ from odoo.tests.common import HttpCase
|
|||
class TestReportQwebSigner(HttpCase):
|
||||
def setUp(self):
|
||||
super(TestReportQwebSigner, self).setUp()
|
||||
self.partner = self.env["res.partner"].create(
|
||||
{"name": "Test partner", "customer": True}
|
||||
)
|
||||
self.partner = self.env["res.partner"].create({"name": "Test partner"})
|
||||
self.report = self.env.ref(
|
||||
"report_qweb_signer.partner_demo_report"
|
||||
).with_context(force_report_rendering=True)
|
||||
|
|
|
@ -55,7 +55,6 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|||
<record id="action_report_certificate" model="ir.actions.act_window">
|
||||
<field name="name">PDF certificates</field>
|
||||
<field name="res_model">report.certificate</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
</record>
|
||||
<menuitem
|
||||
|
|
Loading…
Reference in New Issue