[FIX] point_of_sale: load partners when scanning barcode

Before this commit, because limited partner loading is enabled by
default, only a limited number of partners were loaded. If the user
tries to add a partner that is not loaded in the PoS, it is not
fetched from the server.

To fix this, we should load the partner when their barcode is scanned.

opw-3398628

closes odoo/odoo#129798

X-original-commit: 6b7e18382ec35565ed978bb0ba7f3d5fd6c5e76c
Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
Signed-off-by: Ahmad Khanalizadeh (khah) <khah@odoo.com>
This commit is contained in:
Ahmad Khanalizadeh
2023-07-27 10:32:53 +02:00
parent 2fc8a324d1
commit 6dfb294b43
@@ -183,8 +183,23 @@ export class ProductScreen extends ControlButtonsMixin(Component) {
this.currentOrder.add_product(product, options);
this.numberBuffer.reset();
}
_barcodePartnerAction(code) {
const partner = this.pos.db.get_partner_by_barcode(code.code);
async _getPartnerByBarcode(code) {
let partner = this.pos.db.get_partner_by_barcode(code.code);
if (!partner) {
// find the partner in the backend by the barcode
const foundPartnerIds = await this.orm.search("res.partner", [
["barcode", "=", code.code]
]);
if (foundPartnerIds.length) {
await this.pos._loadPartners(foundPartnerIds);
// assume that the result is unique.
partner = this.pos.db.get_partner_by_id(foundPartnerIds[0]);
}
}
return partner;
}
async _barcodePartnerAction(code) {
const partner = await this._getPartnerByBarcode(code);
if (partner) {
if (this.currentOrder.get_partner() !== partner) {
this.currentOrder.set_partner(partner);