Skip to content

Commit 1a2df95

Browse files
committed
[FIX] pos: get method to read both id and uuid
1 parent ca13d6e commit 1a2df95

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

addons/point_of_sale/static/src/app/models/related_models/index.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,29 @@ export function createRelatedModels(modelDefs, modelClasses = {}, opts = {}) {
9999
return result;
100100
}
101101

102+
getUuidFromId(id) {
103+
if (typeof id === "string") {
104+
return id;
105+
}
106+
const modelUuids = this.map((rec) => rec.uuid);
107+
const idUpdates = JSON.parse(localStorage.getItem("idUpdates")) || {};
108+
const entry = Object.entries(idUpdates).find(
109+
([_uuid, _id]) => modelUuids.includes(_uuid) && _id === id
110+
);
111+
if (entry) {
112+
return entry[0];
113+
}
114+
return false;
115+
}
116+
102117
read(value) {
103118
const id = /^\d+$/.test(value) ? parseInt(value) : value; // In case of ID came from an input
104-
return this[STORE_SYMBOL].getById(this.name, id);
119+
const record = this[STORE_SYMBOL].getById(this.name, id);
120+
const uuid = record || this.fields["uuid"] ? this.getUuidFromId(id) : null;
121+
if (record || !uuid) {
122+
return record;
123+
}
124+
return this[STORE_SYMBOL].get(this.name, "uuid", uuid);
105125
}
106126

107127
readFirst() {

addons/point_of_sale/static/tests/unit/related_models/related_models.test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,6 @@ describe("Related Model", () => {
669669
order.sampleData = "test";
670670

671671
expect(order.lines.length).toBe(1);
672-
const oldLineId = order.lines[0].id;
673672
expect(typeof oldOrderId).toBe("string");
674673
expect(models["pos.order"].get(oldOrderId)).not.toBeEmpty();
675674

@@ -694,11 +693,9 @@ describe("Related Model", () => {
694693
expect(order.lines[0].name).toBe("Line 1111");
695694

696695
//Find by ids, uuids
697-
expect(models["pos.order"].get(oldOrderId)).toBe(undefined);
698696
expect(models["pos.order"].get(order.id)).toBe(order);
699697
expect(models["pos.order"].getBy("uuid", order.uuid)).toBe(order);
700698

701-
expect(models["pos.order.line"].get(oldLineId)).toBe(undefined);
702699
expect(models["pos.order.line"].get(line.id)).toBe(line);
703700
expect(models["pos.order.line"].getBy("uuid", line.uuid)).toBe(line);
704701
});

0 commit comments

Comments
 (0)