From f7dd12d0a66499e7aecd941b66014b63ce20d904 Mon Sep 17 00:00:00 2001 From: Denis Roussel Date: Wed, 29 Dec 2021 09:10:46 +0100 Subject: [PATCH] [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 99f4172..90f371f 100644 --- a/base_report_to_printer/models/ir_actions_report.py +++ b/base_report_to_printer/models/ir_actions_report.py @@ -101,7 +101,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 876d5f1..381ad5b 100644 --- a/base_report_to_printer/tests/test_report.py +++ b/base_report_to_printer/tests/test_report.py @@ -43,6 +43,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}) @@ -109,6 +117,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()