@managesome/eposmatic-toolkit 0.2.716 → 0.2.717

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.
@@ -466,9 +466,11 @@ function getReceiptBody({ orderItems, currency_symbol, show_modifiers, display_m
466
466
  * - ITEM -> the option `ref` is a real menu product id. It can NEVER contain
467
467
  * nested ITEM / HALF_HALF options - it is filtered by partial-menu membership
468
468
  * only, never recursed;
469
- * - HALF_HALF -> the option `ref` is a real menu product id, and its OWN
470
- * top-level modifiers (segment groups) hold options with ref_type ITEM - so
471
- * filtering IS applied recursively there;
469
+ * - HALF_HALF -> the option `ref` is the half-half setup id (not a catalog
470
+ * item id), and its OWN top-level modifiers (segment groups) hold options
471
+ * with ref_type ITEM. Its survival is decided by those segment items:
472
+ * filtering is recursive there, and the option is dropped when nothing
473
+ * survives;
472
474
  * - OPTION (or unset) -> a regular modifier option (size, topping, ...). It is
473
475
  * a terminal leaf: it never contains nested ITEM / HALF_HALF options, so it
474
476
  * passes through fully (never partialed).
@@ -510,25 +512,15 @@ function getTrimmedCompositeModifiers(modifiers, includedItemIds) {
510
512
  keptOptions.push(option);
511
513
  continue;
512
514
  }
513
- // A HALF_HALF option's ref is the half-half SETUP id — never a catalog
514
- // item id, so it is not present in `includedItemIds` (which is built
515
- // from catalog items only). Its survival is decided by its own segment
516
- // groups (options with ref_type ITEM): recurse into them; drop the
517
- // option only when nothing printable is left. Also keep it when the
518
- // setup id is explicitly included (e.g. the whole setup is selected).
519
- if (includedItemIds.has(option.ref)) {
520
- keptOptions.push(option);
521
- continue;
522
- }
515
+ // A HALF_HALF option's ref is the half-half setup id, which is NOT a
516
+ // catalog item id, so it is not present in `includedItemIds` (built from
517
+ // catalog items only). Its survival is decided by its own segment groups
518
+ // (options with ref_type ITEM): recurse into them and keep only the
519
+ // segments whose items are part of the partial menu. Drop the option
520
+ // when nothing printable remains.
523
521
  const nestedModifiers = option.modifiers != null ? getTrimmedCompositeModifiers(option.modifiers, includedItemIds) : null;
524
- // A HALF_HALF option that had constituent parts but none survived the
525
- // filter has nothing printable left -> drop it as well.
526
- if (option.modifiers != null &&
527
- option.modifiers.length > 0 &&
528
- nestedModifiers != null &&
529
- nestedModifiers.length === 0) {
522
+ if (nestedModifiers == null || nestedModifiers.length === 0)
530
523
  continue;
531
- }
532
524
  keptOptions.push({
533
525
  ...option,
534
526
  modifiers: nestedModifiers,
@@ -201,4 +201,54 @@ describe('getPartialItems - composite items on partial KOTs (ref_type)', () => {
201
201
  const trimmedDeal = result.find((c) => c.category_id === 'cat-deals').items[0];
202
202
  expect(trimmedDeal.modifiers[0].options.map((o) => o.ref)).toEqual(['cola-next']);
203
203
  });
204
+ it('drops the whole deal when only the half-half product is selected but none of its inner items are', () => {
205
+ // Mirrors "3 Pizzas for 1600": Large Pizza = Half/Half Pizza Large, plus
206
+ // Medium Pizza (TORENTO) and Small Pizza (MILANO).
207
+ const deal = makeItem('deal-5', '3 Pizzas for 1600', {
208
+ item_type: constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL,
209
+ modifiers: [
210
+ makeModifier('mod-large', 'modref-large', 'Large Pizza', [
211
+ makeOption('opt-half', 'half-pizza-large', 'Half/Half Pizza Large', {
212
+ ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF,
213
+ modifiers: [
214
+ makeModifier('mod-first-half', 'modref-first-half', 'First Half', [
215
+ makeOption('opt-milano-1', 'pizza-milano', 'MILANO', {
216
+ ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
217
+ }),
218
+ ]),
219
+ makeModifier('mod-second-half', 'modref-second-half', 'Second Half', [
220
+ makeOption('opt-milano-2', 'pizza-milano', 'MILANO', {
221
+ ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
222
+ }),
223
+ ]),
224
+ ],
225
+ }),
226
+ ]),
227
+ makeModifier('mod-medium', 'modref-medium', 'Medium Pizza', [
228
+ makeOption('opt-torento', 'pizza-torento', 'TORENTO', {
229
+ ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
230
+ }),
231
+ ]),
232
+ makeModifier('mod-small', 'modref-small', 'Small Pizza', [
233
+ makeOption('opt-milano-small', 'pizza-milano', 'MILANO', {
234
+ ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
235
+ }),
236
+ ]),
237
+ ],
238
+ });
239
+ const categories = [{ name: 'BEVERAGES', category_id: 'cat-bev', items: [deal] }];
240
+ // Partial menu has the deal + the half-half product selected, but NONE of
241
+ // its inner pizzas -> nothing printable should survive.
242
+ const result = (0, receipt_engine_1.getPartialItems)(categories, {
243
+ 'cat-bev': {
244
+ sortId: 0,
245
+ includedItemsMap: {
246
+ 'deal-5': { sortId: 0 },
247
+ 'half-pizza-large': { sortId: 1 },
248
+ },
249
+ },
250
+ });
251
+ const bevCategory = result.find((c) => c.category_id === 'cat-bev');
252
+ expect(bevCategory.items).toHaveLength(0);
253
+ });
204
254
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.716",
3
+ "version": "0.2.717",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",