Skip to content
Snippets Groups Projects
Commit 51b2c7fa authored by Joseph Caburnay's avatar Joseph Caburnay
Browse files

[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: default avatarpimodoo <pimodoo@users.noreply.github.com>
parent c578c2e5
No related branches found
No related tags found
No related merge requests found
......@@ -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';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment