[IMP] point_of_sale: disable backend querying when all items loaded

In this commit, we improve the load-in-the-background
feature of partners/products.

If there are items that are not loaded yet, (either because the
background loading is still running or because the user did not
want to load any prodcts at all at the start of the session)
the option to fetch items from the database is enabled: every
time the user interacts with the search bar (pressing "Enter",
"Search database" or the "Search" icon at the search bar) the
backend is queried and new items (products/partners) are fetched
and added to the frontend. Before the fetching of products from
the backend was done using the "database" icon / "Load Customers"
button which are now dropped.

In this commit, the feature of querrying the database
is automatically disabled once all the partners or
products (available_in_pos) have been loaded in PoS.
Then, the querying of the backend stops.

task-2755384

closes odoo/odoo#81226

Related: odoo/enterprise#23544
Signed-off-by: Masereel Pierre <pim@odoo.com>
This commit is contained in:
Eleftherios Kritsotakis
2022-06-02 18:58:07 +02:00
committed by Pierre Masereel
parent 4dd7416ab8
commit ca200e2ba5
6 changed files with 40 additions and 12 deletions
+7 -2
View File
@@ -198,10 +198,15 @@ odoo.define('point_of_sale.Chrome', function(require) {
// Basically, preload the images in the background.
this._preloadImages();
if (this.env.pos.config.limited_partners_loading && this.env.pos.config.partner_load_background) {
this.env.pos.loadPartnersBackground();
this.env.pos.loadPartnersBackground().then(() => {
this.env.pos.isEveryPartnerLoaded = true;
});
}
if (this.env.pos.config.limited_products_loading && this.env.pos.config.product_load_background) {
this.env.pos.loadProductsBackground().then(() => this.render(true));
this.env.pos.loadProductsBackground().then(() => {
this.env.pos.isEveryProductLoaded = true;
this.render(true);
});
}
}
@@ -8,7 +8,7 @@ odoo.define('point_of_sale.PartnerListScreen', function(require) {
const { debounce } = require("@web/core/utils/timing");
const { useListener } = require("@web/core/utils/hooks");
const { onWillUnmount, useRef } = owl;
const { onWillUnmount, useRef, onMounted } = owl;
/**
* Render this screen using `showTempScreen` to select partner.
@@ -47,6 +47,10 @@ odoo.define('point_of_sale.PartnerListScreen', function(require) {
};
this.updatePartnerList = debounce(this.updatePartnerList, 70);
onWillUnmount(this.updatePartnerList.cancel);
onMounted(() => {
if(!this.env.pos.config.limited_partners_loading)
this.env.pos.isEveryPartnerLoaded = true;
});
}
// Lifecycle hooks
@@ -93,9 +97,6 @@ odoo.define('point_of_sale.PartnerListScreen', function(require) {
}
return res
}
get isEveryPartnerLoaded() {
return !this.env.pos.config.limited_partners_loading || this.env.pos.config.partner_load_background;
}
get isBalanceDisplayed() {
return this.env.pos.config.module_pos_loyalty;
}
@@ -107,7 +108,7 @@ odoo.define('point_of_sale.PartnerListScreen', function(require) {
async _onPressEnterKey() {
if (!this.state.query) return;
if (!this.isEveryPartnerLoaded) {
if (!this.env.pos.isEveryPartnerLoaded) {
const result = await this.searchPartner();
this.showNotification(
_.str.sprintf(this.env._t('%s customer(s) found for "%s".'),
@@ -59,8 +59,8 @@ odoo.define('point_of_sale.ProductsWidget', function(require) {
get hasNoCategories() {
return this.env.pos.db.get_category_childs_ids(0).length === 0;
}
get isEveryProductLoaded() {
return !this.env.pos.config.limited_products_loading || this.env.pos.config.product_load_background;
get shouldShowButton() {
return this.productsToDisplay.length === 0 && this.searchWord && !this.env.pos.isEveryProductLoaded;
}
_switchCategory(event) {
this.env.pos.setSelectedCategoryId(event.detail);
@@ -17,6 +17,8 @@ odoo.define('point_of_sale.ProductsWidgetControlPanel', function(require) {
onMounted(() => {
this.env.posbus.on('search-product-from-info-popup', this, this.searchProductFromInfo)
if(!this.env.pos.config.limited_products_loading)
this.env.pos.isEveryProductLoaded = true;
});
onWillUnmount(() => {
@@ -112,6 +112,9 @@ class PosGlobalState extends PosModel {
this.numpadMode = 'quantity';
this.isEveryPartnerLoaded = false;
this.isEveryProductLoaded = false;
// Record<orderlineId, { 'qty': number, 'orderline': { qty: number, refundedQty: number, orderUid: string }, 'destinationOrderUid': string }>
this.toRefundLines = {};
this.TICKET_SCREEN_STATE = {
@@ -349,6 +352,24 @@ class PosGlobalState extends PosModel {
});
}
async updateIsEveryPartnerLoaded() {
let partnersCount = await this.env.services.rpc({
model: 'res.partner',
method: 'search_count',
args: [[]],
});
this.isEveryPartnerLoaded = partnersCount === this.db.partner_sorted.length;
}
async updateIsEveryProductLoaded() {
let productsCount = await this.env.services.rpc({
model: 'product.product',
method: 'search_count',
args: [[['available_in_pos', '=', true]]],
});
this.isEveryProductLoaded = productsCount === this.db.get_product_by_category(this.db.root_category_id).length;
}
setSelectedCategoryId(categoryId) {
this.selectedCategoryId = categoryId;
}
@@ -4,7 +4,7 @@
<t t-name="ProductsWidget" owl="1">
<div class="products-widget">
<ProductsWidgetControlPanel mobileSearchBarIsShown="props.mobileSearchBarIsShown" breadcrumbs="breadcrumbs"
subcategories="subcategories" hasNoCategories="hasNoCategories" isEveryProductLoaded="isEveryProductLoaded" />
subcategories="subcategories" hasNoCategories="hasNoCategories" />
<div class="product-list-container">
<div t-if="productsToDisplay.length != 0" class="product-list">
<t t-foreach="productsToDisplay" t-as="product" t-key="product.id">
@@ -19,8 +19,7 @@
There are no products in this category.
</p>
</div>
<div class="portal search-database-button no-results-message"
t-att-class="{ oe_hidden: productsToDisplay.length !== 0 or isEveryProductLoaded or !searchWord }"></div>
<div class="portal search-database-button no-results-message" t-att-class="{ oe_hidden: !shouldShowButton }"></div>
</div>
</div>
</t>