diff --git a/report_py3o_signer/README.rst b/report_py3o_signer/README.rst new file mode 100644 index 0000000000..243f7f833f --- /dev/null +++ b/report_py3o_signer/README.rst @@ -0,0 +1,90 @@ +.. 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 + +================== +Report Py3o Signer +================== + +Sign Py3o PDF's using PKCS#12 certificate + +Installation +============ + +To install this module, you need to: + +#. Do this ... + +Configuration +============= + +To configure this module, you need to: + +#. Go to ... + +.. figure:: path/to/local/image.png + :alt: alternative description + :width: 600 px + +Usage +===== + +To use this module, you need to: + +#. Go to ... + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/{repo_id}/{branch} + +.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt +.. branch is "8.0" for example + +Known issues / Roadmap +====================== + + +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 smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Firstname Lastname +* Second Person + +Funders +------- + +The development of this module has been financially supported by: + +* Company 1 name +* Company 2 name + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/report_py3o_signer/__init__.py b/report_py3o_signer/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/report_py3o_signer/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/report_py3o_signer/__manifest__.py b/report_py3o_signer/__manifest__.py new file mode 100644 index 0000000000..74e290f2a5 --- /dev/null +++ b/report_py3o_signer/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2021 Acsone SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Report Py3o Signer", + "summary": """ + Sign Py3o PDF's using PKCS#12 certificate""", + "version": "13.0.1.0.0", + "license": "AGPL-3", + "author": "Acsone SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/reporting-engine", + "depends": ["report_qweb_signer", "report_py3o"], + "data": [], + "demo": [], +} diff --git a/report_py3o_signer/models/__init__.py b/report_py3o_signer/models/__init__.py new file mode 100644 index 0000000000..1728defe72 --- /dev/null +++ b/report_py3o_signer/models/__init__.py @@ -0,0 +1,2 @@ +from . import ir_actions_report +from . import py3o_report diff --git a/report_py3o_signer/models/ir_actions_report.py b/report_py3o_signer/models/ir_actions_report.py new file mode 100644 index 0000000000..75b600d9b3 --- /dev/null +++ b/report_py3o_signer/models/ir_actions_report.py @@ -0,0 +1,16 @@ +# Copyright 2021 Acsone SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import logging + +from odoo import models + +_logger = logging.getLogger(__name__) + + +class IrActionReport(models.Model): + _inherit = "ir.actions.report" + + def _is_report_type_signable(self): + res = super()._is_report_type_signable() + return res or (self.report_type == "py3o") diff --git a/report_py3o_signer/models/py3o_report.py b/report_py3o_signer/models/py3o_report.py new file mode 100644 index 0000000000..6f6a16fce4 --- /dev/null +++ b/report_py3o_signer/models/py3o_report.py @@ -0,0 +1,30 @@ +# Copyright 2021 Acsone SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import logging +import os + +from odoo import models + +_logger = logging.getLogger(__name__) + + +class Py3oReport(models.TransientModel): + _inherit = "py3o.report" + + def _postprocess_report(self, model_instance, result_path): + certificate = self.ir_actions_report_id._certificate_get(model_instance.ids) + if not certificate: + return super()._postprocess_report(model_instance, result_path) + _logger.debug( + "Signing PDF document '%s' for ID %s with certificate '%s'", + self.ir_actions_report_id.report_name, + model_instance.id, + certificate.name, + ) + signed = self.ir_actions_report_id.pdf_sign(result_path, certificate) + try: + os.unlink(result_path) + except (OSError, IOError): + _logger.error("Error when trying to remove file %s", result_path) + return super()._postprocess_report(model_instance, signed) diff --git a/report_py3o_signer/static/description/icon.png b/report_py3o_signer/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/report_py3o_signer/static/description/icon.png differ diff --git a/report_qweb_signer/models/ir_actions_report.py b/report_qweb_signer/models/ir_actions_report.py index 771ae0f04d..b3a659d3c5 100644 --- a/report_qweb_signer/models/ir_actions_report.py +++ b/report_qweb_signer/models/ir_actions_report.py @@ -30,9 +30,12 @@ def _normalize_filepath(path): class IrActionsReport(models.Model): _inherit = "ir.actions.report" + def _is_report_type_signable(self): + return self.report_type == "qweb-pdf" + def _certificate_get(self, res_ids): """Obtain the proper certificate for the report and the conditions.""" - if self.report_type != "qweb-pdf": + if not self._is_report_type_signable(): return False certificates = self.env["report.certificate"].search( [ diff --git a/setup/report_py3o_signer/odoo/addons/report_py3o_signer b/setup/report_py3o_signer/odoo/addons/report_py3o_signer new file mode 120000 index 0000000000..9c12aee556 --- /dev/null +++ b/setup/report_py3o_signer/odoo/addons/report_py3o_signer @@ -0,0 +1 @@ +../../../../report_py3o_signer \ No newline at end of file diff --git a/setup/report_py3o_signer/setup.py b/setup/report_py3o_signer/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/report_py3o_signer/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)