mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[MIG] report_qweb_designer: Migration to 12.0
This commit is contained in:
@@ -1,22 +1,44 @@
|
|||||||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
|
||||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
|
||||||
:alt: License: AGPL-3
|
|
||||||
|
|
||||||
=======================
|
=======================
|
||||||
Qweb PDF reports signer
|
Qweb PDF reports signer
|
||||||
=======================
|
=======================
|
||||||
|
|
||||||
|
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
!! This file is generated by oca-gen-addon-readme !!
|
||||||
|
!! changes will be overwritten. !!
|
||||||
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
|
||||||
|
:target: https://odoo-community.org/page/development-status
|
||||||
|
:alt: Beta
|
||||||
|
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
|
||||||
|
: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/12.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-12-0/reporting-engine-12-0-report_qweb_signer
|
||||||
|
:alt: Translate me on Weblate
|
||||||
|
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
|
||||||
|
:target: https://runbot.odoo-community.org/runbot/143/12.0
|
||||||
|
:alt: Try me on Runbot
|
||||||
|
|
||||||
|
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||||
|
|
||||||
This module extends the functionality of report module to sign
|
This module extends the functionality of report module to sign
|
||||||
PDFs using a PKCS#12 certificate.
|
PDFs using a PKCS#12 certificate.
|
||||||
|
|
||||||
|
**Table of contents**
|
||||||
|
|
||||||
|
.. contents::
|
||||||
|
:local:
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
============
|
============
|
||||||
|
|
||||||
To install this module, you need to install Java JDK::
|
To install this module, you need to install Java JDK Headlees, e.g.:
|
||||||
|
|
||||||
apt-get install openjdk-7-jre-headless
|
|
||||||
|
|
||||||
|
apt-get install openjdk-8-jre-headless
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
=============
|
=============
|
||||||
@@ -42,7 +64,7 @@ For example, if you want to sign only customer invoices in open or paid state:
|
|||||||
read access to certificate file and password file
|
read access to certificate file and password file
|
||||||
|
|
||||||
Java Memory Settings
|
Java Memory Settings
|
||||||
--------------------
|
~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
If you are signing large amounts of reports at the same time, or if you have a
|
If you are signing large amounts of reports at the same time, or if you have a
|
||||||
lower worker memory size than the JVM defaults, you may need to tune the JVM
|
lower worker memory size than the JVM defaults, you may need to tune the JVM
|
||||||
@@ -66,10 +88,6 @@ when signing date is important, for example, when signing customer invoices.
|
|||||||
You can try the signing with the demo report that is included for customers
|
You can try the signing with the demo report that is included for customers
|
||||||
called "Test PDF certificate".
|
called "Test PDF certificate".
|
||||||
|
|
||||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
|
||||||
:alt: Try me on Runbot
|
|
||||||
:target: https://runbot.odoo-community.org/runbot/143/10.0
|
|
||||||
|
|
||||||
Known issues / Roadmap
|
Known issues / Roadmap
|
||||||
======================
|
======================
|
||||||
|
|
||||||
@@ -79,50 +97,63 @@ Known issues / Roadmap
|
|||||||
* To have a visible signature through an image embedded in the resulting PDF.
|
* To have a visible signature through an image embedded in the resulting PDF.
|
||||||
* Add tests.
|
* Add tests.
|
||||||
|
|
||||||
|
|
||||||
Bug Tracker
|
Bug Tracker
|
||||||
===========
|
===========
|
||||||
|
|
||||||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_.
|
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.
|
In case of trouble, please check there if your issue has already been reported.
|
||||||
If you spotted it first, help us smashing it by providing a detailed and
|
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||||
welcomed feedback `here <https://github.com/OCA/reporting-engine/issues/new>`_.
|
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_qweb_signer%0Aversion:%2012.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.
|
||||||
|
|
||||||
Credits
|
Credits
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
Authors
|
||||||
|
~~~~~~~
|
||||||
|
|
||||||
|
* Tecnativa
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
|
* `Tecnativa <https://www.tecnativa.com>`_:
|
||||||
|
|
||||||
|
* Rafael Blasco
|
||||||
|
* Antonio Espinosa
|
||||||
|
* Pedro M. Baeza
|
||||||
|
* Jairo Llopis
|
||||||
|
* David Vidal
|
||||||
|
|
||||||
|
Other credits
|
||||||
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
External utilities
|
External utilities
|
||||||
------------------
|
++++++++++++++++++
|
||||||
|
|
||||||
* iText v1.4.8: © 2000-2006, Paulo Soares, Bruno Lowagie and others - License `MPL <http://www.mozilla.org/MPL>`__ or `LGPL2 <http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>`__ - http://sourceforge.net/projects/itext
|
* iText v1.4.8: © 2000-2006, Paulo Soares, Bruno Lowagie and others - License `MPL <http://www.mozilla.org/MPL>`__ or `LGPL2 <http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>`__ - http://sourceforge.net/projects/itext
|
||||||
* jPdfSign: © 2006 Jan Peter Stotz - License `MPL <http://www.mozilla.org/MPL>`__ or `LGPL2 <http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>`__ (inherited from iText) - http://private.sit.fraunhofer.de/~stotz/software/jpdfsign
|
* jPdfSign: © 2006 Jan Peter Stotz - License `MPL <http://www.mozilla.org/MPL>`__ or `LGPL2 <http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>`__ (inherited from iText) - http://private.sit.fraunhofer.de/~stotz/software/jpdfsign
|
||||||
* Modified jPdfSign: © 2015 Antonio Espinosa - License `MPL <http://www.mozilla.org/MPL>`__ or `LGPL2 <http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>`__ (inherited from iText) - static/src/java/JPdfSign.java
|
* Modified jPdfSign: © 2015 Antonio Espinosa - License `MPL <http://www.mozilla.org/MPL>`__ or `LGPL2 <http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>`__ (inherited from iText) - static/src/java/JPdfSign.java
|
||||||
|
|
||||||
Icon
|
Icon
|
||||||
----
|
++++
|
||||||
|
|
||||||
`Created by Anton Noskov from the Noun Project <https://thenounproject.com/search/?q=signed+contract&i=65694>`__
|
`Created by Anton Noskov from the Noun Project <https://thenounproject.com/search/?q=signed+contract&i=65694>`__
|
||||||
|
|
||||||
Contributors
|
Maintainers
|
||||||
------------
|
~~~~~~~~~~~
|
||||||
|
|
||||||
* Rafael Blasco <rafael.blasco@tecnativa.com>
|
This module is maintained by the OCA.
|
||||||
* Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
|
||||||
* Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
|
||||||
* Jairo Llopis <jairo.llopis@tecnativa.com>
|
|
||||||
|
|
||||||
Maintainer
|
|
||||||
----------
|
|
||||||
|
|
||||||
.. image:: https://odoo-community.org/logo.png
|
.. image:: https://odoo-community.org/logo.png
|
||||||
:alt: Odoo Community Association
|
:alt: Odoo Community Association
|
||||||
:target: https://odoo-community.org
|
:target: https://odoo-community.org
|
||||||
|
|
||||||
This module is maintained by the OCA.
|
|
||||||
|
|
||||||
OCA, or the Odoo Community Association, is a nonprofit organization whose
|
OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||||
mission is to support the collaborative development of Odoo features and
|
mission is to support the collaborative development of Odoo features and
|
||||||
promote its widespread use.
|
promote its widespread use.
|
||||||
|
|
||||||
To contribute to this module, please visit https://odoo-community.org.
|
This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/12.0/report_qweb_signer>`_ project on GitHub.
|
||||||
|
|
||||||
|
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
|||||||
@@ -1,25 +1,26 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright 2015 Tecnativa - Antonio Espinosa
|
# Copyright 2015 Tecnativa - Antonio Espinosa
|
||||||
# Copyright 2017 Tecnativa - Pedro M. Baeza
|
# Copyright 2017 Tecnativa - Pedro M. Baeza
|
||||||
|
# Copyright 2018 Tecnativa - David Vidal
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "Qweb PDF reports signer",
|
"name": "Qweb PDF reports signer",
|
||||||
"summary": "Sign Qweb PDFs usign a PKCS#12 certificate",
|
"summary": "Sign Qweb PDFs usign a PKCS#12 certificate",
|
||||||
"version": "10.0.1.0.1",
|
"version": "12.0.1.0.0",
|
||||||
"category": "Reporting",
|
"category": "Reporting",
|
||||||
"website": "https://www.tecnativa.com",
|
"website": "https://www.github.com/reporting-engine",
|
||||||
"author": "Tecnativa, "
|
"author": "Tecnativa, "
|
||||||
"Odoo Community Association (OCA)",
|
"Odoo Community Association (OCA)",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"installable": True,
|
"installable": True,
|
||||||
"depends": [
|
"depends": [
|
||||||
"report",
|
"web",
|
||||||
],
|
],
|
||||||
"external_dependencies": {
|
"external_dependencies": {
|
||||||
"bin": ['/usr/bin/java'],
|
"bin": ['/usr/bin/java'],
|
||||||
},
|
},
|
||||||
"data": [
|
"data": [
|
||||||
|
"data/defaults.xml",
|
||||||
"security/ir.model.access.csv",
|
"security/ir.model.access.csv",
|
||||||
"views/report_certificate_view.xml",
|
"views/report_certificate_view.xml",
|
||||||
"views/res_company_view.xml",
|
"views/res_company_view.xml",
|
||||||
|
|||||||
7
report_qweb_signer/data/defaults.xml
Normal file
7
report_qweb_signer/data/defaults.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<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>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
@@ -7,7 +7,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|||||||
<odoo>
|
<odoo>
|
||||||
|
|
||||||
<template id="report_partner_demo_document">
|
<template id="report_partner_demo_document">
|
||||||
<t t-call="report.external_layout">
|
<t t-call="web.external_layout">
|
||||||
<div class="page">
|
<div class="page">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
@@ -24,7 +24,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template id="report_partner_demo">
|
<template id="report_partner_demo">
|
||||||
<t t-call="report.html_container">
|
<t t-call="web.html_container">
|
||||||
<t t-foreach="docs" t-as="o">
|
<t t-foreach="docs" t-as="o">
|
||||||
<t t-call="report_qweb_signer.report_partner_demo_document" t-lang="o.lang"/>
|
<t t-call="report_qweb_signer.report_partner_demo_document" t-lang="o.lang"/>
|
||||||
</t>
|
</t>
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# © 2015 Antiun Ingenieria S.L. - Antonio Espinosa
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from . import report
|
from . import ir_actions_report
|
||||||
from . import report_certificate
|
from . import report_certificate
|
||||||
from . import res_company
|
from . import res_company
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright 2015 Tecnativa - Antonio Espinosa
|
# Copyright 2015 Tecnativa - Antonio Espinosa
|
||||||
# Copyright 2017 Tecnativa - Pedro M. Baeza
|
# Copyright 2017 Tecnativa - Pedro M. Baeza
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
@@ -28,16 +27,16 @@ def _normalize_filepath(path):
|
|||||||
return path if os.path.exists(path) else False
|
return path if os.path.exists(path) else False
|
||||||
|
|
||||||
|
|
||||||
class Report(models.Model):
|
class IrActionsReport(models.Model):
|
||||||
_inherit = 'report'
|
_inherit = 'ir.actions.report'
|
||||||
|
|
||||||
def _certificate_get(self, report, docids):
|
def _certificate_get(self, res_ids):
|
||||||
"""Obtain the proper certificate for the report and the conditions."""
|
"""Obtain the proper certificate for the report and the conditions."""
|
||||||
if report.report_type != 'qweb-pdf':
|
if self.report_type != 'qweb-pdf':
|
||||||
return False
|
return False
|
||||||
certificates = self.env['report.certificate'].search([
|
certificates = self.env['report.certificate'].search([
|
||||||
('company_id', '=', self.env.user.company_id.id),
|
('company_id', '=', self.env.user.company_id.id),
|
||||||
('model_id', '=', report.model),
|
('model_id', '=', self.model),
|
||||||
])
|
])
|
||||||
if not certificates:
|
if not certificates:
|
||||||
return False
|
return False
|
||||||
@@ -47,11 +46,11 @@ class Report(models.Model):
|
|||||||
_logger.debug(
|
_logger.debug(
|
||||||
"Certificate '%s' allows only one document, "
|
"Certificate '%s' allows only one document, "
|
||||||
"but printing %d documents",
|
"but printing %d documents",
|
||||||
cert.name, len(docids))
|
cert.name, len(res_ids))
|
||||||
continue
|
continue
|
||||||
# Check domain
|
# Check domain
|
||||||
if cert.domain:
|
if cert.domain:
|
||||||
domain = [('id', 'in', tuple(docids))]
|
domain = [('id', 'in', tuple(res_ids))]
|
||||||
domain = domain + safe_eval(cert.domain)
|
domain = domain + safe_eval(cert.domain)
|
||||||
docs = self.env[cert.model_id.model].search(domain)
|
docs = self.env[cert.model_id.model].search(domain)
|
||||||
if not docs:
|
if not docs:
|
||||||
@@ -62,34 +61,34 @@ class Report(models.Model):
|
|||||||
return cert
|
return cert
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _attach_filename_get(self, docids, certificate):
|
def _attach_filename_get(self, res_ids, certificate):
|
||||||
if len(docids) != 1:
|
if len(res_ids) != 1:
|
||||||
return False
|
return False
|
||||||
doc = self.env[certificate.model_id.model].browse(docids[0])
|
doc = self.env[certificate.model_id.model].browse(res_ids[0])
|
||||||
return safe_eval(certificate.attachment, {
|
return safe_eval(certificate.attachment, {
|
||||||
'object': doc,
|
'object': doc,
|
||||||
'time': time
|
'time': time
|
||||||
})
|
})
|
||||||
|
|
||||||
def _attach_signed_read(self, docids, certificate):
|
def _attach_signed_read(self, res_ids, certificate):
|
||||||
if len(docids) != 1:
|
if len(res_ids) != 1:
|
||||||
return False
|
return False
|
||||||
filename = self._attach_filename_get(docids, certificate)
|
filename = self._attach_filename_get(res_ids, certificate)
|
||||||
if not filename:
|
if not filename:
|
||||||
return False
|
return False
|
||||||
attachment = self.env['ir.attachment'].search([
|
attachment = self.env['ir.attachment'].search([
|
||||||
('datas_fname', '=', filename),
|
('datas_fname', '=', filename),
|
||||||
('res_model', '=', certificate.model_id.model),
|
('res_model', '=', certificate.model_id.model),
|
||||||
('res_id', '=', docids[0]),
|
('res_id', '=', res_ids[0]),
|
||||||
], limit=1)
|
], limit=1)
|
||||||
if attachment:
|
if attachment:
|
||||||
return base64.decodestring(attachment.datas)
|
return base64.decodestring(attachment.datas)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _attach_signed_write(self, docids, certificate, signed):
|
def _attach_signed_write(self, res_ids, certificate, signed):
|
||||||
if len(docids) != 1:
|
if len(res_ids) != 1:
|
||||||
return False
|
return False
|
||||||
filename = self._attach_filename_get(docids, certificate)
|
filename = self._attach_filename_get(res_ids, certificate)
|
||||||
if not filename:
|
if not filename:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
@@ -98,7 +97,7 @@ class Report(models.Model):
|
|||||||
'datas': base64.encodestring(signed),
|
'datas': base64.encodestring(signed),
|
||||||
'datas_fname': filename,
|
'datas_fname': filename,
|
||||||
'res_model': certificate.model_id.model,
|
'res_model': certificate.model_id.model,
|
||||||
'res_id': docids[0],
|
'res_id': res_ids[0],
|
||||||
})
|
})
|
||||||
except AccessError:
|
except AccessError:
|
||||||
raise UserError(
|
raise UserError(
|
||||||
@@ -108,9 +107,11 @@ class Report(models.Model):
|
|||||||
|
|
||||||
def _signer_bin(self, opts):
|
def _signer_bin(self, opts):
|
||||||
me = os.path.dirname(__file__)
|
me = os.path.dirname(__file__)
|
||||||
|
irc_param = self.env['ir.config_parameter'].sudo()
|
||||||
java_bin = 'java -jar'
|
java_bin = 'java -jar'
|
||||||
|
java_param = irc_param.get_param('report_qweb_signer.java_parameters')
|
||||||
jar = '{}/../static/jar/jPdfSign.jar'.format(me)
|
jar = '{}/../static/jar/jPdfSign.jar'.format(me)
|
||||||
return '%s %s %s' % (java_bin, jar, opts)
|
return '%s %s %s %s' % (java_bin, java_param, jar, opts)
|
||||||
|
|
||||||
def pdf_sign(self, pdf, certificate):
|
def pdf_sign(self, pdf, certificate):
|
||||||
pdfsigned = pdf + '.signed.pdf'
|
pdfsigned = pdf + '.signed.pdf'
|
||||||
@@ -132,30 +133,28 @@ class Report(models.Model):
|
|||||||
(process.returncode, err, out))
|
(process.returncode, err, out))
|
||||||
return pdfsigned
|
return pdfsigned
|
||||||
|
|
||||||
@api.model
|
@api.multi
|
||||||
def get_pdf(self, docids, report_name, html=None, data=None):
|
def render_qweb_pdf(self, res_ids=None, data=None):
|
||||||
report = self._get_report_from_name(report_name)
|
certificate = self._certificate_get(res_ids)
|
||||||
certificate = self._certificate_get(report, docids)
|
|
||||||
if certificate and certificate.attachment:
|
if certificate and certificate.attachment:
|
||||||
signed_content = self._attach_signed_read(docids, certificate)
|
signed_content = self._attach_signed_read(res_ids, certificate)
|
||||||
if signed_content:
|
if signed_content:
|
||||||
_logger.debug(
|
_logger.debug(
|
||||||
"The signed PDF document '%s/%s' was loaded from the "
|
"The signed PDF document '%s/%s' was loaded from the "
|
||||||
"database", report_name, docids,
|
"database", self.report_name, res_ids,
|
||||||
)
|
)
|
||||||
return signed_content
|
return signed_content
|
||||||
content = super(Report, self).get_pdf(
|
content, ext = super(IrActionsReport, self).render_qweb_pdf(res_ids,
|
||||||
docids, report_name, html=html, data=data,
|
data)
|
||||||
)
|
|
||||||
if certificate:
|
if certificate:
|
||||||
# Creating temporary origin PDF
|
# Creating temporary origin PDF
|
||||||
pdf_fd, pdf = tempfile.mkstemp(
|
pdf_fd, pdf = tempfile.mkstemp(
|
||||||
suffix='.pdf', prefix='report.tmp.')
|
suffix='.pdf', prefix='report.tmp.')
|
||||||
with closing(os.fdopen(pdf_fd, 'w')) as pf:
|
with closing(os.fdopen(pdf_fd, 'wb')) as pf:
|
||||||
pf.write(content)
|
pf.write(content)
|
||||||
_logger.debug(
|
_logger.debug(
|
||||||
"Signing PDF document '%s' for IDs %s with certificate '%s'",
|
"Signing PDF document '%s' for IDs %s with certificate '%s'",
|
||||||
report_name, docids, certificate.name,
|
self.report_name, res_ids, certificate.name,
|
||||||
)
|
)
|
||||||
signed = self.pdf_sign(pdf, certificate)
|
signed = self.pdf_sign(pdf, certificate)
|
||||||
# Read signed PDF
|
# Read signed PDF
|
||||||
@@ -169,5 +168,5 @@ class Report(models.Model):
|
|||||||
except (OSError, IOError):
|
except (OSError, IOError):
|
||||||
_logger.error('Error when trying to remove file %s', fname)
|
_logger.error('Error when trying to remove file %s', fname)
|
||||||
if certificate.attachment:
|
if certificate.attachment:
|
||||||
self._attach_signed_write(docids, certificate, content)
|
self._attach_signed_write(res_ids, certificate, content)
|
||||||
return content
|
return content, ext
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# Copyright 2015 Tecnativa - Antonio Espinosa
|
||||||
# © 2015 Antiun Ingenieria S.L. - Antonio Espinosa
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from odoo import api, fields, models
|
from odoo import api, fields, models
|
||||||
@@ -7,6 +6,7 @@ from odoo import api, fields, models
|
|||||||
|
|
||||||
class ReportCertificate(models.Model):
|
class ReportCertificate(models.Model):
|
||||||
_name = 'report.certificate'
|
_name = 'report.certificate'
|
||||||
|
_description = 'Report Certificate'
|
||||||
_order = 'sequence,id'
|
_order = 'sequence,id'
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# Copyright 2015 Tecnativa - Antonio Espinosa
|
||||||
# © 2015 Antiun Ingenieria S.L. - Antonio Espinosa
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from odoo import models, fields
|
from odoo import models, fields
|
||||||
|
|||||||
30
report_qweb_signer/readme/CONFIGURE.rst
Normal file
30
report_qweb_signer/readme/CONFIGURE.rst
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
In order to start signing PDF documents you need to configure certificate(s)
|
||||||
|
to use in your company.
|
||||||
|
|
||||||
|
* Go to ``Settings > Companies > Companies > Your company``
|
||||||
|
* Go to ``Report configuration`` tab
|
||||||
|
* Click ``Edit``
|
||||||
|
* Add a new item in ``PDF report certificates`` list
|
||||||
|
* Click ``Create``
|
||||||
|
* Set name, certificate file, password file and model
|
||||||
|
* Optionally you can set a domain and filename pattern for saving as attachment
|
||||||
|
|
||||||
|
For example, if you want to sign only customer invoices in open or paid state:
|
||||||
|
|
||||||
|
* Model: ``account.invoice``
|
||||||
|
* Domain: ``[('type','=','out_invoice'), ('state', 'in', ('open', 'paid'))]``
|
||||||
|
* Save as attachment: ``(object.number or '').replace('/','_') + '.signed.pdf'``
|
||||||
|
|
||||||
|
**Note**: Linux user that executes Odoo server process must have
|
||||||
|
read access to certificate file and password file
|
||||||
|
|
||||||
|
Java Memory Settings
|
||||||
|
~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
If you are signing large amounts of reports at the same time, or if you have a
|
||||||
|
lower worker memory size than the JVM defaults, you may need to tune the JVM
|
||||||
|
heap memory limits. Do so by adding a ``$JVM_ARGS`` environment variable that
|
||||||
|
contains the required flags. Check out these links too:
|
||||||
|
|
||||||
|
- `StackOverflow answer <https://stackoverflow.com/a/14763095/1468388>`_.
|
||||||
|
- `Java docs <https://docs.oracle.com/cd/E15523_01/web.1111/e13814/jvm_tuning.htm#PERFM161>`_.
|
||||||
7
report_qweb_signer/readme/CONTRIBUTORS.rst
Normal file
7
report_qweb_signer/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
* `Tecnativa <https://www.tecnativa.com>`_:
|
||||||
|
|
||||||
|
* Rafael Blasco
|
||||||
|
* Antonio Espinosa
|
||||||
|
* Pedro M. Baeza
|
||||||
|
* Jairo Llopis
|
||||||
|
* David Vidal
|
||||||
11
report_qweb_signer/readme/CREDITS.rst
Normal file
11
report_qweb_signer/readme/CREDITS.rst
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
External utilities
|
||||||
|
++++++++++++++++++
|
||||||
|
|
||||||
|
* iText v1.4.8: © 2000-2006, Paulo Soares, Bruno Lowagie and others - License `MPL <http://www.mozilla.org/MPL>`__ or `LGPL2 <http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>`__ - http://sourceforge.net/projects/itext
|
||||||
|
* jPdfSign: © 2006 Jan Peter Stotz - License `MPL <http://www.mozilla.org/MPL>`__ or `LGPL2 <http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>`__ (inherited from iText) - http://private.sit.fraunhofer.de/~stotz/software/jpdfsign
|
||||||
|
* Modified jPdfSign: © 2015 Antonio Espinosa - License `MPL <http://www.mozilla.org/MPL>`__ or `LGPL2 <http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html>`__ (inherited from iText) - static/src/java/JPdfSign.java
|
||||||
|
|
||||||
|
Icon
|
||||||
|
++++
|
||||||
|
|
||||||
|
`Created by Anton Noskov from the Noun Project <https://thenounproject.com/search/?q=signed+contract&i=65694>`__
|
||||||
2
report_qweb_signer/readme/DESCRIPTION.rst
Normal file
2
report_qweb_signer/readme/DESCRIPTION.rst
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
This module extends the functionality of report module to sign
|
||||||
|
PDFs using a PKCS#12 certificate.
|
||||||
3
report_qweb_signer/readme/INSTALL.rst
Normal file
3
report_qweb_signer/readme/INSTALL.rst
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
To install this module, you need to install Java JDK Headlees, e.g.:
|
||||||
|
|
||||||
|
apt-get install openjdk-8-jre-headless
|
||||||
5
report_qweb_signer/readme/ROADMAP.rst
Normal file
5
report_qweb_signer/readme/ROADMAP.rst
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
* When signing multiple documents (if 'Allow only one document' is disable)
|
||||||
|
then 'Save as attachment' is not applied and signed result is not
|
||||||
|
saved as attachment.
|
||||||
|
* To have a visible signature through an image embedded in the resulting PDF.
|
||||||
|
* Add tests.
|
||||||
10
report_qweb_signer/readme/USAGE.rst
Normal file
10
report_qweb_signer/readme/USAGE.rst
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
User just prints PDF documents (only Qweb PDF reports supported) as usual,
|
||||||
|
but signed PDF is automatically downloaded if this document model is configured
|
||||||
|
as indicated above.
|
||||||
|
|
||||||
|
If 'Save as attachment' is configured, signed PDF is saved as attachment and
|
||||||
|
next time saved one is downloaded without signing again. This is appropiate
|
||||||
|
when signing date is important, for example, when signing customer invoices.
|
||||||
|
|
||||||
|
You can try the signing with the demo report that is included for customers
|
||||||
|
called "Test PDF certificate".
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from . import test_report_qweb_signer
|
from . import test_report_qweb_signer
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright 2017 Tecnativa - Pedro M. Baeza
|
# Copyright 2017 Tecnativa - Pedro M. Baeza
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
@@ -15,10 +14,6 @@ class TestReportQwebSigner(HttpCase):
|
|||||||
self.report = self.env.ref('report_qweb_signer.partner_demo_report')
|
self.report = self.env.ref('report_qweb_signer.partner_demo_report')
|
||||||
|
|
||||||
def test_report_qweb_signer(self):
|
def test_report_qweb_signer(self):
|
||||||
self.env['report'].get_pdf(
|
self.report.render_qweb_pdf(self.partner.ids)
|
||||||
self.partner.ids, self.report.report_name, data={},
|
|
||||||
)
|
|
||||||
# Reprint again for taking the PDF from attachment
|
# Reprint again for taking the PDF from attachment
|
||||||
self.env['report'].get_pdf(
|
self.report.render_qweb_pdf(self.partner.ids)
|
||||||
self.partner.ids, self.report.report_name, data={},
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|||||||
|
|
||||||
<menuitem id="menu_report_certificate"
|
<menuitem id="menu_report_certificate"
|
||||||
name="PDF certificates"
|
name="PDF certificates"
|
||||||
parent="report.reporting_menuitem"
|
parent="base.reporting_menuitem"
|
||||||
action="action_report_certificate"/>
|
action="action_report_certificate"/>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|||||||
Reference in New Issue
Block a user