@darkpos/pricing 1.0.139 → 1.0.141

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.
@@ -1,5 +1,6 @@
1
1
  const usePricing = require('../index');
2
2
  const mockStores = require('./mocks/stores');
3
+ const itemMerge = require('./mocks/items/addItemMerge.json');
3
4
 
4
5
  const session = {
5
6
  store: mockStores[0],
@@ -2677,5 +2678,21 @@ describe('Item actions', () => {
2677
2678
  expect(updatedOrder.items[0].modifiers.length).toBe(1);
2678
2679
  expect(updatedOrder.items[0].modifiers[0].modifierId).toBe('mod-shared');
2679
2680
  });
2681
+
2682
+ test('mergeWithParentItem using payload from frontend sets merged parent price to 14.5', () => {
2683
+ const { updatedOrder, item: updatedItem } = pricingService.order.addItem({
2684
+ order: itemMerge.order,
2685
+ item: itemMerge.item,
2686
+ itemIndex: itemMerge.itemIndex,
2687
+ autoBarcode: false,
2688
+ });
2689
+
2690
+ expect(updatedOrder.items.length).toBe(1);
2691
+ expect(updatedOrder.items[0]._id).toBe('6995e8f62c1da14e79747d68');
2692
+ expect(updatedOrder.items[0].name).toBe('Blouse - Blouse Side Seam');
2693
+ expect(updatedOrder.items[0].price).toBe(14.5);
2694
+ expect(updatedItem._id).toBe('6995e8f62c1da14e79747d68');
2695
+ expect(updatedItem.price).toBe(14.5);
2696
+ });
2680
2697
  });
2681
2698
  });
@@ -0,0 +1,770 @@
1
+ {
2
+ "order": {
3
+ "parentId": null,
4
+ "isParent": false,
5
+ "subTotal": 4.5,
6
+ "tax": 0,
7
+ "modifiers": [],
8
+ "discount": 0,
9
+ "total": 4.73,
10
+ "description": "",
11
+ "displayId": "",
12
+ "type": "",
13
+ "location": {},
14
+ "status": {
15
+ "detailed": false,
16
+ "picked": false,
17
+ "paid": false,
18
+ "order": "open"
19
+ },
20
+ "attributes": [],
21
+ "properties": {
22
+ "pieceCount": 0
23
+ },
24
+ "fee": 0,
25
+ "user": null,
26
+ "items": [
27
+ {
28
+ "location": {},
29
+ "status": {
30
+ "picked": {
31
+ "value": false,
32
+ "date": ""
33
+ },
34
+ "paid": {
35
+ "value": false,
36
+ "date": ""
37
+ },
38
+ "tracker": []
39
+ },
40
+ "name": "Blouse",
41
+ "description": "",
42
+ "pieces": 0,
43
+ "modifiersTotalAmount": 0,
44
+ "total": 4.73,
45
+ "totalPaid": 0,
46
+ "price": 4.5,
47
+ "quantity": 1,
48
+ "path": ",68a0ea81aa30dd1524162285,68a102e959fd1012e3aaa97a,",
49
+ "notes": [],
50
+ "serial": null,
51
+ "sku": "",
52
+ "modifiers": [
53
+ {
54
+ "_id": "6995e8f62c1da14e79747d69",
55
+ "attributes": [
56
+ "department"
57
+ ],
58
+ "modifierId": "68a0eedba4582a7ef17e9a35",
59
+ "_parentId": null,
60
+ "locked": false,
61
+ "name": "Dry Cleaning",
62
+ "sku": "",
63
+ "description": "",
64
+ "group": "",
65
+ "type": "",
66
+ "tags": [
67
+ "default",
68
+ "police"
69
+ ],
70
+ "order": 0,
71
+ "included": false,
72
+ "direct": true,
73
+ "hidden": false,
74
+ "print": false,
75
+ "required": true,
76
+ "recommended": false,
77
+ "default": false,
78
+ "code": "D",
79
+ "properties": {
80
+ "group": null,
81
+ "department": {
82
+ "tagSize": "big",
83
+ "splitUnit": "quantity",
84
+ "maxItems": "6",
85
+ "autoSplit": true,
86
+ "keepRelatedItems": true
87
+ },
88
+ "sort": null
89
+ },
90
+ "_computed": {
91
+ "amount": 0,
92
+ "description": "Dry Cleaning"
93
+ },
94
+ "conditions": {
95
+ "valid": true
96
+ },
97
+ "compute": null,
98
+ "_createdAt": "2025-08-16T20:49:31.368Z",
99
+ "_updatedAt": "2026-01-07T16:01:13.575Z",
100
+ "__typename": "Modifier",
101
+ "addModifiers": [],
102
+ "delModifiers": []
103
+ },
104
+ {
105
+ "_id": "6995e8f62c1da14e79747d6b",
106
+ "attributes": [],
107
+ "modifierId": "68a1005bb49860bc58c2ce90",
108
+ "_parentId": null,
109
+ "locked": false,
110
+ "name": "Prepay discount",
111
+ "sku": "",
112
+ "description": "",
113
+ "group": "Discount",
114
+ "type": "discount",
115
+ "tags": [
116
+ "default"
117
+ ],
118
+ "order": 0,
119
+ "included": false,
120
+ "direct": true,
121
+ "hidden": false,
122
+ "print": true,
123
+ "required": false,
124
+ "recommended": false,
125
+ "default": true,
126
+ "code": "",
127
+ "properties": {
128
+ "override": null,
129
+ "sort": 3,
130
+ "isQuantityMultiplier": true
131
+ },
132
+ "_computed": {
133
+ "amount": 0,
134
+ "description": "Prepay discount"
135
+ },
136
+ "conditions": {
137
+ "valid": false,
138
+ "rules": [
139
+ {
140
+ "key": "payment",
141
+ "value": "prepay",
142
+ "operand": "$in"
143
+ }
144
+ ]
145
+ },
146
+ "compute": {
147
+ "type": "percentage",
148
+ "action": "subtract",
149
+ "amount": 10
150
+ },
151
+ "_createdAt": "2025-08-16T22:04:11.497Z",
152
+ "_updatedAt": "2026-01-20T21:13:15.668Z",
153
+ "__typename": "Modifier",
154
+ "addModifiers": [],
155
+ "delModifiers": []
156
+ },
157
+ {
158
+ "_id": "6995e8f62c1da14e79747d6c",
159
+ "attributes": [],
160
+ "modifierId": "698666f3951a06401bd31fdb",
161
+ "_parentId": null,
162
+ "locked": false,
163
+ "name": "25% Family discount",
164
+ "sku": "",
165
+ "description": "",
166
+ "group": "",
167
+ "type": "",
168
+ "tags": [
169
+ "default"
170
+ ],
171
+ "order": 0,
172
+ "included": false,
173
+ "direct": true,
174
+ "hidden": false,
175
+ "print": true,
176
+ "required": false,
177
+ "recommended": false,
178
+ "default": true,
179
+ "code": "",
180
+ "properties": {
181
+ "override": null,
182
+ "sort": null
183
+ },
184
+ "_computed": {
185
+ "amount": 0,
186
+ "description": "25% Family discount"
187
+ },
188
+ "conditions": {
189
+ "valid": false,
190
+ "rules": [
191
+ {
192
+ "key": "itemQuantity",
193
+ "value": "2",
194
+ "operand": "$gte"
195
+ }
196
+ ]
197
+ },
198
+ "compute": {
199
+ "type": "percentage",
200
+ "action": "subtract",
201
+ "amount": 25
202
+ },
203
+ "_createdAt": "2026-02-06T22:10:59.265Z",
204
+ "_updatedAt": "2026-02-06T22:35:06.808Z",
205
+ "__typename": "Modifier",
206
+ "addModifiers": [],
207
+ "delModifiers": []
208
+ },
209
+ {
210
+ "_id": "6995e8f62c1da14e79747d6a",
211
+ "attributes": [],
212
+ "modifierId": "68a10008a4582a7ef17eb3ec",
213
+ "_parentId": null,
214
+ "locked": false,
215
+ "name": "Tax 5%",
216
+ "sku": "",
217
+ "description": "",
218
+ "group": "Tax",
219
+ "type": "tax",
220
+ "tags": [
221
+ "default"
222
+ ],
223
+ "order": 0,
224
+ "included": false,
225
+ "direct": true,
226
+ "hidden": false,
227
+ "print": false,
228
+ "required": true,
229
+ "recommended": false,
230
+ "default": false,
231
+ "code": "",
232
+ "properties": {
233
+ "override": null,
234
+ "sort": 5,
235
+ "isQuantityMultiplier": true
236
+ },
237
+ "_computed": {
238
+ "amount": 0.23,
239
+ "description": "Tax 5% ($0.23)"
240
+ },
241
+ "conditions": {
242
+ "valid": true,
243
+ "rules": []
244
+ },
245
+ "compute": {
246
+ "type": "percentage",
247
+ "action": "add",
248
+ "amount": 5
249
+ },
250
+ "_createdAt": "2025-08-16T22:02:48.698Z",
251
+ "_updatedAt": "2026-01-20T20:19:08.047Z",
252
+ "__typename": "Modifier",
253
+ "addModifiers": [],
254
+ "delModifiers": []
255
+ }
256
+ ],
257
+ "_id": "6995e8f62c1da14e79747d68",
258
+ "_updatedAt": "2026-02-12T21:09:29.319Z",
259
+ "_createdAt": "2025-08-16T21:48:12.777Z",
260
+ "weight": 0,
261
+ "properties": {},
262
+ "hasInventory": true,
263
+ "inventoryType": "push",
264
+ "serialRequired": null,
265
+ "tags": [],
266
+ "category": null,
267
+ "__typename": "OrderItem",
268
+ "priceLevels": [
269
+ {
270
+ "value": 4.5,
271
+ "tags": [
272
+ "default"
273
+ ]
274
+ },
275
+ {
276
+ "value": 3.5,
277
+ "tags": [
278
+ "default",
279
+ "press only"
280
+ ]
281
+ }
282
+ ],
283
+ "costLevels": [],
284
+ "itemId": "68a0fc9caa30dd1524163766",
285
+ "menuRuleId": "68a103ad59fd1012e3aaa992",
286
+ "subTotals": {
287
+ "_included": 0,
288
+ "_xincluded": 0.23,
289
+ "_direct": 0.23,
290
+ "_xdirect": 0,
291
+ "_simple": 4.5,
292
+ "_actual": 4.5,
293
+ "tax": 0.23
294
+ },
295
+ "picked": {
296
+ "value": false,
297
+ "date": ""
298
+ },
299
+ "paid": {
300
+ "value": false,
301
+ "date": ""
302
+ },
303
+ "tracker": []
304
+ }
305
+ ],
306
+ "notes": [
307
+ {
308
+ "_id": "6995e8d42c1da14e79747d67",
309
+ "message": "",
310
+ "attributes": [
311
+ "print"
312
+ ],
313
+ "type": "",
314
+ "name": "",
315
+ "date": "2026-02-18T16:29:08.183Z",
316
+ "user": {
317
+ "_id": "68a0b1b7a4582a7ef17dd169",
318
+ "_accountId": "68a0b1b7aa30dd1524152178",
319
+ "firstName": "Admin",
320
+ "lastName": "Admin",
321
+ "username": "cleanshow"
322
+ },
323
+ "url": ""
324
+ }
325
+ ],
326
+ "customer": {
327
+ "_id": "68ab3e9f1a3b4b470c5fd3e4",
328
+ "username": "",
329
+ "firstName": "bob",
330
+ "lastName": "Ham",
331
+ "description": null,
332
+ "attributes": [],
333
+ "properties": {
334
+ "company": "",
335
+ "billing": {
336
+ "cycle": null,
337
+ "limit": "0"
338
+ },
339
+ "events": [],
340
+ "relationships": [],
341
+ "charge": {
342
+ "walletCard": null
343
+ }
344
+ },
345
+ "tags": [
346
+ "default"
347
+ ],
348
+ "status": null,
349
+ "parent": null,
350
+ "parentId": null,
351
+ "loyalty": null,
352
+ "stats": {
353
+ "lastVisit": "2026-02-16T16:25:47.594Z",
354
+ "totalVisits": 16,
355
+ "totalSales": 2062.92,
356
+ "salesRank": 1,
357
+ "totalPoints": 2023,
358
+ "balance": 1217.31
359
+ },
360
+ "modifiers": [
361
+ {
362
+ "_id": "69739464562d4464679e964c",
363
+ "modifierId": null,
364
+ "_parentId": null,
365
+ "locked": false,
366
+ "name": "Subscription ( 5 Pants )_Pants",
367
+ "sku": null,
368
+ "group": null,
369
+ "type": null,
370
+ "attributes": [
371
+ "subscription"
372
+ ],
373
+ "cost": 0,
374
+ "tags": [],
375
+ "order": null,
376
+ "included": false,
377
+ "direct": true,
378
+ "hidden": false,
379
+ "required": false,
380
+ "recommended": false,
381
+ "default": false,
382
+ "code": null,
383
+ "conditions": null,
384
+ "compute": null,
385
+ "_computed": null,
386
+ "_hidden": false,
387
+ "properties": {
388
+ "subscription": {
389
+ "subscriptionId": "69739464562d4464679e962e",
390
+ "dateLimit": {
391
+ "from": "2026-01-23T15:31:48.062Z",
392
+ "to": "1970-01-01T00:00:00.000Z"
393
+ },
394
+ "item": {
395
+ "id": "6973944f788628d9c9245e84",
396
+ "itemId": "68a0f4eda4582a7ef17ea048",
397
+ "name": "Pants",
398
+ "serial": "Test0000005884",
399
+ "limit": 5,
400
+ "usesLimit": 5,
401
+ "uses": 0,
402
+ "renewalType": "none"
403
+ }
404
+ }
405
+ }
406
+ },
407
+ {
408
+ "_id": "6973c06c6685c8a174d98b0e",
409
+ "modifierId": null,
410
+ "_parentId": null,
411
+ "locked": false,
412
+ "name": "Subscription ( 5 Pants )_Pants",
413
+ "sku": null,
414
+ "group": null,
415
+ "type": null,
416
+ "attributes": [
417
+ "subscription"
418
+ ],
419
+ "cost": 0,
420
+ "tags": [],
421
+ "order": null,
422
+ "included": false,
423
+ "direct": true,
424
+ "hidden": false,
425
+ "required": false,
426
+ "recommended": false,
427
+ "default": false,
428
+ "code": null,
429
+ "conditions": null,
430
+ "compute": null,
431
+ "_computed": null,
432
+ "_hidden": false,
433
+ "properties": {
434
+ "subscription": {
435
+ "subscriptionId": "6973c06c6685c8a174d98a76",
436
+ "dateLimit": {
437
+ "from": "2026-01-23T18:39:40.248Z",
438
+ "to": "1970-01-01T00:00:00.000Z"
439
+ },
440
+ "item": {
441
+ "id": "6973c01ea69c2680509c570b",
442
+ "itemId": "68a0f4eda4582a7ef17ea048",
443
+ "name": "Pants",
444
+ "serial": "",
445
+ "limit": 5,
446
+ "usesLimit": 5,
447
+ "uses": 0,
448
+ "renewalType": "none"
449
+ }
450
+ }
451
+ }
452
+ }
453
+ ],
454
+ "addresses": [],
455
+ "contacts": [],
456
+ "notes": [],
457
+ "_accountId": "68a0b1b7aa30dd1524152178",
458
+ "_storeId": "68a0b1b7f53773001282b971",
459
+ "_isDeleted": false,
460
+ "_deletedAt": null,
461
+ "_updatedAt": "2026-02-16T22:01:07.377Z",
462
+ "_createdAt": "2025-08-24T16:32:31.087Z",
463
+ "isEmbedded": true
464
+ },
465
+ "start": {
466
+ "location": {
467
+ "name": "Clean Show 2025",
468
+ "locationType": "store",
469
+ "storeId": "68a0b1b7f53773001282b971"
470
+ },
471
+ "requestDate": "2026-02-18T16:29:08.183Z"
472
+ },
473
+ "end": {
474
+ "location": {
475
+ "name": "Clean Show 2025",
476
+ "locationType": "store",
477
+ "storeId": "68a0b1b7f53773001282b971"
478
+ },
479
+ "requestDate": "2026-02-18T16:29:00Z"
480
+ },
481
+ "_storeId": "",
482
+ "__typename": "Order",
483
+ "subTotals": {
484
+ "tax": 0.23
485
+ },
486
+ "totalPaid": 0
487
+ },
488
+ "item": {
489
+ "_id": null,
490
+ "name": "Blouse Side Seam",
491
+ "sku": "",
492
+ "description": "",
493
+ "price": 0,
494
+ "hasInventory": true,
495
+ "inventoryType": "push",
496
+ "quantity": 1,
497
+ "pieces": 1,
498
+ "weight": 0,
499
+ "priceLevels": [
500
+ {
501
+ "value": 10,
502
+ "tags": [
503
+ "default"
504
+ ],
505
+ "_id": "68a396b0aa30dd152418166e"
506
+ },
507
+ {
508
+ "value": 0,
509
+ "tags": [
510
+ "default",
511
+ "press only"
512
+ ],
513
+ "_id": "68a396b0aa30dd152418166f"
514
+ }
515
+ ],
516
+ "tags": [],
517
+ "cost": 0,
518
+ "modifiers": [],
519
+ "_accountId": "68a0b1b7aa30dd1524152178",
520
+ "_storeId": "68a0b1b7f53773001282b971",
521
+ "_isDeleted": false,
522
+ "costLevels": [],
523
+ "notes": [],
524
+ "_createdAt": "2025-08-18T21:10:08.332Z",
525
+ "_updatedAt": "2025-08-20T15:32:56.103Z",
526
+ "_version": 1,
527
+ "__typename": "Item",
528
+ "properties": {
529
+ "relatedItem": true,
530
+ "parentItemId": "68a0fc9caa30dd1524163766",
531
+ "parentId": "6995e8f62c1da14e79747d68",
532
+ "repairOnly": false,
533
+ "removeParentItem": false,
534
+ "mergeWithParentItem": true,
535
+ "addModifiers": [
536
+ {
537
+ "_id": "68a39e72aa30dd1524183961",
538
+ "attributes": [
539
+ "group"
540
+ ],
541
+ "modifierId": null,
542
+ "_parentId": null,
543
+ "locked": false,
544
+ "name": "Repair Blouse",
545
+ "sku": "",
546
+ "description": "",
547
+ "group": "",
548
+ "type": "",
549
+ "tags": [
550
+ "default"
551
+ ],
552
+ "order": 0,
553
+ "included": false,
554
+ "direct": true,
555
+ "hidden": false,
556
+ "print": true,
557
+ "required": false,
558
+ "recommended": false,
559
+ "default": false,
560
+ "code": "",
561
+ "properties": {
562
+ "override": null,
563
+ "group": {
564
+ "modifiers": [],
565
+ "items": [],
566
+ "displayType": "card",
567
+ "enableAutoPopup": true,
568
+ "displayReplacePrompt": true,
569
+ "manualModifiers": "",
570
+ "promptMessage": "",
571
+ "removeParentItem": false,
572
+ "mergeWithParentItem": true
573
+ },
574
+ "sort": null
575
+ },
576
+ "_computed": null,
577
+ "conditions": null,
578
+ "compute": null,
579
+ "_createdAt": "2025-08-18T21:43:14.157Z",
580
+ "_updatedAt": "2026-02-09T16:22:53.654Z",
581
+ "__typename": "Modifier",
582
+ "addModifiers": [
583
+ {
584
+ "_id": "68a0efefaa30dd1524162a07",
585
+ "attributes": [
586
+ "department"
587
+ ],
588
+ "modifierId": null,
589
+ "_parentId": null,
590
+ "locked": false,
591
+ "name": "D+T",
592
+ "sku": "",
593
+ "description": "",
594
+ "group": "",
595
+ "type": "",
596
+ "tags": [
597
+ "default"
598
+ ],
599
+ "order": 0,
600
+ "included": false,
601
+ "direct": true,
602
+ "hidden": false,
603
+ "print": false,
604
+ "required": false,
605
+ "recommended": false,
606
+ "default": false,
607
+ "code": "DT",
608
+ "properties": {
609
+ "department": {
610
+ "tagSize": "big",
611
+ "splitUnit": "quantity",
612
+ "maxItems": "",
613
+ "autoSplit": true,
614
+ "keepRelatedItems": true
615
+ },
616
+ "sort": null
617
+ },
618
+ "_computed": null,
619
+ "conditions": null,
620
+ "compute": null,
621
+ "_createdAt": "2025-08-16T20:54:07.726Z",
622
+ "_updatedAt": "2025-08-16T20:54:07.726Z",
623
+ "__typename": "Modifier"
624
+ }
625
+ ],
626
+ "delModifiers": [
627
+ {
628
+ "_id": "68a0eedba4582a7ef17e9a35",
629
+ "attributes": [
630
+ "department"
631
+ ],
632
+ "modifierId": null,
633
+ "_parentId": null,
634
+ "locked": false,
635
+ "name": "Dry Cleaning",
636
+ "sku": "",
637
+ "description": "",
638
+ "group": "",
639
+ "type": "",
640
+ "tags": [
641
+ "default",
642
+ "police"
643
+ ],
644
+ "order": 0,
645
+ "included": false,
646
+ "direct": true,
647
+ "hidden": false,
648
+ "print": false,
649
+ "required": true,
650
+ "recommended": false,
651
+ "default": false,
652
+ "code": "D",
653
+ "properties": {
654
+ "subscription": {},
655
+ "override": {},
656
+ "group": null,
657
+ "department": {
658
+ "tagSize": "big",
659
+ "splitUnit": "quantity",
660
+ "maxItems": "6",
661
+ "autoSplit": true,
662
+ "keepRelatedItems": true
663
+ },
664
+ "sort": null
665
+ },
666
+ "_computed": null,
667
+ "conditions": null,
668
+ "compute": null,
669
+ "_createdAt": "2025-08-16T20:49:31.368Z",
670
+ "_updatedAt": "2026-01-07T16:01:13.575Z",
671
+ "__typename": "Modifier"
672
+ }
673
+ ]
674
+ }
675
+ ],
676
+ "groupPath": ",68a39e72aa30dd1524183961"
677
+ },
678
+ "itemModifiers": [
679
+ {
680
+ "_id": "68a0efefaa30dd1524162a07",
681
+ "attributes": [
682
+ "department"
683
+ ],
684
+ "modifierId": null,
685
+ "_parentId": null,
686
+ "locked": false,
687
+ "name": "D+T",
688
+ "sku": "",
689
+ "description": "",
690
+ "group": "",
691
+ "type": "",
692
+ "tags": [
693
+ "default"
694
+ ],
695
+ "order": 0,
696
+ "included": false,
697
+ "direct": true,
698
+ "hidden": false,
699
+ "print": false,
700
+ "required": false,
701
+ "recommended": false,
702
+ "default": false,
703
+ "code": "DT",
704
+ "properties": {
705
+ "department": {
706
+ "tagSize": "big",
707
+ "splitUnit": "quantity",
708
+ "maxItems": "",
709
+ "autoSplit": true,
710
+ "keepRelatedItems": true
711
+ },
712
+ "sort": null
713
+ },
714
+ "_computed": null,
715
+ "conditions": null,
716
+ "compute": null,
717
+ "_createdAt": "2025-08-16T20:54:07.726Z",
718
+ "_updatedAt": "2025-08-16T20:54:07.726Z",
719
+ "__typename": "Modifier"
720
+ },
721
+ {
722
+ "_id": "68a0ef40a4582a7ef17e9b0f",
723
+ "attributes": [
724
+ "department"
725
+ ],
726
+ "modifierId": null,
727
+ "_parentId": null,
728
+ "locked": false,
729
+ "name": "Tailoring",
730
+ "sku": "",
731
+ "description": "",
732
+ "group": "",
733
+ "type": "",
734
+ "tags": [
735
+ "default",
736
+ "police"
737
+ ],
738
+ "order": 0,
739
+ "included": false,
740
+ "direct": true,
741
+ "hidden": false,
742
+ "print": false,
743
+ "required": true,
744
+ "recommended": false,
745
+ "default": false,
746
+ "code": "T",
747
+ "properties": {
748
+ "department": {
749
+ "tagSize": "big",
750
+ "splitUnit": "quantity",
751
+ "maxItems": "",
752
+ "autoSplit": true
753
+ },
754
+ "sort": null
755
+ },
756
+ "_computed": null,
757
+ "conditions": null,
758
+ "compute": null,
759
+ "_createdAt": "2025-08-16T20:51:12.231Z",
760
+ "_updatedAt": "2025-12-26T23:00:11.332Z",
761
+ "__typename": "Modifier",
762
+ "addModifiers": [],
763
+ "delModifiers": []
764
+ }
765
+ ],
766
+ "itemId": "68a396b0aa30dd152418166d",
767
+ "menuRuleId": "68a103ad59fd1012e3aaa992"
768
+ },
769
+ "itemIndex": -1
770
+ }
@@ -3808,6 +3808,27 @@ describe('Order actions', () => {
3808
3808
  expect(newOrder2.items[0].status).toMatchObject({ paid: { value: true } });
3809
3809
  });
3810
3810
 
3811
+ test('Mark paid status true if totalPaid is greater than total', () => {
3812
+ const orderItem = {
3813
+ price: 25,
3814
+ quantity: 1,
3815
+ status: {},
3816
+ totalPaid: 30,
3817
+ };
3818
+ const pricing = usePricing({
3819
+ store: { _settings: { order: { autoMarkAsPaid: false } } },
3820
+ });
3821
+ const order = { items: [orderItem], status: {} };
3822
+ const newOrder = pricing.order.calculate(order);
3823
+
3824
+ expect(newOrder).toHaveProperty('total', 25);
3825
+ expect(newOrder).toHaveProperty('totalPaid', 30);
3826
+ expect(newOrder.status).toMatchObject({ paid: true });
3827
+ expect(newOrder.items[0].status).toMatchObject({
3828
+ paid: { value: true },
3829
+ });
3830
+ });
3831
+
3811
3832
  test('Dont update status if not needed', () => {
3812
3833
  const orderItem = {
3813
3834
  price: 25,
@@ -0,0 +1,7 @@
1
+ module.exports = ({ utils }) =>
2
+ function getOverpaidAmount({ item }) {
3
+ const total = Number(item.total || 0);
4
+ const totalPaid = Number(item.totalPaid || 0);
5
+
6
+ return utils.math.sub(totalPaid, total);
7
+ };
@@ -9,21 +9,21 @@ module.exports = ({ actions, settings }) =>
9
9
  const total = totalParam || 0;
10
10
  const totalPaid = totalPaidParam || 0;
11
11
 
12
- if (
13
- actions.isPaid({ item: { status: localStatus } }) &&
14
- total !== 0 &&
15
- total > totalPaid
16
- ) {
12
+ const isPaid = actions.isPaid({ item: { status: localStatus } });
13
+
14
+ const paid = { value: true, date: new Date() };
15
+
16
+ if (isPaid && total !== 0 && total > totalPaid) {
17
17
  return undefined;
18
18
  }
19
19
 
20
+ if (!isPaid && totalPaid > total) return paid;
21
+
20
22
  if (!settings || !settings.order || !settings.order.autoMarkAsPaid) {
21
23
  return localStatus.paid;
22
24
  }
23
25
 
24
- if (!actions.isPaid({ item: { status: localStatus } }) && total === 0) {
25
- return { value: true, date: new Date() };
26
- }
26
+ if (!isPaid && total === 0) return paid;
27
27
 
28
28
  return localStatus.paid;
29
29
  };
package/lib/item/index.js CHANGED
@@ -82,6 +82,8 @@ const getTaxes = require('./getTaxes');
82
82
  const getAmountToPayById = require('./getAmountToPayById');
83
83
  const applyPayment = require('./applyPayment');
84
84
  const getBalanceForPaymentModifier = require('./getBalanceForPaymentModifier');
85
+ const isOverpaid = require('./isOverpaid');
86
+ const getOverpaidAmount = require('./getOverpaidAmount');
85
87
 
86
88
  const itemActions = (deps = {}) => {
87
89
  const actions = {};
@@ -177,6 +179,8 @@ const itemActions = (deps = {}) => {
177
179
  getAmountToPayById: getAmountToPayById(innerDeps),
178
180
  applyPayment: applyPayment(innerDeps),
179
181
  getBalanceForPaymentModifier: getBalanceForPaymentModifier(innerDeps),
182
+ isOverpaid: isOverpaid(innerDeps),
183
+ getOverpaidAmount: getOverpaidAmount(innerDeps),
180
184
  });
181
185
 
182
186
  Object.keys(freezedActions).forEach(actionName => {
@@ -0,0 +1,7 @@
1
+ module.exports = () =>
2
+ function isOverpaid({ item }) {
3
+ const total = Number(item.total || 0);
4
+ const totalPaid = Number(item.totalPaid || 0);
5
+
6
+ return totalPaid > total;
7
+ };
@@ -0,0 +1,8 @@
1
+ module.exports = ({ utils }) =>
2
+ function getOverPaidAmount({ order }) {
3
+ if (!order) return 0;
4
+ const total = Number(order.total || 0);
5
+ const totalPaid = Number(order.totalPaid || 0);
6
+
7
+ return utils.math.sub(totalPaid, total);
8
+ };
@@ -100,6 +100,7 @@ const removeEmptyNotes = require('./removeEmptyNotes');
100
100
  const getTaxes = require('./getTaxes');
101
101
  const getPickedStatus = require('./getPickedStatus');
102
102
  const calculateWithPayment = require('./calculateWithPayment');
103
+ const getOverpaidAmount = require('./getOverpaidAmount');
103
104
 
104
105
  const orderActions = (deps = {}) => {
105
106
  const actions = {};
@@ -211,6 +212,7 @@ const orderActions = (deps = {}) => {
211
212
  getTaxes: getTaxes(innerDeps),
212
213
  getPickedStatus: getPickedStatus(innerDeps),
213
214
  calculateWithPayment: calculateWithPayment(innerDeps),
215
+ getOverpaidAmount: getOverpaidAmount(innerDeps),
214
216
  });
215
217
 
216
218
  Object.keys(freezedActions).forEach(actionName => {
@@ -48,6 +48,10 @@ module.exports = ({ actions, itemActions, utils }) => {
48
48
  updatedParent.price || 0,
49
49
  relatedItem.price
50
50
  );
51
+ updatedParent.properties = {
52
+ ...(updatedParent.properties || {}),
53
+ priceChanged: true,
54
+ };
51
55
  }
52
56
 
53
57
  nextOrder.items = [...nextOrder.items];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkpos/pricing",
3
- "version": "1.0.139",
3
+ "version": "1.0.141",
4
4
  "description": "Pricing calculator",
5
5
  "author": "Dark POS",
6
6
  "license": "ISC",
@@ -53,5 +53,5 @@
53
53
  "supertest": "^6.2.3",
54
54
  "supervisor": "^0.12.0"
55
55
  },
56
- "gitHead": "643797505f915f1c4562c19e59a82dd98ae888ec"
56
+ "gitHead": "aa435cbf25766d8c6c161c7511958dedd656d1a3"
57
57
  }