From 9d62888623956be07085e9bebaae4aa045c6502a Mon Sep 17 00:00:00 2001 From: Pierre Masereel Date: Thu, 2 Feb 2023 14:48:44 +0000 Subject: [PATCH] [FIX] point_of_sale: limited load new partners When you create or update a partner from the POS, it will call the server to get the new modifications on partners. When you put a limit to 0 and so no background loading. You don't get any partners and when you create or update one, it will try to load all of your partners because the last write_date is unknown. Which is not the intended behaviour. If you have set a limit different than 0, you will not get all of them (because you already have some records but it can take a larger batch than the one defined. So we are now trying to correctly handle the load of new partners. closes odoo/odoo#111912 X-original-commit: a5af7b235c8a786e972698ab709fd74f4c1bf515 Signed-off-by: Masereel Pierre --- addons/point_of_sale/static/src/js/models.js | 71 +++++++++++--------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 6da476552db..20a55452a10 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -339,35 +339,42 @@ export class PosGlobalState extends PosModel { // reload the list of partner, returns as a promise that resolves if there were // updated partners, and fails if not - load_new_partners() { - return new Promise((resolve, reject) => { - var domain = this.prepare_new_partners_domain(); - this.env.services - .rpc( - { - model: "pos.session", - method: "get_pos_ui_res_partner_by_params", - args: [[odoo.pos_session_id], { domain }], - }, - { - timeout: 3000, - shadow: true, - } - ) - .then( - (partners) => { - if (this.addPartners(partners)) { - // check if the partners we got were real updates - resolve(); - } else { - reject("Failed in updating partners."); - } - }, - function (type, err) { - reject(); - } - ); - }); + async load_new_partners() { + let search_params = { domain: this.prepare_new_partners_domain() }; + if (this.env.pos.config.limited_partners_loading) { + search_params['order'] = 'write_date desc'; + if (this.env.pos.config.partner_load_background) { + search_params['limit'] = this.env.pos.config.limited_partners_amount || 1; + } + else { + search_params['limit'] = 1; + } + } + const partners = await this.env.services + .rpc( + { + model: 'pos.session', + method: 'get_pos_ui_res_partner_by_params', + args: [[odoo.pos_session_id], search_params], + }, + { + timeout: 3000, + shadow: true, + } + ) + if (this.env.pos.config.partner_load_background) { + this.loadPartnersBackground( + search_params['domain'], + this.env.pos.config.limited_partners_amount || 1, + 'write_date desc' + ); + } + if (this.addPartners(partners)) { + return true + } + else { + return false + } } setSelectedCategoryId(categoryId) { @@ -540,7 +547,7 @@ export class PosGlobalState extends PosModel { page += 1; } while (products.length == this.config.limited_products_amount); } - async loadPartnersBackground() { + async loadPartnersBackground(domain=[], offset=0, order=false) { // Start at the first page since the first set of loaded partners are not actually in the // same order as this background loading procedure. let i = 0; @@ -553,8 +560,10 @@ export class PosGlobalState extends PosModel { args: [ [odoo.pos_session_id], { + domain: domain, limit: this.config.limited_partners_amount, - offset: this.config.limited_partners_amount * i, + offset: offset + this.config.limited_partners_amount * i, + order: order, }, ], context: this.env.session.user_context,