summaryrefslogtreecommitdiff
path: root/addons/point_of_sale/static/src/js/Misc/AbstractReceiptScreen.js
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/point_of_sale/static/src/js/Misc/AbstractReceiptScreen.js
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/point_of_sale/static/src/js/Misc/AbstractReceiptScreen.js')
-rw-r--r--addons/point_of_sale/static/src/js/Misc/AbstractReceiptScreen.js62
1 files changed, 62 insertions, 0 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
new file mode 100644
index 00000000..2ebdce20
--- /dev/null
+++ b/addons/point_of_sale/static/src/js/Misc/AbstractReceiptScreen.js
@@ -0,0 +1,62 @@
+odoo.define('point_of_sale.AbstractReceiptScreen', function (require) {
+ 'use strict';
+
+ const { useRef } = owl.hooks;
+ const { nextFrame } = require('point_of_sale.utils');
+ const PosComponent = require('point_of_sale.PosComponent');
+ const Registries = require('point_of_sale.Registries');
+
+ /**
+ * This relies on the assumption that there is a reference to
+ * `order-receipt` so it is important to declare a `t-ref` to
+ * `order-receipt` in the template of the Component that extends
+ * this abstract component.
+ */
+ class AbstractReceiptScreen extends PosComponent {
+ constructor() {
+ super(...arguments);
+ this.orderReceipt = useRef('order-receipt');
+ }
+ async _printReceipt() {
+ if (this.env.pos.proxy.printer) {
+ const printResult = await this.env.pos.proxy.printer.print_receipt(this.orderReceipt.el.outerHTML);
+ if (printResult.successful) {
+ return true;
+ } else {
+ const { confirmed } = await this.showPopup('ConfirmPopup', {
+ title: printResult.message.title,
+ body: 'Do you want to print using the web printer?',
+ });
+ if (confirmed) {
+ // We want to call the _printWeb when the popup is fully gone
+ // from the screen which happens after the next animation frame.
+ await nextFrame();
+ return await this._printWeb();
+ }
+ return false;
+ }
+ } else {
+ return await this._printWeb();
+ }
+ }
+ async _printWeb() {
+ try {
+ window.print();
+ return true;
+ } catch (err) {
+ await this.showPopup('ErrorPopup', {
+ title: this.env._t('Printing is not supported on some browsers'),
+ body: this.env._t(
+ 'Printing is not supported on some browsers due to no default printing protocol ' +
+ 'is available. It is possible to print your tickets by making use of an IoT Box.'
+ ),
+ });
+ return false;
+ }
+ }
+ }
+
+ Registries.Component.add(AbstractReceiptScreen);
+
+ return AbstractReceiptScreen;
+});