diff --git a/addons/point_of_sale/static/src/js/Chrome.js b/addons/point_of_sale/static/src/js/Chrome.js index 2b39a3dcf1d..6adb7a72bff 100644 --- a/addons/point_of_sale/static/src/js/Chrome.js +++ b/addons/point_of_sale/static/src/js/Chrome.js @@ -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); + }); } } diff --git a/addons/point_of_sale/static/src/js/Screens/PartnerListScreen/PartnerListScreen.js b/addons/point_of_sale/static/src/js/Screens/PartnerListScreen/PartnerListScreen.js index 0ebffa4efde..2ee190afd3c 100644 --- a/addons/point_of_sale/static/src/js/Screens/PartnerListScreen/PartnerListScreen.js +++ b/addons/point_of_sale/static/src/js/Screens/PartnerListScreen/PartnerListScreen.js @@ -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".'), diff --git a/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductsWidget.js b/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductsWidget.js index 8da8e5304f9..17b9988f3ce 100644 --- a/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductsWidget.js +++ b/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductsWidget.js @@ -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); diff --git a/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductsWidgetControlPanel.js b/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductsWidgetControlPanel.js index af16a2ec450..67d0e6c5e26 100644 --- a/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductsWidgetControlPanel.js +++ b/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductsWidgetControlPanel.js @@ -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(() => { diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index ea264e44832..81fb4432426 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -112,6 +112,9 @@ class PosGlobalState extends PosModel { this.numpadMode = 'quantity'; + this.isEveryPartnerLoaded = false; + this.isEveryProductLoaded = false; + // Record 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; } diff --git a/addons/point_of_sale/static/src/xml/Screens/ProductScreen/ProductsWidget.xml b/addons/point_of_sale/static/src/xml/Screens/ProductScreen/ProductsWidget.xml index df3f0fb2c68..4111c0b54fc 100644 --- a/addons/point_of_sale/static/src/xml/Screens/ProductScreen/ProductsWidget.xml +++ b/addons/point_of_sale/static/src/xml/Screens/ProductScreen/ProductsWidget.xml @@ -4,7 +4,7 @@
+ subcategories="subcategories" hasNoCategories="hasNoCategories" />
@@ -19,8 +19,7 @@ There are no products in this category.

-
+