@darkpos/pricing 1.0.33 → 1.0.35
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.
|
@@ -2287,4 +2287,194 @@ describe('Order actions', () => {
|
|
|
2287
2287
|
_actual: 10,
|
|
2288
2288
|
});
|
|
2289
2289
|
});
|
|
2290
|
+
|
|
2291
|
+
test('CU-86duna31h -> Get calculated Order, multiple items and indirect required discount modifiers', () => {
|
|
2292
|
+
const discountModifier = {
|
|
2293
|
+
_id: 1,
|
|
2294
|
+
compute: {
|
|
2295
|
+
amount: 10,
|
|
2296
|
+
type: 'percentage',
|
|
2297
|
+
action: 'subtract',
|
|
2298
|
+
},
|
|
2299
|
+
name: `10% Discount`,
|
|
2300
|
+
type: 'discount',
|
|
2301
|
+
required: true,
|
|
2302
|
+
};
|
|
2303
|
+
|
|
2304
|
+
const item1 = {
|
|
2305
|
+
_id: 1,
|
|
2306
|
+
price: 10,
|
|
2307
|
+
quantity: 1,
|
|
2308
|
+
modifiers: [
|
|
2309
|
+
{
|
|
2310
|
+
...discountModifier,
|
|
2311
|
+
_parentId: discountModifier._id,
|
|
2312
|
+
modifierId: discountModifier._id,
|
|
2313
|
+
},
|
|
2314
|
+
],
|
|
2315
|
+
};
|
|
2316
|
+
const item2 = {
|
|
2317
|
+
_id: 2,
|
|
2318
|
+
price: 20,
|
|
2319
|
+
quantity: 1,
|
|
2320
|
+
modifiers: [
|
|
2321
|
+
{
|
|
2322
|
+
...discountModifier,
|
|
2323
|
+
_parentId: discountModifier._id,
|
|
2324
|
+
modifierId: discountModifier._id,
|
|
2325
|
+
},
|
|
2326
|
+
],
|
|
2327
|
+
};
|
|
2328
|
+
|
|
2329
|
+
const order = { items: [item1, item2], modifiers: [discountModifier] };
|
|
2330
|
+
|
|
2331
|
+
const newOrder = pricingService.order.calculate(order);
|
|
2332
|
+
expect(newOrder).toHaveProperty('total', 27);
|
|
2333
|
+
expect(newOrder).toHaveProperty('subTotal', 30);
|
|
2334
|
+
expect(newOrder).toHaveProperty('subTotals', {
|
|
2335
|
+
discount: -3,
|
|
2336
|
+
});
|
|
2337
|
+
expect(newOrder.items[0]).toHaveProperty('total', 9);
|
|
2338
|
+
expect(newOrder.items[0]).toHaveProperty('subTotals', {
|
|
2339
|
+
discount: -1,
|
|
2340
|
+
_included: 0,
|
|
2341
|
+
_xincluded: -1,
|
|
2342
|
+
_direct: 0,
|
|
2343
|
+
_xdirect: -1,
|
|
2344
|
+
_simple: 10,
|
|
2345
|
+
_actual: 10,
|
|
2346
|
+
});
|
|
2347
|
+
expect(newOrder.items[1]).toHaveProperty('total', 18);
|
|
2348
|
+
expect(newOrder.items[1]).toHaveProperty('subTotals', {
|
|
2349
|
+
discount: -2,
|
|
2350
|
+
_included: 0,
|
|
2351
|
+
_xincluded: -2,
|
|
2352
|
+
_direct: 0,
|
|
2353
|
+
_xdirect: -2,
|
|
2354
|
+
_simple: 20,
|
|
2355
|
+
_actual: 20,
|
|
2356
|
+
});
|
|
2357
|
+
});
|
|
2358
|
+
|
|
2359
|
+
test('CU-86duna31h -> Get calculated Order, multiple items and indirect discount modifiers', () => {
|
|
2360
|
+
const discountModifier = {
|
|
2361
|
+
_id: 1,
|
|
2362
|
+
compute: {
|
|
2363
|
+
amount: 10,
|
|
2364
|
+
type: 'percentage',
|
|
2365
|
+
action: 'subtract',
|
|
2366
|
+
},
|
|
2367
|
+
name: `10% Discount`,
|
|
2368
|
+
type: 'discount',
|
|
2369
|
+
required: true,
|
|
2370
|
+
};
|
|
2371
|
+
|
|
2372
|
+
const item1 = {
|
|
2373
|
+
_id: 1,
|
|
2374
|
+
price: 10,
|
|
2375
|
+
quantity: 1,
|
|
2376
|
+
modifiers: [],
|
|
2377
|
+
};
|
|
2378
|
+
const item2 = {
|
|
2379
|
+
_id: 2,
|
|
2380
|
+
price: 20,
|
|
2381
|
+
quantity: 1,
|
|
2382
|
+
modifiers: [],
|
|
2383
|
+
};
|
|
2384
|
+
|
|
2385
|
+
const order = { items: [item1, item2], modifiers: [discountModifier] };
|
|
2386
|
+
|
|
2387
|
+
const newOrder = pricingService.order.calculate(order);
|
|
2388
|
+
expect(newOrder).toHaveProperty('total', 27);
|
|
2389
|
+
expect(newOrder).toHaveProperty('subTotal', 30);
|
|
2390
|
+
expect(newOrder).toHaveProperty('subTotals', {
|
|
2391
|
+
discount: -3,
|
|
2392
|
+
});
|
|
2393
|
+
expect(newOrder.items[0]).toHaveProperty('total', 9);
|
|
2394
|
+
expect(newOrder.items[0]).toHaveProperty('subTotals', {
|
|
2395
|
+
discount: -1,
|
|
2396
|
+
_included: 0,
|
|
2397
|
+
_xincluded: -1,
|
|
2398
|
+
_direct: 0,
|
|
2399
|
+
_xdirect: -1,
|
|
2400
|
+
_simple: 10,
|
|
2401
|
+
_actual: 10,
|
|
2402
|
+
});
|
|
2403
|
+
expect(newOrder.items[1]).toHaveProperty('total', 18);
|
|
2404
|
+
expect(newOrder.items[1]).toHaveProperty('subTotals', {
|
|
2405
|
+
discount: -2,
|
|
2406
|
+
_included: 0,
|
|
2407
|
+
_xincluded: -2,
|
|
2408
|
+
_direct: 0,
|
|
2409
|
+
_xdirect: -2,
|
|
2410
|
+
_simple: 20,
|
|
2411
|
+
_actual: 20,
|
|
2412
|
+
});
|
|
2413
|
+
});
|
|
2414
|
+
|
|
2415
|
+
test('CU-86duna31h -> Get calculated Order, multiple items and indirect required discount modifiers', () => {
|
|
2416
|
+
const discountModifier = {
|
|
2417
|
+
_id: 1,
|
|
2418
|
+
compute: {
|
|
2419
|
+
amount: 10,
|
|
2420
|
+
type: 'percentage',
|
|
2421
|
+
action: 'subtract',
|
|
2422
|
+
},
|
|
2423
|
+
name: `10% Discount`,
|
|
2424
|
+
type: 'discount',
|
|
2425
|
+
};
|
|
2426
|
+
|
|
2427
|
+
const item1 = {
|
|
2428
|
+
_id: 1,
|
|
2429
|
+
price: 10,
|
|
2430
|
+
quantity: 1,
|
|
2431
|
+
modifiers: [
|
|
2432
|
+
{
|
|
2433
|
+
...discountModifier,
|
|
2434
|
+
_parentId: discountModifier._id,
|
|
2435
|
+
modifierId: discountModifier._id,
|
|
2436
|
+
},
|
|
2437
|
+
],
|
|
2438
|
+
};
|
|
2439
|
+
const item2 = {
|
|
2440
|
+
_id: 2,
|
|
2441
|
+
price: 20,
|
|
2442
|
+
quantity: 1,
|
|
2443
|
+
modifiers: [
|
|
2444
|
+
{
|
|
2445
|
+
...discountModifier,
|
|
2446
|
+
_parentId: discountModifier._id,
|
|
2447
|
+
modifierId: discountModifier._id,
|
|
2448
|
+
},
|
|
2449
|
+
],
|
|
2450
|
+
};
|
|
2451
|
+
const order = { items: [item1, item2], modifiers: [discountModifier] };
|
|
2452
|
+
|
|
2453
|
+
const newOrder = pricingService.order.calculate(order);
|
|
2454
|
+
expect(newOrder).toHaveProperty('total', 27);
|
|
2455
|
+
expect(newOrder).toHaveProperty('subTotal', 30);
|
|
2456
|
+
expect(newOrder).toHaveProperty('subTotals', {
|
|
2457
|
+
discount: -3,
|
|
2458
|
+
});
|
|
2459
|
+
expect(newOrder.items[0]).toHaveProperty('total', 9);
|
|
2460
|
+
expect(newOrder.items[0]).toHaveProperty('subTotals', {
|
|
2461
|
+
discount: -1,
|
|
2462
|
+
_included: 0,
|
|
2463
|
+
_xincluded: -1,
|
|
2464
|
+
_direct: 0,
|
|
2465
|
+
_xdirect: -1,
|
|
2466
|
+
_simple: 10,
|
|
2467
|
+
_actual: 10,
|
|
2468
|
+
});
|
|
2469
|
+
expect(newOrder.items[1]).toHaveProperty('total', 18);
|
|
2470
|
+
expect(newOrder.items[1]).toHaveProperty('subTotals', {
|
|
2471
|
+
discount: -2,
|
|
2472
|
+
_included: 0,
|
|
2473
|
+
_xincluded: -2,
|
|
2474
|
+
_direct: 0,
|
|
2475
|
+
_xdirect: -2,
|
|
2476
|
+
_simple: 20,
|
|
2477
|
+
_actual: 20,
|
|
2478
|
+
});
|
|
2479
|
+
});
|
|
2290
2480
|
});
|
|
@@ -5,12 +5,14 @@ module.exports = ({ modifierActions, _, actions }) => {
|
|
|
5
5
|
const isValid = (itemModifiers, modifier) => {
|
|
6
6
|
if (!modifierActions.findById(itemModifiers, modifier._id)) return false;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
)
|
|
13
|
-
|
|
8
|
+
// 18-SEP-24 - Commenting out due to bug: https://app.clickup.com/t/86duna31h.
|
|
9
|
+
// This logic was preventing required Order Discounts to be removed from the items.
|
|
10
|
+
// if (
|
|
11
|
+
// modifierActions.isRequired(modifier) &&
|
|
12
|
+
// !modifierActions.isGroupOfValues(modifier) &&
|
|
13
|
+
// !modifierActions.isRequiredAndOverride(modifier)
|
|
14
|
+
// )
|
|
15
|
+
// return false;
|
|
14
16
|
|
|
15
17
|
if (
|
|
16
18
|
!modifierActions.isGroupOfItems(modifier) &&
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.35",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@darkpos/utils": "1.0.
|
|
22
|
+
"@darkpos/utils": "1.0.10",
|
|
23
23
|
"lodash": "^4.17.21",
|
|
24
24
|
"moment-timezone": "^0.5.34"
|
|
25
25
|
},
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"supertest": "^6.2.3",
|
|
37
37
|
"supervisor": "^0.12.0"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "00a27ca75fa0c5b5a2e0dba0f9446487f7c1ac63"
|
|
40
40
|
}
|