@managesome/eposmatic-toolkit 0.2.791 → 0.2.792
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -281,11 +281,35 @@ function getSelectedVendorInventoryItems(mappedInventory, includedCategories, ca
|
|
|
281
281
|
refToId.set(c.ref_id, c._id);
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
|
-
|
|
284
|
+
// A vendor can hold BOTH a legacy ref_id-keyed entry and a synced
|
|
285
|
+
// _id-keyed entry for one category (the drawer appends the synced entry
|
|
286
|
+
// without recognizing the legacy one). Merge them by canonical category id
|
|
287
|
+
// first — otherwise the legacy entry (typically excluded_items: [])
|
|
288
|
+
// re-includes every item the synced entry excluded, leaking them into the
|
|
289
|
+
// catalog. The `_id`-keyed entry reflects the newest form save, so it wins.
|
|
290
|
+
const mergedCategories = [];
|
|
291
|
+
const mergedIndexByCanonicalId = new Map();
|
|
285
292
|
for (let i = 0; i < includedCategories.length; i++) {
|
|
286
|
-
const
|
|
287
|
-
const
|
|
288
|
-
const
|
|
293
|
+
const entry = includedCategories[i];
|
|
294
|
+
const rawCategoryId = entry.category_id ?? '';
|
|
295
|
+
const canonicalCategoryId = refToId.get(rawCategoryId) ?? rawCategoryId;
|
|
296
|
+
const mergedIndex = mergedIndexByCanonicalId.get(canonicalCategoryId);
|
|
297
|
+
const mergedEntry = {
|
|
298
|
+
category_id: canonicalCategoryId,
|
|
299
|
+
excluded_items: entry.excluded_items ?? [],
|
|
300
|
+
};
|
|
301
|
+
if (mergedIndex === undefined) {
|
|
302
|
+
mergedIndexByCanonicalId.set(canonicalCategoryId, mergedCategories.length);
|
|
303
|
+
mergedCategories.push(mergedEntry);
|
|
304
|
+
}
|
|
305
|
+
else if (rawCategoryId === canonicalCategoryId) {
|
|
306
|
+
mergedCategories[mergedIndex] = mergedEntry;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
const result = [];
|
|
310
|
+
for (let i = 0; i < mergedCategories.length; i++) {
|
|
311
|
+
const { category_id, excluded_items } = mergedCategories[i];
|
|
312
|
+
const items = mappedInventory[category_id ?? ''];
|
|
289
313
|
if (!items)
|
|
290
314
|
continue;
|
|
291
315
|
if (excluded_items.length === 0) {
|
|
@@ -334,9 +358,23 @@ function getGroupedInventoryCategories(categories, items) {
|
|
|
334
358
|
// would omit those items from the group.
|
|
335
359
|
const sortedCategories = [...categories].sort((a, b) => a.sort_id - b.sort_id);
|
|
336
360
|
for (const cat of sortedCategories) {
|
|
361
|
+
// Items can be stored under BOTH keys when legacy (ref_id) and synced
|
|
362
|
+
// (_id) data coexist — merge the two sets instead of the old `||` fallback,
|
|
363
|
+
// which silently dropped one of them. The PO container merges both, so
|
|
364
|
+
// dropped items leaked into the PO without ever being visible/selectable
|
|
365
|
+
// here. De-dupe for the legacy case ref_id === _id.
|
|
366
|
+
const refItems = cat.ref_id ? (itemsByCategory[cat.ref_id] ?? []) : [];
|
|
367
|
+
const idItems = cat._id ? (itemsByCategory[cat._id] ?? []) : [];
|
|
368
|
+
const seenItemIds = new Set();
|
|
369
|
+
const items = [...refItems, ...idItems].filter((item) => {
|
|
370
|
+
if (seenItemIds.has(item._id))
|
|
371
|
+
return false;
|
|
372
|
+
seenItemIds.add(item._id);
|
|
373
|
+
return true;
|
|
374
|
+
});
|
|
337
375
|
result.push({
|
|
338
376
|
category: cat,
|
|
339
|
-
items
|
|
377
|
+
items,
|
|
340
378
|
});
|
|
341
379
|
}
|
|
342
380
|
// Append uncategorized items as a synthetic category (ref_id: null so the API receives null, not a fake string)
|