diff options
| author | Joseph Caburnay <jcb@odoo.com> | 2021-05-05 11:33:07 +0000 |
|---|---|---|
| committer | Joseph Caburnay <jcb@odoo.com> | 2021-05-05 11:37:58 +0000 |
| commit | 51b2c7fad08354499503c5c444dd1a3ae1f26fc1 (patch) | |
| tree | eac8e8d66b43380c6c63098b33271fa33ab70542 | |
| parent | c578c2e52dcf347de9734462d3dcf7b7df042c60 (diff) | |
[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#70403
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
| -rw-r--r-- | addons/point_of_sale/static/src/js/Chrome.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/addons/point_of_sale/static/src/js/Chrome.js b/addons/point_of_sale/static/src/js/Chrome.js index 41bb4e28d58..205283450ad 100644 --- a/addons/point_of_sale/static/src/js/Chrome.js +++ b/addons/point_of_sale/static/src/js/Chrome.js @@ -130,6 +130,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 @@ -406,6 +407,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'; |
