[FIX] point_of_sale,pos_sale: load the missing partners
Before this commit: if the "Limited Partners Loading" were enabled, the
partner wouldn't set when using the "Quotation/Order" functionality
for unsynced partners.
Steps to reproduce the issue on the runbot:
Enable developer mode.
Go to the Point of Sale.
Open the config of any pos.
Enable "Limited Partners Loading" and set "Number of Partners
Loaded" to a low number (like 5 or 10)
Disable "Load all remaining partners in the background."
Open a new PoS session for the configured PoS
Use the "Quotation/Order" functionality.
Select any order, for example, S00043.
The customer is not set for the current pos order.
Solution
The solution is to load the partner.
Also, there was an issue when using the limited number of partner loading
when it tried to load the cached and paid orders' partners. I added a function
to load missing partners.
opw-2883686
closes odoo/odoo#97442
X-original-commit: 4d7c05346e0c253c8b11736b9ee9f8426a87f2af
Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
Signed-off-by: Pedram Bi Ria (pebr) <pebr@odoo.com>
This commit is contained in:
@@ -573,8 +573,9 @@ odoo.define('point_of_sale.TicketScreen', function (require) {
|
||||
args: [idsNotInCache],
|
||||
context: this.env.session.user_context,
|
||||
});
|
||||
// Check for missing products and load them in the PoS
|
||||
// Check for missing products and partners and load them in the PoS
|
||||
await this.env.pos._loadMissingProducts(fetchedOrders);
|
||||
await this.env.pos._loadMissingPartners(fetchedOrders);
|
||||
// Cache these fetched orders so that next time, no need to fetch
|
||||
// them again, unless invalidated. See `_onInvoiceOrder`.
|
||||
fetchedOrders.forEach((order) => {
|
||||
|
||||
@@ -434,6 +434,7 @@ class PosGlobalState extends PosModel {
|
||||
async load_orders(){
|
||||
var jsons = this.db.get_unpaid_orders();
|
||||
await this._loadMissingProducts(jsons);
|
||||
await this._loadMissingPartners(jsons);
|
||||
var orders = [];
|
||||
|
||||
for (var i = 0; i < jsons.length; i++) {
|
||||
@@ -479,6 +480,32 @@ class PosGlobalState extends PosModel {
|
||||
});
|
||||
this._loadProductProduct(products);
|
||||
}
|
||||
// load the partners based on the ids
|
||||
async _loadPartners(partnerIds) {
|
||||
if (partnerIds.length > 0) {
|
||||
var domain = [['id','in', partnerIds]];
|
||||
const fetchedPartners = await 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,
|
||||
});
|
||||
this.env.pos.db.add_partners(fetchedPartners);
|
||||
}
|
||||
}
|
||||
async _loadMissingPartners(orders) {
|
||||
const missingPartnerIds = new Set([]);
|
||||
for (const order of orders) {
|
||||
const partnerId = order.partner_id;
|
||||
if(missingPartnerIds.has(partnerId)) continue;
|
||||
if (partnerId && !this.db.get_partner_by_id(partnerId)) {
|
||||
missingPartnerIds.add(partnerId);
|
||||
}
|
||||
}
|
||||
await this._loadPartners([...missingPartnerIds]);
|
||||
}
|
||||
async loadProductsBackground() {
|
||||
let page = 0;
|
||||
let products = [];
|
||||
|
||||
@@ -90,7 +90,20 @@ odoo.define('pos_sale.SaleOrderManagementScreen', function (require) {
|
||||
}
|
||||
catch (_error){
|
||||
}
|
||||
currentPOSOrder.set_partner(this.env.pos.db.get_partner_by_id(sale_order.partner_id[0]));
|
||||
let order_partner = this.env.pos.db.get_partner_by_id(sale_order.partner_id[0])
|
||||
if(order_partner){
|
||||
currentPOSOrder.set_client(order_partner);
|
||||
} else {
|
||||
try {
|
||||
await this.env.pos._loadPartners([sale_order.partner_id[0]]);
|
||||
}
|
||||
catch (_error){
|
||||
const title = this.env._t('Customer loading error');
|
||||
const body = _.str.sprintf(this.env._t('There was a problem in loading the %s customer.'), sale_order.partner_id[1]);
|
||||
await this.showPopup('ErrorPopup', { title, body });
|
||||
}
|
||||
currentPOSOrder.set_partner(this.env.pos.db.get_partner_by_id(sale_order.partner_id[0]));
|
||||
}
|
||||
let orderFiscalPos = sale_order.fiscal_position_id ? this.env.pos.fiscal_positions.find(
|
||||
(position) => position.id === sale_order.fiscal_position_id[0]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user