From dbf12af2fa547cdcb2761a927b9b449caca07864 Mon Sep 17 00:00:00 2001 From: "Loan (LSE)" Date: Thu, 2 Mar 2023 14:34:52 +0000 Subject: [PATCH] [FIX] pos_epson_printer: more details on printer errors Before this commit: If the ePos printer is reachable but is configured incorrectly (change of Device ID, etc.) or have an issue (missing paper, etc.), a generic error message will be given: "Please check if the printer has enough paper and is ready to print." This is too generic considering the amount of issue that can happen and the fact that the printer itself does send to us a `code` which give good indication on the origin of the issue. The list of these codes can be seen at: https://files.support.epson.com/pdf/pos/bulk/server_direct_print_um_en_revk.pdf#page=52 In version 14 this code was given in the error message. But this feature was lost in the versions above & Trying to print a receipt from the PoS with a wrongly configured ePoS printer will just pop the confirmation popup: 'Do you want to print using the web printer?' Without giving any details regarding the errors causing the issue After this commit: A more precise error message is given: - Containing the printer error code - Giving recommendation on how to search online to solve the issue - On the specific case of the `Device ID` setting changed, give more details on the value to use & The error pop-up with the error details is displayed first. Then the confirmation one opw-3188576 opw-3071709 closes odoo/odoo#116020 X-original-commit: 1f753d31c925e479e8243a6427a24b3da99bfc31 Signed-off-by: Loan (LSE) Signed-off-by: Loan (LSE) Signed-off-by: Sens Loan (lse) --- .../src/js/Misc/AbstractReceiptScreen.js | 4 ++ .../point_of_sale/static/src/js/printers.js | 2 +- .../i18n/pos_epson_printer.pot | 39 ++++++++++++++++++- .../static/src/js/printers.js | 32 ++++++++++++--- 4 files changed, 68 insertions(+), 9 deletions(-) diff --git a/addons/point_of_sale/static/src/js/Misc/AbstractReceiptScreen.js b/addons/point_of_sale/static/src/js/Misc/AbstractReceiptScreen.js index 1980266cbca..b01e79024b2 100644 --- a/addons/point_of_sale/static/src/js/Misc/AbstractReceiptScreen.js +++ b/addons/point_of_sale/static/src/js/Misc/AbstractReceiptScreen.js @@ -25,6 +25,10 @@ export class AbstractReceiptScreen extends Component { if (printResult.successful) { return true; } else { + await this.popup.add(ErrorPopup, { + title: printResult.message.title, + body: printResult.message.body, + }); const { confirmed } = await this.popup.add(ConfirmPopup, { title: printResult.message.title, body: "Do you want to print using the web printer?", diff --git a/addons/point_of_sale/static/src/js/printers.js b/addons/point_of_sale/static/src/js/printers.js index 5205f37a0c2..9a8fee1bf61 100644 --- a/addons/point_of_sale/static/src/js/printers.js +++ b/addons/point_of_sale/static/src/js/printers.js @@ -77,7 +77,7 @@ export const PrinterMixin = { // IoT box can't find a printer. if (!sendPrintResult || sendPrintResult.result === false) { this.receipt_queue.length = 0; - return this.printResultGenerator.IoTResultError(); + return this.printResultGenerator.IoTResultError(sendPrintResult.printerErrorCode); } } return this.printResultGenerator.Successful(); diff --git a/addons/pos_epson_printer/i18n/pos_epson_printer.pot b/addons/pos_epson_printer/i18n/pos_epson_printer.pot index 8d5b5e49562..f6afec24908 100644 --- a/addons/pos_epson_printer/i18n/pos_epson_printer.pot +++ b/addons/pos_epson_printer/i18n/pos_epson_printer.pot @@ -26,6 +26,14 @@ msgstr "" msgid "Config Settings" msgstr "" +#. module: pos_epson_printer +#. openerp-web +#: code:addons/pos_epson_printer/static/src/js/printers.js:0 +#, python-format +msgid "" +"Check on the printer configuration for the 'Device ID' setting. It should be set to: " +msgstr "" + #. module: pos_epson_printer #. openerp-web #: code:addons/pos_epson_printer/static/src/js/printers.js:0 @@ -58,6 +66,13 @@ msgstr "" msgid "Local IP address of an Epson receipt printer." msgstr "" +#. module: pos_epson_printer +#. openerp-web +#: code:addons/pos_epson_printer/static/src/js/printers.js:0 +#, python-format +msgid "No paper was detected by the printer" +msgstr "" + #. module: pos_epson_printer #. openerp-web #: code:addons/pos_epson_printer/static/src/js/printers.js:0 @@ -95,6 +110,26 @@ msgstr "" #: model_terms:ir.ui.view,arch_db:pos_epson_printer.pos_iot_config_view_form #: model_terms:ir.ui.view,arch_db:pos_epson_printer.res_config_settings_view_form msgid "" -"The Epson receipt printer will be used instead of the receipt printer " -"connected to the IoT Box." +"The Epson receipt printer will be used instead of the receipt printer connected to the IoT Box." +msgstr "" + +#. module: pos_epson_printer +#. openerp-web +#: code:addons/pos_epson_printer/static/src/js/printers.js:0 +#, python-format +msgid "The following error code was given by the printer:" +msgstr "" + +#. module: pos_epson_printer +#. openerp-web +#: code:addons/pos_epson_printer/static/src/js/printers.js:0 +#, python-format +msgid "The printer was successfully reached, but it wasn't able to print." +msgstr "" + +#. module: pos_epson_printer +#. openerp-web +#: code:addons/pos_epson_printer/static/src/js/printers.js:0 +#, python-format +msgid "To find more details on the error reason, please search online for:" msgstr "" diff --git a/addons/pos_epson_printer/static/src/js/printers.js b/addons/pos_epson_printer/static/src/js/printers.js index 43c86186874..c371adc411f 100644 --- a/addons/pos_epson_printer/static/src/js/printers.js +++ b/addons/pos_epson_printer/static/src/js/printers.js @@ -19,9 +19,9 @@ class EpsonPrintResultGenerator extends PrintResultGenerator { title: _t("Connection to the printer failed"), body: _t( "Please check if the printer is still connected. \n" + - "Some browsers don't allow HTTP calls from websites to devices in the network (for security reasons). " + - "If it is the case, you will need to follow Odoo's documentation for " + - "'Self-signed certificate for ePOS printers' and 'Secure connection (HTTPS)' to solve the issue" + "Some browsers don't allow HTTP calls from websites to devices in the network (for security reasons). " + + "If it is the case, you will need to follow Odoo's documentation for " + + "'Self-signed certificate for ePOS printers' and 'Secure connection (HTTPS)' to solve the issue" ), }, }); @@ -38,12 +38,31 @@ class EpsonPrintResultGenerator extends PrintResultGenerator { return printRes; } - IoTResultError() { + IoTResultError(printerErrorCode) { + let message = _t("The printer was successfully reached, but it wasn't able to print.") + '\n'; + if (printerErrorCode) { + message += '\n' + _t("The following error code was given by the printer:") + '\n' + printerErrorCode; + + const extra_messages = { + "DeviceNotFound": + _t("Check on the printer configuration for the 'Device ID' setting. " + + "It should be set to: ") + "\nlocal_printer", + "EPTR_REC_EMPTY": + _t("No paper was detected by the printer"), + }; + if (printerErrorCode in extra_messages) { + message += '\n' + extra_messages[printerErrorCode]; + } + message += '\n' + _t("To find more details on the error reason, please search online for:") + '\n' + + " Epson Server Direct Print " + printerErrorCode; + } else { + message += _t("Please check if the printer has enough paper and is ready to print."); + } return new PrintResult({ successful: false, message: { title: _t("Printing failed"), - body: _t("Please check if the printer has enough paper and is ready to print."), + body: message, }, }); } @@ -164,6 +183,7 @@ export const EpsonPrinter = core.Class.extend(PrinterMixin, { method: "POST", data: img, }); - return $(res).find("response").attr("success") === "true"; + const response = $(res).find("response"); + return {"result": response.attr("success") === "true", "printerErrorCode": response.attr("code")}; }, });