Skip to content

Commit 6cf3954

Browse files
committed
[IMP] point_of_sale: improve IoT error messages
This commit improves the error messages in the following scenarios when receipt printing fails: - If the user if offline, we get a message telling them to reconnect to the internet. - If the IoT box responds but the printer cannot be found, we explain this to the user and ask them to check the printer. - If we fail to connect to the IoT box at all, we assume there is a HTTPS problem and tell the user to set up their subscription. task-4787508 closes odoo#209541 X-original-commit: 7b0d177 Related: odoo/enterprise#85332 Signed-off-by: Yaroslav Soroko (yaso) <[email protected]> Signed-off-by: Max Whale (mawh) <[email protected]>
1 parent 8d0c0a7 commit 6cf3954

File tree

5 files changed

+50
-11
lines changed

5 files changed

+50
-11
lines changed

addons/point_of_sale/static/src/app/components/popups/retry_print_popup/retry_print_popup.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ export class RetryPrintPopup extends Component {
88
static props = {
99
title: { type: String, optional: true },
1010
message: { type: String, optional: true },
11+
canRetry: { type: Boolean, optional: true },
1112
download: Function,
1213
retry: Function,
1314
close: Function,
1415
};
1516
static defaultProps = {
1617
title: _t("Printing error"),
18+
message: _t("An unknown error occurred. Do you want to download the receipt instead?"),
1719
};
1820

1921
onClickDownload() {

addons/point_of_sale/static/src/app/components/popups/retry_print_popup/retry_print_popup.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33

44
<t t-name="point_of_sale.RetryPrintPopup">
55
<Dialog size="'md'" title="props.title">
6-
<p t-if="props.message" t-out="props.message"/>
7-
<p>Do you want to retry printing, or download it instead?</p>
6+
<p t-if="props.message" t-out="props.message" class="text-prewrap"/>
87
<t t-set-slot="footer">
9-
<button class="btn btn-primary btn-lg" t-on-click="onClickRetry">Retry</button>
10-
<button class="btn btn-secondary btn-lg" t-on-click="onClickDownload">Download</button>
8+
<button t-if="props.canRetry" class="btn btn-primary btn-lg" t-on-click="onClickRetry">Retry</button>
9+
<button class="btn btn-lg" t-att-class="{ 'btn-secondary': props.canRetry, 'btn-primary': !props.canRetry }" t-on-click="onClickDownload">Download</button>
1110
<button class="btn btn-secondary btn-lg" t-on-click="props.close">Discard</button>
1211
</t>
1312
</Dialog>

addons/point_of_sale/static/src/app/services/pos_printer_service.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export class PosPrinterService extends PrinterService {
4545
this.dialog.add(RetryPrintPopup, {
4646
title: error.title,
4747
message: error.body,
48+
canRetry: error.canRetry,
4849
retry: () => {
4950
this.printHtml(...arguments);
5051
},

addons/point_of_sale/static/src/app/services/printer_service.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export class PrinterService extends Reactive {
3636
throw {
3737
title: printResult.message.title || "Error",
3838
body: printResult.message.body,
39+
canRetry: printResult.canRetry,
3940
errorCode: printResult.errorCode,
4041
};
4142
}

addons/point_of_sale/static/src/app/utils/printer/base_printer.js

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { _t } from "@web/core/l10n/translation";
2+
import { ConnectionLostError } from "@web/core/network/rpc";
23
import { htmlToCanvas } from "@point_of_sale/app/services/render_service";
34
/**
45
* Implements basic printer functions.
@@ -30,9 +31,12 @@ export class BasePrinter {
3031
);
3132
try {
3233
printResult = await this.sendPrintingJob(image);
33-
} catch {
34+
} catch (error) {
3435
// Error in communicating to the IoT box.
3536
this.receiptQueue.length = 0;
37+
if (error instanceof ConnectionLostError) {
38+
return this.getOfflineError();
39+
}
3640
return this.getActionError();
3741
}
3842
// rpc call is okay but printing failed because
@@ -66,11 +70,45 @@ export class BasePrinter {
6670
* if it failed to connect to the IoT box.
6771
*/
6872
getActionError() {
73+
if (window.isSecureContext) {
74+
// We assume if we get a network error over HTTPS that it is a certificate issue.
75+
return {
76+
successful: false,
77+
canRetry: false,
78+
message: {
79+
title: _t("Connection to IoT Box failed"),
80+
body: _t(
81+
"Your database is not registered.\n" +
82+
"Buy a subscription, or register your subscription code, then retry.\n\n" +
83+
"You can still download the receipt and print it manually."
84+
),
85+
},
86+
};
87+
} else {
88+
return {
89+
successful: false,
90+
canRetry: true,
91+
message: {
92+
title: _t("Connection to IoT Box failed"),
93+
body: _t(
94+
"Please ensure the IoT box is turned on and connected to the network before retrying."
95+
),
96+
},
97+
};
98+
}
99+
}
100+
101+
/**
102+
* Return value of this method will be the result of calling `printReceipt`
103+
* if it failed due to the client being offline.
104+
*/
105+
getOfflineError() {
69106
return {
70107
successful: false,
108+
canRetry: true,
71109
message: {
72-
title: _t("Connection to IoT Box failed"),
73-
body: _t("Please check if the IoT Box is still connected."),
110+
title: _t("No Internet Connection"),
111+
body: _t("Please ensure you are connected to the internet before retrying."),
74112
},
75113
};
76114
}
@@ -82,13 +120,11 @@ export class BasePrinter {
82120
getResultsError(_printResult) {
83121
return {
84122
successful: false,
123+
canRetry: true,
85124
message: {
86125
title: _t("Connection to the printer failed"),
87126
body: _t(
88-
"Please check if the printer is still connected. \n" +
89-
"Some browsers don't allow HTTP calls from websites to devices in the network (for security reasons). " +
90-
"If it is the case, you will need to follow Odoo's documentation for " +
91-
"'Self-signed certificate for ePOS printers' and 'Secure connection (HTTPS)' to solve the issue. "
127+
"Your IoT box cannot find the printer, please ensure it is connected and turned on before retrying."
92128
),
93129
},
94130
};

0 commit comments

Comments
 (0)