Help

0

Problem with Javascript

Avatar
Christian Mepat

I have a piece of code that works in an instance of Odoo 11 and not in another.

In fact in POS, when the user wants to disconnect from the interface,  I check if there is one order in localstorage. And the rest of the behaviour depends on it.

Please any solution ?

see code below

var rpc = require('web.rpc');
var chrome = require('point_of_sale.chrome');



chrome.HeaderButtonWidget.include({
renderElement: function(){
var self = this;
this._super();
this.$el.click(function(){

function get_current_session(){
var current_session = 0;
return current_session;
}
function checkOrdersInLocalstorage(){
var local_storage = window.localStorage;
var keys = [];
for (var key in local_storage) keys.push(key)
var key_ = ""
for(var i=0; i<keys.length; i++){
if (keys[i].includes('orders') && !keys[i]\
                            .includes('unpaid')){
                                    key_ = keys[i];}}

var list_empty = true;
if(key_ != ""){
var tmp = local_storage[key_];
var ordersList = tmp.split('[');
if(ordersList.length > 2){
list_empty = false;
}
}
return list_empty;
}

                // On vérifie si la liste n'est pas vide

if(!checkOrdersInLocalstorage()){
                        
self.gui.show_popup('error', {
'title': _t('Erreur de conformité'),
'body': _t('Veuillez vous rassurer que
vous navez pas de commande en attente!\n\nSi le problème persiste
veuillez contacter votre administrateur!'),
});
}

else {

rpc.query({//Appel de la méthode sur le serveur
model: 'pos.session',
method: 'set_field_can_be_closed',
args: [[], get_current_session()]
}).then(function(){
return true;
});
}
});
},
});


Avatar
Abbandona