From a11662e525aad9a843acf54b717f3df18d8c2cab Mon Sep 17 00:00:00 2001 From: Romeo Fragomeli Date: Fri, 30 Apr 2021 08:46:41 +0000 Subject: [FIX] point_of_sale: print not working in Mobile App Before this commit, "document.execCommand" was first method used when attempting to print, due to a bug in Safari for Windows (ndr. which is deprecated as the last version of Safari for Windows is 5.1.7 from may 2012). On the mobile App, the "document.execCommand('print')" call returns "true" even if nothing has actually been done, which therefore prevents from executing "window.print()". After this commit, we execute directly "window.print()" as it's supported by all modern browsers (except Firefox Android, which doesn't support printing at all). Notes: * "document.execCommand" is deprecated and the "print" command isn't even documented * Safari 5.1.7 doesn't support Promise/Async/Await, and therefore not Odoo 13+. References: * https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand * https://developer.mozilla.org/en-US/docs/Web/API/Window/print * https://caniuse.com/?search=await * https://caniuse.com/?search=promise * https://apple.stackexchange.com/questions/68836/where-can-i-download-safari-for-windows opw-2486818 closes odoo/odoo#70155 Signed-off-by: Pierre Paridans --- addons/point_of_sale/static/src/js/Misc/AbstractReceiptScreen.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (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 index 6abf4b2e93d..2ebdce20e3f 100644 --- a/addons/point_of_sale/static/src/js/Misc/AbstractReceiptScreen.js +++ b/addons/point_of_sale/static/src/js/Misc/AbstractReceiptScreen.js @@ -39,13 +39,9 @@ odoo.define('point_of_sale.AbstractReceiptScreen', function (require) { 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(); + window.print(); return true; } catch (err) { await this.showPopup('ErrorPopup', { -- cgit v1.2.3