From 507b5cce3ae848d4b22b401f45d346f66e8fc45d Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Wed, 16 May 2018 14:28:49 +0200 Subject: [PATCH] [FIX] point_of_sale: repair cashier from localStorage on refresh page open a pos, change cashier hit F5 Before this commit, the previous user was set as cashier, forgetting about the change we made This was because of two things: - The original fix to do just this use case was pushed in v9.0 as e14ab697727d87773dbefba11453b9edca79fc68 - In v11.0 the commit f5f60599bfd49df5904f971b0f1bbb37a96ccdbe introduced full usage of Backbone's set and get which meant that self.cashier was no longer relevant - In v10.0 the commit 475027b9889c0701f8fe5e0373a40663f6a831e1 (For v11.0: a9caef0ebbc7f3288e06f352f5bb817861e9689c) Was intended to update the res.users objects at their loading to ensure that their access rights were loaded too But it did this using the wrong condition After this commit, it reworks fine OPW 1844006 closes #24762 --- addons/point_of_sale/static/src/js/models.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 24443942ba5..1e5fa2e937b 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -259,6 +259,7 @@ exports.PosModel = Backbone.Model.extend({ // we attribute a role to the user, 'cashier' or 'manager', depending // on the group the user belongs. var pos_users = []; + var current_cashier = self.get_cashier(); for (var i = 0; i < users.length; i++) { var user = users[i]; for (var j = 0; j < user.groups_id.length; j++) { @@ -276,6 +277,8 @@ exports.PosModel = Backbone.Model.extend({ // replace the current user with its updated version if (user.id === self.user.id) { self.user = user; + } + if (user.id === current_cashier.id) { self.set_cashier(user); } } @@ -629,7 +632,7 @@ exports.PosModel = Backbone.Model.extend({ // changes the current cashier set_cashier: function(user){ this.set('cashier', user); - this.db.set_cashier(this.cashier); + this.db.set_cashier(this.get('cashier')); }, //creates a new empty order and sets it as the current order add_new_order: function(){