From d86f274c305c4c87bbec8732d10d105363072864 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 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()