[14.0][IMP] base_report_to_printer: Add tests for text documents

This commit is contained in:
Denis Roussel
2021-12-29 09:10:46 +01:00
parent a716e134b9
commit f7dd12d0a6
2 changed files with 27 additions and 1 deletions

View File

@@ -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(

View File

@@ -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()