mirror of
https://github.com/bringout/oca-ocb-pos.git
synced 2026-04-20 05:02:06 +02:00
Initial commit: Pos packages
This commit is contained in:
commit
95dfb9edb0
1301 changed files with 264148 additions and 0 deletions
|
|
@ -0,0 +1,33 @@
|
|||
odoo.define('pos_cache.chrome', function (require) {
|
||||
'use strict';
|
||||
|
||||
const Chrome = require('point_of_sale.Chrome');
|
||||
const Registries = require('point_of_sale.Registries');
|
||||
|
||||
function roundUpDiv(y, x) {
|
||||
const remainder = y % x;
|
||||
return (y - remainder) / x + (remainder > 0 ? 1 : 0);
|
||||
}
|
||||
|
||||
const PosCacheChrome = (Chrome) => class PosCacheChrome extends Chrome {
|
||||
_runBackgroundTasks() {
|
||||
super._runBackgroundTasks();
|
||||
if (!this.env.pos.config.limited_products_loading) {
|
||||
this._loadRemainingProducts();
|
||||
}
|
||||
}
|
||||
async _loadRemainingProducts() {
|
||||
const nInitiallyLoaded = Object.keys(this.env.pos.db.product_by_id).length;
|
||||
const totalProductsCount = await this.env.pos._getTotalProductsCount();
|
||||
const nRemaining = totalProductsCount - nInitiallyLoaded;
|
||||
if (!(nRemaining > 0)) return;
|
||||
const multiple = 100000;
|
||||
const nLoops = roundUpDiv(nRemaining, multiple);
|
||||
for (let i = 0; i < nLoops; i++) {
|
||||
await this.env.pos._loadCachedProducts(i * multiple + nInitiallyLoaded, (i + 1) * multiple + nInitiallyLoaded);
|
||||
}
|
||||
this.showNotification(this.env._t('All products are loaded.'), 5000);
|
||||
}
|
||||
};
|
||||
Registries.Component.extend(Chrome, PosCacheChrome);
|
||||
});
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
odoo.define('pos_cache.pos_cache', function (require) {
|
||||
"use strict";
|
||||
|
||||
var { PosGlobalState } = require('point_of_sale.models');
|
||||
const Registries = require('point_of_sale.Registries');
|
||||
|
||||
|
||||
const PosCachePosGlobalState = (PosGlobalState) => class PosCachePosGlobalState extends PosGlobalState {
|
||||
async _getTotalProductsCount() {
|
||||
return this.env.services.rpc({
|
||||
model: 'pos.session',
|
||||
method: 'get_total_products_count',
|
||||
args: [[odoo.pos_session_id]],
|
||||
context: this.env.session.user_context,
|
||||
});
|
||||
}
|
||||
async _loadCachedProducts(start, end) {
|
||||
const products = await this.env.services.rpc({
|
||||
model: 'pos.session',
|
||||
method: 'get_cached_products',
|
||||
args: [[odoo.pos_session_id], start, end],
|
||||
context: this.env.session.user_context,
|
||||
});
|
||||
this._loadProductProduct(products);
|
||||
}
|
||||
}
|
||||
Registries.Model.extend(PosGlobalState, PosCachePosGlobalState);
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue