Community mailing list archives

community@mail.odoo.com

Odoo 9 POS: Product Quantity sync between different pos sessions

by
Hugo Razera
- 02/13/2016 16:03:33
Hello List,

i'm trying to figure out a way to Synchronize the Quantity Available of products in the POS.

Currently i'm using the pos_product_available (https://github.com/yelizariev/pos-addons) module, that provides the product qty available in the POS screen.

here is the main JS code:
odoo.define('pos_product_available.PosModel', function(require){
"use strict";


var models = require('point_of_sale.models');
models.load_models({
model: 'product.product',
fields: ['qty_available'],
domain:[['sale_ok','=',true],['available_in_pos','=',true]],
context: function(self){ return {'location': self.config.stock_location_id[0]}},
loaded: function(self, products){
$.each(products, function(){
$.extend(self.db.get_product_by_id(this.id) || {}, this)
});
}
})

var PosModelSuper = models.PosModel;

models.PosModel = models.PosModel.extend({
refresh_qty_available:function(product){
var $elem = $("[data-product-id='"+product.id+"'] .qty-tag");
$elem.html(product.qty_available)
if (product.qty_available <= 0 && !$elem.hasClass('not-available')){
$elem.addClass('not-available')
}
},
push_order: function(order){
var self = this;
var pushed = PosModelSuper.prototype.push_order.call(this, order);
if (order){
order.orderlines.each(function(line){
var product = line.get_product();
product.qty_available -= line.get_quantity();
self.refresh_qty_available(product);
})
}
return pushed;
},
push_and_invoice_order: function(order){
var self = this;
var invoiced = PosModelSuper.prototype.push_and_invoice_order.call(this, order);

if (order && order.get_client()){
if (order.orderlines){
order.orderlines.each(function(line){
var product = line.get_product();
product.qty_available -= line.get_quantity();
self.refresh_qty_available(product);
})
} else if (order.orderlines){
order.orderlines.each(function(line){
var product = line.get_product();
product.qty_available -= line.get_quantity();
self.refresh_qty_available(product);
})
}
}

return invoiced;
},
})
})

It works pretty well for a single POS session, but the problem is when there are multiple sessions. the qty does not reflect the products sold on the other pos session.

my question are:

1) is it posible to reload the models from the backend on the POS? and how would be this better executed.
2) How can i periodically call the "reload models" from question 1. i mean, is there a way to run code on time intervals?

the idea is to reload the products qty say every second from the backend and update the displayed data on the screen.

thanks for your time.
Hugo Razera