diff --git a/addons/point_of_sale/static/src/app/store/models.js b/addons/point_of_sale/static/src/app/store/models.js index 878a9020eae..d7eed801921 100644 --- a/addons/point_of_sale/static/src/app/store/models.js +++ b/addons/point_of_sale/static/src/app/store/models.js @@ -1095,22 +1095,19 @@ export class Orderline extends PosModel { } findAttribute(values) { const listOfAttributes = []; - Object.values(this.pos.attributes_by_ptal_id).filter( - (attribute) => { + for (const value of values){ + for (const ptal_id of this.pos.ptal_ids_by_ptav_id[value]){ + const attribute = this.pos.attributes_by_ptal_id[ptal_id] const attFound = attribute.values.filter((target) => { return Object.values(values).includes(target.id); }); - if (attFound.length > 0) { - const modifiedAttribute = { - ...attribute, - valuesForOrderLine: attFound, - }; - listOfAttributes.push(modifiedAttribute); - return true; - } - return false; + const modifiedAttribute = { + ...attribute, + valuesForOrderLine: attFound, + }; + listOfAttributes.push(modifiedAttribute); } - ); + } return listOfAttributes; } getDisplayData() { diff --git a/addons/point_of_sale/static/src/app/store/pos_store.js b/addons/point_of_sale/static/src/app/store/pos_store.js index fd54e2d94a6..645cfbe4193 100644 --- a/addons/point_of_sale/static/src/app/store/pos_store.js +++ b/addons/point_of_sale/static/src/app/store/pos_store.js @@ -286,6 +286,7 @@ export class PosStore extends Reactive { this._loadProductProduct(loadedData["product.product"]); this.db.add_packagings(loadedData["product.packaging"]); this.attributes_by_ptal_id = loadedData["attributes_by_ptal_id"]; + this._add_ptal_ids_by_ptav_id(this.attributes_by_ptal_id); this.cash_rounding = loadedData["account.cash.rounding"]; this.payment_methods = loadedData["pos.payment.method"]; this._loadPosPaymentMethod(); @@ -299,6 +300,23 @@ export class PosStore extends Reactive { await this._loadPosPrinters(loadedData["pos.printer"]); this.open_orders_json = loadedData["open_orders"]; } + _add_ptal_ids_by_ptav_id(attributes_by_ptal_id) { + // Create a cache based on attributes_by_ptal_id + // that enables faster lookup for all ptal_ids + // inside a given attribute's "values" list, + // given a specific ptav_id. + this.ptal_ids_by_ptav_id = {}; + for (const [ptal_id, attribute] of Object.entries(attributes_by_ptal_id)) { + for (const value of attribute["values"]) { + const ptav_id = value["id"]; + if (ptav_id in this.ptal_ids_by_ptav_id) { + this.ptal_ids_by_ptav_id[ptav_id].push(ptal_id); + } else { + this.ptal_ids_by_ptav_id[ptav_id] = [ptal_id]; + } + } + } + } _loadPosSession() { // We need to do it here, since only then the local storage has the correct uuid this.db.save("pos_session_id", this.pos_session.id);