Skip to content

Commit eb63730

Browse files
committed
[FIX] fixed error when closing the customer screen without selecting one + dirty fix to check connectivity before loading the pricelist
1 parent 1a0e6c8 commit eb63730

2 files changed

Lines changed: 30 additions & 15 deletions

File tree

addons/point_of_sale/static/src/app/store/pos_store.js

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,26 +1969,40 @@ export class PosStore extends Reactive {
19691969
partner: currentPartner,
19701970
getPayload: (newPartner) => currentOrder.set_partner(newPartner),
19711971
});
1972-
let pricelistId = payload.pos_property_product_pricelist_id;
19731972

1974-
if (payload && Boolean(pricelistId)) {
1973+
try {
1974+
if (payload && Boolean(payload.pos_property_product_pricelist_id)) {
1975+
let pricelistId = payload.pos_property_product_pricelist_id;
1976+
let pricelist = this.models["product.pricelist"].find((item) => item.id === pricelistId);
1977+
if (!Boolean(pricelist)) {
1978+
await loadPricelistItems(this, pricelistId);
1979+
pricelist = this.models["product.pricelist"].find((item) => item.id === pricelistId);
1980+
}
1981+
if (Boolean(pricelist)) {
1982+
payload.property_product_pricelist = pricelist;
1983+
const orderLines = currentOrder.get_orderlines();
1984+
for (const lineIndex in orderLines) {
1985+
let line = orderLines[lineIndex];
1986+
await computeProductPricelistCacheOfProductAndPricelist(this, [], line.product_id, pricelistId);
1987+
}
1988+
}
19751989

1976-
let pricelist = this.models["product.pricelist"].find((item) => item.id === pricelistId);
1977-
if (!Boolean(pricelist)) {
1978-
await loadPricelistItems(this, pricelistId);
1979-
pricelist = this.models["product.pricelist"].find((item) => item.id === pricelistId);
19801990
}
1981-
if (Boolean(pricelist)) {
1982-
payload.property_product_pricelist = pricelist;
1983-
const orderLines = currentOrder.get_orderlines();
1984-
for (const lineIndex in orderLines) {
1985-
let line = orderLines[lineIndex];
1986-
await computeProductPricelistCacheOfProductAndPricelist(this, [], line.product_id, pricelistId);
1987-
}
1991+
} catch (error) {
1992+
console.log(error)
1993+
let message;
1994+
if (error instanceof ConnectionLostError) {
1995+
message = _t(
1996+
"Connection to the server has been lost. Please check your internet connection."
1997+
);
1998+
} else {
1999+
message = error.data.message;
19882000
}
1989-
2001+
this.env.services.dialog.add(AlertDialog, {
2002+
title: _t("Failure to apply pricelist of the customer"),
2003+
body: message,
2004+
});
19902005
}
1991-
19922006
if (payload) {
19932007
currentOrder.set_partner(payload);
19942008
} else {

addons/point_of_sale/static/src/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ export function computeProductPricelistCache(service, data = []) {
257257
}
258258

259259
export async function loadPricelistItems(service, pricelist_id) {
260+
await service.data.read("pos.config", [service.config.id], ["id"]); // dirty fix to check connectivity
260261
await service.data.callRelated("pos.session", "get_pos_uis_product_pricelist_item_by_pricelist", [
261262
odoo.pos_session_id,
262263
service.config.id,

0 commit comments

Comments
 (0)