This question has been flagged
1 Reply
5137 Views

I am trying to trace how orders from touchscreen interface of the point of sale module are saved to database but to no avail. I have tracked the process but don't understand how these scripts saves order/s to the database.

file: addons/point_of_sale/static/src/js/db.js

* save: function(store,data){
            //alert(store);
            //alert(this.look_deep(data));
            var str_data = JSON.stringify(data);
            localStorage[this.name + '_' + store] = JSON.stringify(data);
            this.cache[store] = data;
        },

*In a series of function calls this was the last called. But I don't understand how this script would save data to the database. Is this the function that saves or is there anything else involved in the process.

Avatar
Discard
Best Answer

Hi ,

 

In V7, this is the _flush() function  in static/js/model.js around line 275 :

        _flush: function(index){
            var self = this;
            var orders = this.db.get_orders();
            self.set('nbr_pending_operations',orders.length);

            var order  = orders[index];
            if(!order){
                return;
            }
            //try to push an order to the server
            // shadow : true is to prevent a spinner to appear in case of timeout
            (new instance.web.Model('pos.order')).call('create_from_ui',[[order]],undefined,{ shadow:true })
                .fail(function(unused, event){
                    //don't show error popup if it fails
                    event.preventDefault();
                    console.error('Failed to send order:',order);
                    self._flush(index+1);
                })
                .done(function(){
                    //remove from db if success
                    self.db.remove_order(order.id);
                    self._flush(index);
                });
        },

Hope this helps.

Avatar
Discard