From b2f8170d88239b5eaf04f1e3c0dcef613b78fedc Mon Sep 17 00:00:00 2001 From: Joseph Caburnay Date: Mon, 15 Jun 2020 09:59:37 +0000 Subject: [IMP] point_of_sale,pos_*: allow users to manage orders in the pos frontend We now allow invoicing of finalized orders in an open session in this first iteration of order management in the pos frontend. Additionally, receipt reprinting is also introduced. With this feature, we can now reprint the receipt of old orders. closes odoo/odoo#51141 Task-id: 1981354 Related: odoo/enterprise#11690 Related: odoo/upgrade#1472 Signed-off-by: pimodoo --- .../static/src/js/Misc/AbstractReceiptScreen.js | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 addons/point_of_sale/static/src/js/Misc/AbstractReceiptScreen.js (limited to 'addons/point_of_sale/static/src/js/Misc/AbstractReceiptScreen.js') 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 00000000000..6abf4b2e93d --- /dev/null +++ b/addons/point_of_sale/static/src/js/Misc/AbstractReceiptScreen.js @@ -0,0 +1,66 @@ +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(); + } + } + /** + * https://stackoverflow.com/questions/21285902/printing-a-part-of-webpage-with-javascript + */ + async _printWeb() { + try { + const isPrinted = document.execCommand('print', false, null); + if (!isPrinted) 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; +}); -- cgit v1.2.3