@darkpos/pricing 1.0.129 → 1.0.131
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.
|
@@ -374,4 +374,172 @@ describe('addItemModifier Function', () => {
|
|
|
374
374
|
|
|
375
375
|
expect(result.items[0].price).toBe(129);
|
|
376
376
|
});
|
|
377
|
+
|
|
378
|
+
test('Calculate item with Override Modifier and unitAsAmountMultiplier=true', () => {
|
|
379
|
+
const item = {
|
|
380
|
+
location: {},
|
|
381
|
+
status: {
|
|
382
|
+
picked: {
|
|
383
|
+
value: false,
|
|
384
|
+
date: '',
|
|
385
|
+
},
|
|
386
|
+
paid: {
|
|
387
|
+
value: false,
|
|
388
|
+
date: '',
|
|
389
|
+
},
|
|
390
|
+
tracker: [],
|
|
391
|
+
},
|
|
392
|
+
name: 'Short Pants2',
|
|
393
|
+
description: '',
|
|
394
|
+
pieces: 1,
|
|
395
|
+
modifiersTotalAmount: 0,
|
|
396
|
+
total: 510,
|
|
397
|
+
totalPaid: 0,
|
|
398
|
+
price: 10,
|
|
399
|
+
quantity: 1,
|
|
400
|
+
path: ',68eeba20cbfa2b080d75f7ea,68eeba2d9366a6367d7baaea,',
|
|
401
|
+
notes: [],
|
|
402
|
+
serial: null,
|
|
403
|
+
sku: '',
|
|
404
|
+
modifiers: [
|
|
405
|
+
{
|
|
406
|
+
_id: '690a3d23de696e15c594f7f2',
|
|
407
|
+
attributes: ['department'],
|
|
408
|
+
modifierId: '68efd827aeec0b1c557f79d4',
|
|
409
|
+
_parentId: null,
|
|
410
|
+
locked: false,
|
|
411
|
+
name: 'Dry Cleaning',
|
|
412
|
+
sku: '',
|
|
413
|
+
description: '',
|
|
414
|
+
group: '',
|
|
415
|
+
type: '',
|
|
416
|
+
tags: ['default'],
|
|
417
|
+
order: 0,
|
|
418
|
+
included: false,
|
|
419
|
+
direct: true,
|
|
420
|
+
hidden: false,
|
|
421
|
+
print: true,
|
|
422
|
+
required: false,
|
|
423
|
+
recommended: false,
|
|
424
|
+
default: false,
|
|
425
|
+
code: 'DC',
|
|
426
|
+
properties: {
|
|
427
|
+
department: {
|
|
428
|
+
tagSize: 'small',
|
|
429
|
+
splitUnit: 'quantity',
|
|
430
|
+
maxItems: '',
|
|
431
|
+
autoSplit: false,
|
|
432
|
+
},
|
|
433
|
+
sort: null,
|
|
434
|
+
},
|
|
435
|
+
_computed: {
|
|
436
|
+
amount: 0,
|
|
437
|
+
description: 'Dry Cleaning',
|
|
438
|
+
},
|
|
439
|
+
conditions: {
|
|
440
|
+
valid: true,
|
|
441
|
+
},
|
|
442
|
+
compute: null,
|
|
443
|
+
_createdAt: '2025-10-15T17:21:43.526Z',
|
|
444
|
+
_updatedAt: '2025-10-15T17:26:13.671Z',
|
|
445
|
+
__typename: 'Modifier',
|
|
446
|
+
addModifiers: [],
|
|
447
|
+
delModifiers: [],
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
_id: '690a3d2ede696e15c594f7f3',
|
|
451
|
+
attributes: ['override'],
|
|
452
|
+
modifierId: '690a195d3117c6cb92a692c0',
|
|
453
|
+
_parentId: null,
|
|
454
|
+
locked: false,
|
|
455
|
+
name: 'Pleats',
|
|
456
|
+
sku: '',
|
|
457
|
+
description: '',
|
|
458
|
+
group: '',
|
|
459
|
+
type: '',
|
|
460
|
+
tags: ['default'],
|
|
461
|
+
order: 0,
|
|
462
|
+
included: false,
|
|
463
|
+
direct: true,
|
|
464
|
+
hidden: false,
|
|
465
|
+
print: true,
|
|
466
|
+
required: false,
|
|
467
|
+
recommended: false,
|
|
468
|
+
default: false,
|
|
469
|
+
code: '',
|
|
470
|
+
properties: {
|
|
471
|
+
subscription: {},
|
|
472
|
+
override: {
|
|
473
|
+
field: 'amount',
|
|
474
|
+
type: 'manual',
|
|
475
|
+
options: null,
|
|
476
|
+
fixedValue: 20,
|
|
477
|
+
service: null,
|
|
478
|
+
unitAsAmountMultiplier: true,
|
|
479
|
+
amountMultiplier: 25,
|
|
480
|
+
multiplier: false,
|
|
481
|
+
},
|
|
482
|
+
group: {
|
|
483
|
+
items: [],
|
|
484
|
+
modifiers: [],
|
|
485
|
+
},
|
|
486
|
+
department: {},
|
|
487
|
+
sort: null,
|
|
488
|
+
},
|
|
489
|
+
_computed: {
|
|
490
|
+
amount: 500,
|
|
491
|
+
description: 'Pleats ($500.00)',
|
|
492
|
+
},
|
|
493
|
+
conditions: {
|
|
494
|
+
valid: true,
|
|
495
|
+
},
|
|
496
|
+
compute: {
|
|
497
|
+
type: 'fixed',
|
|
498
|
+
amount: 20,
|
|
499
|
+
action: 'add',
|
|
500
|
+
},
|
|
501
|
+
_createdAt: '2025-11-04T15:18:53.231Z',
|
|
502
|
+
_updatedAt: '2025-11-04T16:54:33.773Z',
|
|
503
|
+
__typename: 'Modifier',
|
|
504
|
+
addModifiers: [],
|
|
505
|
+
delModifiers: [],
|
|
506
|
+
},
|
|
507
|
+
],
|
|
508
|
+
_id: '690a3d23de696e15c594f7f1',
|
|
509
|
+
_updatedAt: '2025-11-04T17:05:05.845Z',
|
|
510
|
+
_createdAt: '2025-10-14T21:02:10.991Z',
|
|
511
|
+
weight: 0,
|
|
512
|
+
properties: {},
|
|
513
|
+
hasInventory: true,
|
|
514
|
+
inventoryType: 'push',
|
|
515
|
+
serialRequired: false,
|
|
516
|
+
tags: [],
|
|
517
|
+
category: null,
|
|
518
|
+
__typename: 'OrderItem',
|
|
519
|
+
priceLevels: [
|
|
520
|
+
{
|
|
521
|
+
value: 10,
|
|
522
|
+
tags: ['default'],
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
value: 8,
|
|
526
|
+
tags: ['default', 'vip'],
|
|
527
|
+
},
|
|
528
|
+
],
|
|
529
|
+
costLevels: [],
|
|
530
|
+
itemId: '68eeba52cbfa2b080d75fa02',
|
|
531
|
+
menuRuleId: '68eeba559366a6367d7bab08',
|
|
532
|
+
subTotals: {
|
|
533
|
+
_included: 0,
|
|
534
|
+
_xincluded: 500,
|
|
535
|
+
_direct: 500,
|
|
536
|
+
_xdirect: 0,
|
|
537
|
+
_simple: 10,
|
|
538
|
+
_actual: 10,
|
|
539
|
+
'': 500,
|
|
540
|
+
},
|
|
541
|
+
};
|
|
542
|
+
const calculatedItem = pricingService.item.calculate(item);
|
|
543
|
+
expect(calculatedItem.total).toBe(510);
|
|
544
|
+
});
|
|
377
545
|
});
|
|
@@ -70,6 +70,14 @@ module.exports = ({ _, constants, utils, actions }) => {
|
|
|
70
70
|
_computed.amount = math.mul(_computed.amount, options.quantity);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
if (
|
|
74
|
+
actions.isAmountOverride(_modifier) &&
|
|
75
|
+
actions.isAmountMultiplier(_modifier)
|
|
76
|
+
) {
|
|
77
|
+
const amountMultiplier = actions.getAmountMultiplier(_modifier);
|
|
78
|
+
_computed.amount = math.mul(_computed.amount, amountMultiplier);
|
|
79
|
+
}
|
|
80
|
+
|
|
73
81
|
if (actions.isTotalOverride(_modifier)) {
|
|
74
82
|
_computed.amount = math.sub(compute.amount, options.maxDiscountAmount);
|
|
75
83
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module.exports = ({ actions }) =>
|
|
2
|
+
function getAmountMultiplier(modifier) {
|
|
3
|
+
if (!actions.isOverride(modifier)) return 1;
|
|
4
|
+
if (!actions.isAmountMultiplier(modifier)) return 1;
|
|
5
|
+
|
|
6
|
+
return (
|
|
7
|
+
(modifier.properties && modifier.properties.override.amountMultiplier) ||
|
|
8
|
+
1
|
|
9
|
+
);
|
|
10
|
+
};
|
package/lib/modifier/index.js
CHANGED
|
@@ -179,6 +179,8 @@ const isEmptyOverride = require('./isEmptyOverride');
|
|
|
179
179
|
const getMaxUsesPerCustomer = require('./getMaxUsesPerCustomer');
|
|
180
180
|
const getPromoCustomerIds = require('./getPromoCustomerIds');
|
|
181
181
|
const getCountPerCustomer = require('./getCountPerCustomer');
|
|
182
|
+
const getAmountMultiplier = require('./getAmountMultiplier');
|
|
183
|
+
const isAmountMultiplier = require('./isAmountMultiplier');
|
|
182
184
|
|
|
183
185
|
const modifierActions = (deps = {}) => {
|
|
184
186
|
const actions = {};
|
|
@@ -370,6 +372,8 @@ const modifierActions = (deps = {}) => {
|
|
|
370
372
|
getMaxUsesPerCustomer: getMaxUsesPerCustomer(innerDeps),
|
|
371
373
|
getPromoCustomerIds: getPromoCustomerIds(innerDeps),
|
|
372
374
|
getCountPerCustomer: getCountPerCustomer(innerDeps),
|
|
375
|
+
getAmountMultiplier: getAmountMultiplier(innerDeps),
|
|
376
|
+
isAmountMultiplier: isAmountMultiplier(innerDeps),
|
|
373
377
|
});
|
|
374
378
|
|
|
375
379
|
Object.keys(freezedActions).forEach(actionName => {
|
package/lib/order/create.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
module.exports = ({ utils, constants = {} }) => {
|
|
2
|
-
const { helpers } = utils;
|
|
3
|
-
|
|
4
2
|
const defaultOrderStatus = {
|
|
5
3
|
order: constants.Status.Order.OPEN,
|
|
6
4
|
kitchen: constants.Status.Kitchen.OPEN,
|
|
@@ -20,9 +18,6 @@ module.exports = ({ utils, constants = {} }) => {
|
|
|
20
18
|
__typename: 'OrderStart',
|
|
21
19
|
};
|
|
22
20
|
const defaultOrder = {
|
|
23
|
-
get _id() {
|
|
24
|
-
return helpers.getObjectID();
|
|
25
|
-
},
|
|
26
21
|
parentId: null,
|
|
27
22
|
isParent: false,
|
|
28
23
|
subTotal: 0,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.131",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"supertest": "^6.2.3",
|
|
53
53
|
"supervisor": "^0.12.0"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "b4f267cbf11b2857a4fc01053cc315036e63392f"
|
|
56
56
|
}
|