[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 e14ab69772
- In v11.0 the commit f5f60599bf introduced full usage of Backbone's set and get
    which meant that self.cashier was no longer relevant
- In v10.0 the commit 475027b988
    (For v11.0: a9caef0ebb)
    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
This commit is contained in:
Lucas Perais (lpe)
2018-05-17 09:17:21 +02:00
parent 65a589eb54
commit 507b5cce3a
+4 -1
View File
@@ -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(){