From 0b73b7dffabc0b814f1558cecb9f400eff91b33d Mon Sep 17 00:00:00 2001 From: Denis Roussel Date: Mon, 20 Dec 2021 10:50:03 +0100 Subject: [PATCH 1/9] [14.0][IMP] base_report_to_printer: Add Text render document to printer --- .../models/ir_actions_report.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/base_report_to_printer/models/ir_actions_report.py b/base_report_to_printer/models/ir_actions_report.py index 1878344..0cabb65 100644 --- a/base_report_to_printer/models/ir_actions_report.py +++ b/base_report_to_printer/models/ir_actions_report.py @@ -159,3 +159,22 @@ class IrActionsReport(models.Model): ) return document, doc_format + + def _render_qweb_text(self, docids, data=None): + """Generate a TEXT file and returns it. + + If the action configured on the report is server, it prints the + generated document as well. + """ + document, doc_format = super()._render_qweb_text(docids=docids, data=data) + + behaviour = self.behaviour() + printer = behaviour.pop("printer", None) + can_print_report = self._can_print_report(behaviour, printer, document) + + if can_print_report: + printer.print_document( + self, document, doc_format=self.report_type, **behaviour + ) + + return document, doc_format From 69a2af2b22f1e9e82be6017f071b39e82f26b12c Mon Sep 17 00:00:00 2001 From: Denis Roussel Date: Wed, 29 Dec 2021 09:05:33 +0100 Subject: [PATCH 2/9] [14.0][FIX] base_report_to_printer: Manage text print_document() --- .../models/ir_actions_report.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/base_report_to_printer/models/ir_actions_report.py b/base_report_to_printer/models/ir_actions_report.py index 0cabb65..e6627ac 100644 --- a/base_report_to_printer/models/ir_actions_report.py +++ b/base_report_to_printer/models/ir_actions_report.py @@ -8,6 +8,8 @@ from odoo import _, api, exceptions, fields, models from odoo.tools.safe_eval import safe_eval, time +REPORT_TYPES = {"qweb-pdf": "pdf", "qweb-text": "text"} + class IrActionsReport(models.Model): _inherit = "ir.actions.report" @@ -98,10 +100,17 @@ class IrActionsReport(models.Model): return result def print_document(self, record_ids, data=None): - """Print a document, do not return the document file""" - document, doc_format = self.with_context( - must_skip_send_to_printer=True - )._render_qweb_pdf(record_ids, data=data) + """ Print a document, do not return the document file """ + report_type = REPORT_TYPES.get(self.report_type) + if not report_type: + raise exceptions.UserError( + _("This report type (%s) is not supported by direct printing!") + % str(self.report_type) + ) + method_name = "_render_qweb_%s" % (report_type) + document, doc_format = getattr( + self.with_context(must_skip_send_to_printer=True), method_name + )(record_ids, data=data) behaviour = self.behaviour() printer = behaviour.pop("printer", None) From d86f274c305c4c87bbec8732d10d105363072864 Mon Sep 17 00:00:00 2001 From: Denis Roussel Date: Wed, 29 Dec 2021 09:10:46 +0100 Subject: [PATCH 3/9] [14.0][IMP] base_report_to_printer: Add tests for text documents --- .../models/ir_actions_report.py | 2 +- base_report_to_printer/tests/test_report.py | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/base_report_to_printer/models/ir_actions_report.py b/base_report_to_printer/models/ir_actions_report.py index e6627ac..10d30b1 100644 --- a/base_report_to_printer/models/ir_actions_report.py +++ b/base_report_to_printer/models/ir_actions_report.py @@ -100,7 +100,7 @@ class IrActionsReport(models.Model): return result def print_document(self, record_ids, data=None): - """ Print a document, do not return the document file """ + """Print a document, do not return the document file""" report_type = REPORT_TYPES.get(self.report_type) if not report_type: raise exceptions.UserError( diff --git a/base_report_to_printer/tests/test_report.py b/base_report_to_printer/tests/test_report.py index 72ad9c5..cc6a0ea 100644 --- a/base_report_to_printer/tests/test_report.py +++ b/base_report_to_printer/tests/test_report.py @@ -47,6 +47,14 @@ class TestReport(common.HttpCase): "report_name": "base_report_to_printer.test", } ) + self.report_text = self.Model.create( + { + "name": "Test", + "report_type": "qweb-text", + "model": "res.partner", + "report_name": "base_report_to_printer.test", + } + ) self.partners = self.env["res.partner"] for n in range(5): self.partners += self.env["res.partner"].create({"name": "Test %d" % n}) @@ -113,6 +121,24 @@ class TestReport(common.HttpCase): tray=False, ) + def test_render_qweb_text_printable(self): + """It should print the report, only if it is printable""" + with mock.patch( + "odoo.addons.base_report_to_printer.models." + "printing_printer.PrintingPrinter." + "print_document" + ) as print_document: + self.report_text.property_printing_action_id.action_type = "server" + self.report_text.printing_printer_id = self.new_printer() + document = self.report_text._render_qweb_text(self.partners.ids) + print_document.assert_called_once_with( + self.report_text, + document[0], + action="server", + doc_format="qweb-text", + tray=False, + ) + def test_print_document_not_printable(self): """It should print the report, regardless of the defined behaviour""" self.report.printing_printer_id = self.new_printer() From 0414d9c4531ac3ef3ceccadb79323dad32d09afd Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Mon, 27 Apr 2020 14:36:35 +0200 Subject: [PATCH 4/9] [ADD] base_report_to_printer: Print attachments wizard --- base_report_to_printer/README.rst | 1 + base_report_to_printer/__manifest__.py | 1 + .../readme/CONTRIBUTORS.rst | 1 + .../static/description/index.html | 3 +- base_report_to_printer/wizards/__init__.py | 1 + .../wizards/print_attachment_report.py | 74 +++++++++++++++++++ .../wizards/print_attachment_report.xml | 50 +++++++++++++ 7 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 base_report_to_printer/wizards/print_attachment_report.py create mode 100644 base_report_to_printer/wizards/print_attachment_report.xml diff --git a/base_report_to_printer/README.rst b/base_report_to_printer/README.rst index ca78947..e46e8a5 100644 --- a/base_report_to_printer/README.rst +++ b/base_report_to_printer/README.rst @@ -155,6 +155,7 @@ Contributors * Rod Schouteden * Alexandre Fayolle * Matias Peralta +* Akim Juillerat Maintainers ~~~~~~~~~~~ diff --git a/base_report_to_printer/__manifest__.py b/base_report_to_printer/__manifest__.py index 61af227..1512214 100644 --- a/base_report_to_printer/__manifest__.py +++ b/base_report_to_printer/__manifest__.py @@ -24,6 +24,7 @@ "views/printing_report.xml", "views/res_users.xml", "views/ir_actions_report.xml", + "wizards/print_attachment_report.xml", "wizards/printing_printer_update_wizard_view.xml", ], "assets": { diff --git a/base_report_to_printer/readme/CONTRIBUTORS.rst b/base_report_to_printer/readme/CONTRIBUTORS.rst index 7085b17..a046d90 100644 --- a/base_report_to_printer/readme/CONTRIBUTORS.rst +++ b/base_report_to_printer/readme/CONTRIBUTORS.rst @@ -12,3 +12,4 @@ * Rod Schouteden * Alexandre Fayolle * Matias Peralta +* Akim Juillerat diff --git a/base_report_to_printer/static/description/index.html b/base_report_to_printer/static/description/index.html index fecf525..45e1510 100644 --- a/base_report_to_printer/static/description/index.html +++ b/base_report_to_printer/static/description/index.html @@ -3,7 +3,7 @@ - + Report to printer