Maintainers
+Maintainers
This module is maintained by the OCA.
diff --git a/base_report_to_printer/static/src/js/qweb_action_manager.esm.js b/base_report_to_printer/static/src/js/qweb_action_manager.esm.js
index 370fd94..c75a7ba 100644
--- a/base_report_to_printer/static/src/js/qweb_action_manager.esm.js
+++ b/base_report_to_printer/static/src/js/qweb_action_manager.esm.js
@@ -1,4 +1,5 @@
/** @odoo-module */
+import {Markup} from "web.utils";
import {registry} from "@web/core/registry";
async function cupsReportActionHandler(action, options, env) {
@@ -8,36 +9,73 @@ async function cupsReportActionHandler(action, options, env) {
const print_action = await orm.call(
"ir.actions.report",
"print_action_for_report_name",
- [action.report_name]
+ [action.report_name],
+ {context: {force_print_to_client: action.context.force_print_to_client}}
);
- if (
- print_action &&
- print_action.action === "server" &&
- !print_action.printer_exception
- ) {
- const result = await orm.call("ir.actions.report", "print_document", [
- action.id,
- action.context.active_ids,
- action.data,
- ]);
+ var printer_exception = print_action.printer_exception;
+ if (print_action && print_action.action === "server" && !printer_exception) {
+ // The Odoo CUPS backend is ok. We try to print into the printer
+ const result = await orm.call(
+ "ir.actions.report",
+ "print_document_client_action",
+ [action.id, action.context.active_ids, action.data]
+ );
if (result) {
env.services.notification.add(env._t("Successfully sent to printer!"), {
type: "success",
});
- } else {
- env.services.notification.add(env._t("Could not send to printer!"), {
- type: "danger",
- });
+ return true;
+ // In case of exception during the job, we won't get any response. So we
+ // should flag the exception and notify the user
}
- return true;
+ env.services.notification.add(env._t("Could not sent to printer!"), {
+ type: "danger",
+ });
+ printer_exception = true;
}
- if (print_action.printer_exception) {
- env.services.notification.add(
- env._t("The printer couldn't be reached. Downloading document instead"),
+ if (print_action && print_action.action === "server" && printer_exception) {
+ // Just so the translation engine detects them as it doesn't do it inside
+ // template strings
+ const terms = {
+ the_report: env._t("The report"),
+ couldnt_be_printed: env._t(
+ "couldn't be printed. Click on the button below to download it"
+ ),
+ issue_on: env._t("Issue on"),
+ };
+ const notificationRemove = env.services.notification.add(
+ Markup(
+ `${terms.the_report} ${action.name} ${terms.couldnt_be_printed}
` + ), { + title: `${terms.issue_on} ${print_action.printer_name}`, type: "warning", + sticky: true, + messageIsHtml: true, + buttons: [ + { + name: env._t("Print"), + primary: true, + icon: "fa-print", + onClick: async () => { + const context = { + force_print_to_client: true, + must_skip_send_to_printer: true, + }; + env.services.user.updateContext(context); + await env.services.action.doAction( + {type: "ir.actions.report", ...action}, + { + additionalContext: context, + } + ); + notificationRemove(); + }, + }, + ], } ); + return true; } } } diff --git a/base_report_to_printer/tests/test_ir_actions_report.py b/base_report_to_printer/tests/test_ir_actions_report.py index e010dd8..61fd527 100644 --- a/base_report_to_printer/tests/test_ir_actions_report.py +++ b/base_report_to_printer/tests/test_ir_actions_report.py @@ -295,3 +295,20 @@ class TestIrActionsReportXml(TransactionCase): self.assertEqual(action.printer_tray_id, tray) action.onchange_printing_printer_id() self.assertFalse(action.printer_tray_id) + + def test_print_in_new_thread(self): + """It should return the action and printer from printing action in other thread""" + report = self.Model.search([], limit=1) + self.env.user.printing_action = "server" + printing_action = self.new_printing_action() + printing_action.user_id = self.env.user + printing_action.printer_id = self.new_printer() + printing_action.printer_id.multi_thread = True + self.assertEqual( + report.behaviour(), + { + "action": printing_action.action, + "printer": printing_action.printer_id, + "tray": False, + }, + ) diff --git a/base_report_to_printer/tests/test_printing_printer_tray.py b/base_report_to_printer/tests/test_printing_printer_tray.py index 22bbcc4..6440206 100644 --- a/base_report_to_printer/tests/test_printing_printer_tray.py +++ b/base_report_to_printer/tests/test_printing_printer_tray.py @@ -40,7 +40,7 @@ class TestPrintingPrinter(TransactionCase): self.server = self.env["printing.server"].create({}) self.printer = self.env["printing.printer"].create( { - "name": "Printer", + "name": "", "server_id": self.server.id, "system_name": "Sys Name", "default": True, @@ -105,10 +105,11 @@ class TestPrintingPrinter(TransactionCase): Check that the update_printers method calls _prepare_update_from_cups """ self.mock_cups_ppd(cups, file_name=False) - - self.assertEqual(self.printer.name, "Printer") self.ServerModel.update_printers() self.assertEqual(self.printer.name, "info") + self.printer.name = "My custom name" + self.ServerModel.update_printers() + self.assertEqual(self.printer.name, "My custom name") @mock.patch("%s.cups" % server_model) def test_prepare_update_from_cups_no_ppd(self, cups): diff --git a/base_report_to_printer/views/printing_printer.xml b/base_report_to_printer/views/printing_printer.xml index d64a208..49bae3e 100644 --- a/base_report_to_printer/views/printing_printer.xml +++ b/base_report_to_printer/views/printing_printer.xml @@ -78,6 +78,7 @@