Files
odoo_source/addons/pos_cache/static/src/js/pos_cache.js
T
Joren Van Onder 97b0723722 [ADD] pos_cache: add pos_cache ported to v9 from odoo-extra
Originally written by Nicolas Seinlet <nse@odoo.com>. Provides
pos.config with a product.product cache.

This adds a ported and refactored pos_cache from odoo-extra:

- Adapt to changes in web and point_of_sale since 8.0
- Refactor the load_server_data function, so it isn't copy pasted but
  cleanly patched into the load_server_data super.
- Make the cron inactive by default.
- Also remove retrying the write 5 times, when it fails we'll just have
  to wait until the cron triggers again (an hour from then).
- Store the product.product fields and domain on pos_cache. When cache
  is requested from the pos with a different field or domain it'll
  automatically recompute. Necessary for when someone would install a
  module that modifies these things in the pos after a cache has been
  generated.
- Have multiple caches per pos_config per user
- Make the module adhere to the Odoo Coding Guidelines.
2015-09-25 12:47:29 +02:00

44 lines
1.8 KiB
JavaScript

odoo.define('pos_cache.pos_cache', function (require) {
"use strict";
var core = require('web.core');
var models = require('point_of_sale.models');
var Model = require('web.DataModel');
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 = new Model('pos.config').call('get_products_from_cache',
[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);
});
});
},
});
});