Files
odoo_source/addons/pos_cache/static/src/js/pos_cache.js
T
Géry Debongnie 2106e3dd2e [REF] web, *: simplify our RPC system (in JS)
The RPC system was not completely satisfactory, we decided to prepare
the future and do it properly.  This commit introduces the new rpc
system, which replace the previous new one.  We now simply have a
method, this._rpc, which takes a dictionary of parameters.  The idea is
that depending on the parameters, it is able to add correct default
value when necessary.

For situations where we don't have the this._rpc method, we can use the
rpc.query method, which takes the same arguments, but directly calls
ajax.rpc instead of triggering up some events.
2017-04-11 19:44:38 +02:00

48 lines
1.7 KiB
JavaScript

odoo.define('pos_cache.pos_cache', function (require) {
"use strict";
var models = require('point_of_sale.models');
var core = require('web.core');
var rpc = require('web.rpc');
var _t = core._t;
var posmodel_super = models.PosModel.prototype;
models.PosModel = models.PosModel.extend({
load_server_data: function () {
var self = this;
var product_index = _.findIndex(this.models, function (model) {
return model.model === "product.product";
});
// Give both the fields and domain to pos_cache in the
// backend. This way we don't have to hardcode these
// values in the backend and they automatically stay in
// sync with whatever is defined (and maybe extended by
// other modules) in js.
var product_model = this.models[product_index];
var product_fields = product_model.fields;
var product_domain = product_model.domain;
// We don't want to load product.product the normal
// uncached way, so get rid of it.
if (product_index !== -1) {
this.models.splice(product_index, 1);
}
return posmodel_super.load_server_data.apply(this, arguments).then(function () {
var records = rpc.query({
model: 'pos.config',
method: 'get_products_from_cache',
args: [self.pos_session.config_id[0], product_fields, product_domain],
});
self.chrome.loading_message(_t('Loading') + ' product.product', 1);
return records.then(function (product) {
self.db.add_products(product);
});
});
},
});
});