@darkpos/pricing 1.0.164 → 1.0.165

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.
@@ -375,6 +375,102 @@ describe('addItemModifier Function', () => {
375
375
  expect(result.items[0].price).toBe(129);
376
376
  });
377
377
 
378
+ test('Keep zero price on repair-only parent when adding and removing a compute modifier', () => {
379
+ let order = {
380
+ _id: 'order-repair-only',
381
+ customer: {
382
+ _id: '66bb8d1e38ebaee653177a92',
383
+ tags: ['default'],
384
+ },
385
+ items: [],
386
+ };
387
+
388
+ const parentItem = {
389
+ _id: 'parent1',
390
+ itemId: 'item-blouse',
391
+ name: 'Blouse',
392
+ quantity: 1,
393
+ price: 4.5,
394
+ modifiers: [],
395
+ priceLevels: [
396
+ {
397
+ value: 4.5,
398
+ tags: ['default'],
399
+ },
400
+ ],
401
+ };
402
+
403
+ order = pricingService.order.addItem({
404
+ order,
405
+ item: parentItem,
406
+ }).updatedOrder;
407
+
408
+ const addedParent = order.items.find(each => each.itemId === 'item-blouse');
409
+ expect(addedParent.price).toBe(4.5);
410
+
411
+ const relatedItem = {
412
+ _id: 'related1',
413
+ itemId: 'item-sleeve',
414
+ name: 'Blouse Sleeve',
415
+ quantity: 1,
416
+ price: 10,
417
+ modifiers: [],
418
+ properties: {
419
+ relatedItem: true,
420
+ parentItemId: addedParent.itemId,
421
+ parentId: addedParent._id,
422
+ repairOnly: true,
423
+ },
424
+ };
425
+
426
+ order = pricingService.order.addItem({
427
+ order,
428
+ item: relatedItem,
429
+ }).updatedOrder;
430
+
431
+ const parentIndex = order.items.findIndex(
432
+ each => each._id === addedParent._id
433
+ );
434
+ expect(order.items[parentIndex].price).toBe(0);
435
+
436
+ const linenModifier = {
437
+ _id: 'mod-linen',
438
+ modifierId: 'mod-linen',
439
+ name: 'Linen',
440
+ tags: ['default'],
441
+ direct: true,
442
+ included: true,
443
+ compute: {
444
+ type: 'fixed',
445
+ action: 'add',
446
+ amount: 1,
447
+ },
448
+ };
449
+
450
+ order = pricingService.order.addItemModifier({
451
+ order,
452
+ modifier: linenModifier,
453
+ itemIndex: parentIndex,
454
+ });
455
+
456
+ expect(order.items[parentIndex].price).toBe(0);
457
+
458
+ const calculated = pricingService.order.calculate(order);
459
+ expect(calculated.items[parentIndex].price).toBe(0);
460
+ expect(calculated.items[parentIndex].total).toBe(1);
461
+
462
+ order = pricingService.order.removeItemModifier({
463
+ order,
464
+ modifier: order.items[parentIndex].modifiers.find(
465
+ mod => mod.modifierId === 'mod-linen'
466
+ ),
467
+ itemIndex: parentIndex,
468
+ });
469
+
470
+ expect(order.items[parentIndex].price).toBe(0);
471
+ expect(order.items[parentIndex].total).toBe(0);
472
+ });
473
+
378
474
  test('Calculate item with Override Modifier and unitAsAmountMultiplier=true', () => {
379
475
  const item = {
380
476
  location: {},
@@ -44,11 +44,13 @@ module.exports = ({ actions, modifierActions, itemActions, _ }) => {
44
44
  originalItem,
45
45
  });
46
46
 
47
- item.price = itemActions.getItemPrice({
48
- item,
49
- itemPriceLevels: originalItem ? originalItem.priceLevels : undefined,
50
- customer,
51
- });
47
+ if (!itemActions.isPriceChanged(item)) {
48
+ item.price = itemActions.getItemPrice({
49
+ item,
50
+ itemPriceLevels: originalItem ? originalItem.priceLevels : undefined,
51
+ customer,
52
+ });
53
+ }
52
54
 
53
55
  order.items[itemIndex] = item;
54
56
 
@@ -6,6 +6,10 @@ module.exports = ({ itemActions }) =>
6
6
  {
7
7
  ...item,
8
8
  price: 0,
9
+ properties: {
10
+ ...(item.properties || {}),
11
+ priceChanged: true,
12
+ },
9
13
  },
10
14
  {}
11
15
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkpos/pricing",
3
- "version": "1.0.164",
3
+ "version": "1.0.165",
4
4
  "description": "Pricing calculator",
5
5
  "author": "Dark POS",
6
6
  "license": "ISC",
@@ -54,5 +54,5 @@
54
54
  "supertest": "^6.2.3",
55
55
  "supervisor": "^0.12.0"
56
56
  },
57
- "gitHead": "b9786e89438ac14114630c52ecaf5f4770aa2bf8"
57
+ "gitHead": "61d006e904d8c5158a4bb0825d207d3c9465280c"
58
58
  }