From fdc3b425545c7e3ed2fc8aa6f32b2229fd897e0c Mon Sep 17 00:00:00 2001 From: Joseph Caburnay Date: Wed, 5 May 2021 11:33:07 +0000 Subject: [PATCH] [FIX] point_of_sale: restore feature that closes open pos from other tabs After the pos owl refactoring, the feature that closes pos from other browser tabs was removed. Having multiple open pos for the same session in the same browser session may cause issues when syncing orders because the tabs share the same localStorage, and the localStorage is the source of data when syncing orders to the backend. closes odoo/odoo#70427 X-original-commit: 51b2c7fad08354499503c5c444dd1a3ae1f26fc1 Signed-off-by: pimodoo --- addons/point_of_sale/static/src/js/Chrome.js | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/addons/point_of_sale/static/src/js/Chrome.js b/addons/point_of_sale/static/src/js/Chrome.js index 4ff0d745323..207059cc49d 100644 --- a/addons/point_of_sale/static/src/js/Chrome.js +++ b/addons/point_of_sale/static/src/js/Chrome.js @@ -135,6 +135,7 @@ odoo.define('point_of_sale.Chrome', function(require) { this.env.pos = new models.PosModel(posModelDefaultAttributes); await this.env.pos.ready; this._buildChrome(); + this._closeOtherTabs(); this.env.pos.set( 'selectedCategoryId', this.env.pos.config.iface_start_categ_id @@ -422,6 +423,32 @@ odoo.define('point_of_sale.Chrome', function(require) { } }); } + _closeOtherTabs() { + localStorage['message'] = ''; + localStorage['message'] = JSON.stringify({ + message: 'close_tabs', + session: this.env.pos.pos_session.id, + }); + + window.addEventListener( + 'storage', + (event) => { + if (event.key === 'message' && event.newValue) { + const msg = JSON.parse(event.newValue); + if ( + msg.message === 'close_tabs' && + msg.session == this.env.pos.pos_session.id + ) { + console.info( + 'POS / Session opened in another window. EXITING POS' + ); + this._closePos(); + } + } + }, + false + ); + } } Chrome.template = 'Chrome';