@darkpos/pricing 1.0.69 → 1.0.71

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.
@@ -356,12 +356,11 @@ describe('getModifierTags Function', () => {
356
356
 
357
357
  const result = pricingServiceGroupModifiers.item.getModifierTags({ item });
358
358
 
359
- expect(result).toHaveLength(3);
360
- expect(result[0].label.replace(/\s/g, '')).toEqual('1White');
361
- expect(result[1].label.replace(/\s/g, '')).toEqual(
359
+ expect(result).toHaveLength(2);
360
+ expect(result[0].label.replace(/\s/g, '')).toEqual(
362
361
  '1CRC5.10discount(-CRC5.10)'
363
362
  );
364
- expect(result[2].label.replace(/\s/g, '')).toEqual(
363
+ expect(result[1].label.replace(/\s/g, '')).toEqual(
365
364
  '1CRC37.50discount(-CRC37.50)'
366
365
  );
367
366
  });
@@ -3849,6 +3849,8 @@ test('getInvalidRequiredModifiers having related items', () => {
3849
3849
  delModifiers: [],
3850
3850
  },
3851
3851
  ],
3852
+ _id: '67dc63610c106ab7d481d7dd',
3853
+ itemId: '62cdbfd01ee1b4001932821a',
3852
3854
  };
3853
3855
  const otherItems = [
3854
3856
  {
@@ -3860,13 +3862,14 @@ test('getInvalidRequiredModifiers having related items', () => {
3860
3862
  parentId: '67dc63610c106ab7d481d7dd',
3861
3863
  includeParent: true,
3862
3864
  basePrice: 3,
3865
+ relatedItemId: '62cdbfd01ee1b4001932820e',
3863
3866
  },
3864
3867
  },
3865
3868
  ];
3866
3869
 
3867
3870
  const response = pricingService.item.getInvalidRequiredModifiers({
3868
3871
  item,
3869
- otherItems,
3872
+ relatedItems: otherItems,
3870
3873
  });
3871
3874
 
3872
3875
  expect(response.length).toBe(1);
@@ -3234,4 +3234,469 @@ describe('Order actions', () => {
3234
3234
  };
3235
3235
  expect(pricingService.order.getLastLocation({ status })).toEqual(null);
3236
3236
  });
3237
+
3238
+ test('should autoSplit. Department has maxPieces6', () => {
3239
+ const deparmentModifier = {
3240
+ modifierId: '67e5b5faa8b435351f4c60b3',
3241
+ _parentId: null,
3242
+ locked: false,
3243
+ name: 'DepMax6Pieces',
3244
+ sku: '',
3245
+ description: '',
3246
+ group: '',
3247
+ type: '',
3248
+ attributes: ['department'],
3249
+ cost: 0,
3250
+ tags: ['default'],
3251
+ order: 0,
3252
+ code: 'Y',
3253
+ included: false,
3254
+ direct: true,
3255
+ hidden: false,
3256
+ print: true,
3257
+ required: false,
3258
+ recommended: false,
3259
+ default: false,
3260
+ addModifiers: [],
3261
+ delModifiers: [],
3262
+ conditions: {
3263
+ _id: '67e5b6e619f55c6088fc2d00',
3264
+ rules: [],
3265
+ valid: true,
3266
+ },
3267
+ compute: null,
3268
+ properties: {
3269
+ department: {
3270
+ splitUnit: 'pieces',
3271
+ maxItems: '6',
3272
+ autoSplit: true,
3273
+ },
3274
+ sort: null,
3275
+ },
3276
+ _computed: {
3277
+ amount: 0,
3278
+ description: 'DepMax6Pieces',
3279
+ },
3280
+ _hidden: false,
3281
+ _isDeleted: false,
3282
+ _id: '1',
3283
+ };
3284
+
3285
+ const item1 = {
3286
+ itemId: '62cdbfd01ee1b400193282b0',
3287
+ name: 'Belt',
3288
+ price: 0,
3289
+ modifiersTotalAmount: 0,
3290
+ quantity: 1,
3291
+ pieces: 1,
3292
+ weight: null,
3293
+ modifiers: [
3294
+ {
3295
+ ...deparmentModifier,
3296
+ _id: 1,
3297
+ },
3298
+ ],
3299
+ total: 0,
3300
+ totalPaid: 0,
3301
+ notes: [],
3302
+ subTotals: {},
3303
+ properties: {
3304
+ basePrice: 0,
3305
+ },
3306
+ };
3307
+
3308
+ const item2 = {
3309
+ itemId: '62cdbfd01ee1b400193282f4',
3310
+ name: 'Blanket King2',
3311
+ price: 12,
3312
+ modifiersTotalAmount: 0,
3313
+ quantity: 1,
3314
+ pieces: 1,
3315
+ weight: null,
3316
+ modifiers: [
3317
+ {
3318
+ ...deparmentModifier,
3319
+ _id: 6,
3320
+ },
3321
+ ],
3322
+ total: 12,
3323
+ totalPaid: 0,
3324
+ subTotals: {},
3325
+ properties: {
3326
+ basePrice: 12,
3327
+ },
3328
+ };
3329
+
3330
+ const order = {
3331
+ user: '62cdbfcfaaf93c00193d2e7b',
3332
+ customer: '66a3d7d366107c7369873980',
3333
+ parentId: null,
3334
+ isParent: false,
3335
+ items: [
3336
+ {
3337
+ ...item1,
3338
+ _id: 1,
3339
+ },
3340
+ {
3341
+ ...item1,
3342
+ _id: 2,
3343
+ },
3344
+ {
3345
+ ...item1,
3346
+ _id: 3,
3347
+ },
3348
+ {
3349
+ ...item1,
3350
+ _id: 4,
3351
+ },
3352
+ {
3353
+ ...item2,
3354
+ _id: 5,
3355
+ },
3356
+ {
3357
+ ...item2,
3358
+ _id: 6,
3359
+ },
3360
+ {
3361
+ ...item2,
3362
+ _id: 7,
3363
+ },
3364
+ {
3365
+ ...item2,
3366
+ _id: 8,
3367
+ },
3368
+ ],
3369
+ subTotal: 48,
3370
+ tax: 0,
3371
+ discount: 0,
3372
+ fee: 0,
3373
+ total: 48,
3374
+ totalPaid: 0,
3375
+ modifiers: [],
3376
+ displayId: 1554,
3377
+ description: '',
3378
+ type: '',
3379
+ status: {
3380
+ order: 'open',
3381
+ kitchen: 'open',
3382
+ delivery: 'none',
3383
+ detailed: true,
3384
+ },
3385
+ attributes: [],
3386
+ properties: {
3387
+ split: 'auto',
3388
+ },
3389
+ _id: '67e5b66bed32e55e8e6e6603',
3390
+ subTotals: {},
3391
+ orders: [],
3392
+ };
3393
+
3394
+ const splittedOrders = pricingService.order.autoSplit({
3395
+ parentOrder: order,
3396
+ });
3397
+
3398
+ expect(splittedOrders.length).toEqual(2);
3399
+ expect(splittedOrders[0].items.length).toEqual(6);
3400
+ expect(splittedOrders[0].items[0]).toMatchObject({ ...item1 });
3401
+ expect(splittedOrders[0].items[1]).toMatchObject({ ...item1 });
3402
+ expect(splittedOrders[0].items[2]).toMatchObject({ ...item1 });
3403
+ expect(splittedOrders[0].items[3]).toMatchObject({ ...item1 });
3404
+ expect(splittedOrders[0].items[4]).toMatchObject({ ...item2 });
3405
+ expect(splittedOrders[0].items[5]).toMatchObject({ ...item2 });
3406
+
3407
+ expect(splittedOrders[1].items.length).toEqual(2);
3408
+ expect(splittedOrders[1].items[0]).toMatchObject({ ...item2 });
3409
+ expect(splittedOrders[1].items[1]).toMatchObject({ ...item2 });
3410
+ });
3411
+
3412
+ test('should autoSplit. Department has maxQty6', () => {
3413
+ const deparmentModifier = {
3414
+ modifierId: '67e5b5faa8b435351f4c60b3',
3415
+ _parentId: null,
3416
+ locked: false,
3417
+ name: 'DepMax6Qty',
3418
+ sku: '',
3419
+ description: '',
3420
+ group: '',
3421
+ type: '',
3422
+ attributes: ['department'],
3423
+ cost: 0,
3424
+ tags: ['default'],
3425
+ order: 0,
3426
+ code: 'Y',
3427
+ included: false,
3428
+ direct: true,
3429
+ hidden: false,
3430
+ print: true,
3431
+ required: false,
3432
+ recommended: false,
3433
+ default: false,
3434
+ addModifiers: [],
3435
+ delModifiers: [],
3436
+ conditions: {
3437
+ _id: '67e5b6e619f55c6088fc2d00',
3438
+ rules: [],
3439
+ valid: true,
3440
+ },
3441
+ compute: null,
3442
+ properties: {
3443
+ department: {
3444
+ splitUnit: 'quantity',
3445
+ maxItems: '6',
3446
+ autoSplit: true,
3447
+ },
3448
+ sort: null,
3449
+ },
3450
+ _computed: {
3451
+ amount: 0,
3452
+ description: 'DepMax6Qty',
3453
+ },
3454
+ _hidden: false,
3455
+ _isDeleted: false,
3456
+ _id: '1',
3457
+ };
3458
+
3459
+ const item1 = {
3460
+ itemId: '62cdbfd01ee1b400193282b0',
3461
+ name: 'Belt',
3462
+ price: 0,
3463
+ modifiersTotalAmount: 0,
3464
+ quantity: 1,
3465
+ pieces: 1,
3466
+ weight: null,
3467
+ modifiers: [
3468
+ {
3469
+ ...deparmentModifier,
3470
+ _id: 1,
3471
+ },
3472
+ ],
3473
+ total: 0,
3474
+ totalPaid: 0,
3475
+ notes: [],
3476
+ subTotals: {},
3477
+ properties: {
3478
+ basePrice: 0,
3479
+ },
3480
+ };
3481
+
3482
+ const item2 = {
3483
+ itemId: '62cdbfd01ee1b400193282f4',
3484
+ name: 'Blanket King2',
3485
+ price: 12,
3486
+ modifiersTotalAmount: 0,
3487
+ quantity: 1,
3488
+ pieces: 1,
3489
+ weight: null,
3490
+ modifiers: [
3491
+ {
3492
+ ...deparmentModifier,
3493
+ _id: 6,
3494
+ },
3495
+ ],
3496
+ total: 12,
3497
+ totalPaid: 0,
3498
+ subTotals: {},
3499
+ properties: {
3500
+ basePrice: 12,
3501
+ },
3502
+ };
3503
+
3504
+ const order = {
3505
+ user: '62cdbfcfaaf93c00193d2e7b',
3506
+ customer: '66a3d7d366107c7369873980',
3507
+ parentId: null,
3508
+ isParent: false,
3509
+ items: [
3510
+ {
3511
+ ...item1,
3512
+ _id: 1,
3513
+ },
3514
+ {
3515
+ ...item1,
3516
+ _id: 2,
3517
+ },
3518
+ {
3519
+ ...item1,
3520
+ _id: 3,
3521
+ },
3522
+ {
3523
+ ...item1,
3524
+ _id: 4,
3525
+ },
3526
+ {
3527
+ ...item2,
3528
+ _id: 5,
3529
+ },
3530
+ {
3531
+ ...item2,
3532
+ _id: 6,
3533
+ },
3534
+ {
3535
+ ...item2,
3536
+ _id: 7,
3537
+ },
3538
+ {
3539
+ ...item2,
3540
+ _id: 8,
3541
+ },
3542
+ ],
3543
+ subTotal: 48,
3544
+ tax: 0,
3545
+ discount: 0,
3546
+ fee: 0,
3547
+ total: 48,
3548
+ totalPaid: 0,
3549
+ modifiers: [],
3550
+ displayId: 1554,
3551
+ description: '',
3552
+ type: '',
3553
+ status: {
3554
+ order: 'open',
3555
+ kitchen: 'open',
3556
+ delivery: 'none',
3557
+ detailed: true,
3558
+ },
3559
+ attributes: [],
3560
+ properties: {
3561
+ split: 'auto',
3562
+ },
3563
+ _id: '67e5b66bed32e55e8e6e6603',
3564
+ subTotals: {},
3565
+ orders: [],
3566
+ };
3567
+
3568
+ const splittedOrders = pricingService.order.autoSplit({
3569
+ parentOrder: order,
3570
+ });
3571
+
3572
+ expect(splittedOrders.length).toEqual(2);
3573
+ expect(splittedOrders[0].items.length).toEqual(6);
3574
+ expect(splittedOrders[0].items[0]).toMatchObject({ ...item1 });
3575
+ expect(splittedOrders[0].items[1]).toMatchObject({ ...item1 });
3576
+ expect(splittedOrders[0].items[2]).toMatchObject({ ...item1 });
3577
+ expect(splittedOrders[0].items[3]).toMatchObject({ ...item1 });
3578
+ expect(splittedOrders[0].items[4]).toMatchObject({ ...item2 });
3579
+ expect(splittedOrders[0].items[5]).toMatchObject({ ...item2 });
3580
+
3581
+ expect(splittedOrders[1].items.length).toEqual(2);
3582
+ expect(splittedOrders[1].items[0]).toMatchObject({ ...item2 });
3583
+ expect(splittedOrders[1].items[1]).toMatchObject({ ...item2 });
3584
+ });
3585
+
3586
+ test('should autoSplit. Department has maxQty6. Just one item of qty=12', () => {
3587
+ const deparmentModifier = {
3588
+ modifierId: '67e5b5faa8b435351f4c60b3',
3589
+ _parentId: null,
3590
+ locked: false,
3591
+ name: 'DepMax6Qty',
3592
+ sku: '',
3593
+ description: '',
3594
+ group: '',
3595
+ type: '',
3596
+ attributes: ['department'],
3597
+ cost: 0,
3598
+ tags: ['default'],
3599
+ order: 0,
3600
+ code: 'Y',
3601
+ included: false,
3602
+ direct: true,
3603
+ hidden: false,
3604
+ print: true,
3605
+ required: false,
3606
+ recommended: false,
3607
+ default: false,
3608
+ addModifiers: [],
3609
+ delModifiers: [],
3610
+ conditions: {
3611
+ _id: '67e5b6e619f55c6088fc2d00',
3612
+ rules: [],
3613
+ valid: true,
3614
+ },
3615
+ compute: null,
3616
+ properties: {
3617
+ department: {
3618
+ splitUnit: 'quantity',
3619
+ maxItems: '6',
3620
+ autoSplit: true,
3621
+ },
3622
+ sort: null,
3623
+ },
3624
+ _computed: {
3625
+ amount: 0,
3626
+ description: 'DepMax6Qty',
3627
+ },
3628
+ _hidden: false,
3629
+ _isDeleted: false,
3630
+ _id: '1',
3631
+ };
3632
+
3633
+ const item1 = {
3634
+ itemId: '62cdbfd01ee1b400193282b0',
3635
+ name: 'Belt',
3636
+ price: 0,
3637
+ modifiersTotalAmount: 0,
3638
+ quantity: 12,
3639
+ pieces: 1,
3640
+ weight: null,
3641
+ modifiers: [
3642
+ {
3643
+ ...deparmentModifier,
3644
+ _id: 1,
3645
+ },
3646
+ ],
3647
+ total: 0,
3648
+ totalPaid: 0,
3649
+ notes: [],
3650
+ subTotals: {},
3651
+ properties: {
3652
+ basePrice: 0,
3653
+ },
3654
+ _id: 1,
3655
+ };
3656
+
3657
+ const order = {
3658
+ user: '62cdbfcfaaf93c00193d2e7b',
3659
+ customer: '66a3d7d366107c7369873980',
3660
+ parentId: null,
3661
+ isParent: false,
3662
+ items: [item1],
3663
+ subTotal: 48,
3664
+ tax: 0,
3665
+ discount: 0,
3666
+ fee: 0,
3667
+ total: 48,
3668
+ totalPaid: 0,
3669
+ modifiers: [],
3670
+ displayId: 1554,
3671
+ description: '',
3672
+ type: '',
3673
+ status: {
3674
+ order: 'open',
3675
+ kitchen: 'open',
3676
+ delivery: 'none',
3677
+ detailed: true,
3678
+ },
3679
+ attributes: [],
3680
+ properties: {
3681
+ split: 'auto',
3682
+ },
3683
+ _id: '67e5b66bed32e55e8e6e6603',
3684
+ subTotals: {},
3685
+ orders: [],
3686
+ };
3687
+
3688
+ const splittedOrders = pricingService.order.autoSplit({
3689
+ parentOrder: order,
3690
+ });
3691
+
3692
+ expect(splittedOrders.length).toEqual(2);
3693
+
3694
+ expect(splittedOrders[0].items.length).toEqual(1);
3695
+ expect(splittedOrders[0].items[0].name).toEqual(item1.name);
3696
+ expect(splittedOrders[0].items[0].quantity).toEqual(6);
3697
+
3698
+ expect(splittedOrders[1].items.length).toEqual(1);
3699
+ expect(splittedOrders[1].items[0].name).toEqual(item1.name);
3700
+ expect(splittedOrders[1].items[0].quantity).toEqual(6);
3701
+ });
3237
3702
  });
@@ -1,5 +1,5 @@
1
1
  module.exports = ({ modifierActions, actions }) =>
2
- function getInvalidRequiredModifiers({ item, otherItems }) {
2
+ function getInvalidRequiredModifiers({ item, relatedItems }) {
3
3
  if (!item || !Array.isArray(item.modifiers)) return [];
4
4
  const invalidModifiers = [];
5
5
 
@@ -7,23 +7,7 @@ module.exports = ({ modifierActions, actions }) =>
7
7
  if (
8
8
  modifierActions.isRequired(modifier) &&
9
9
  modifierActions.isGroupOfModifiers(modifier) &&
10
- !item.modifiers
11
- .filter(mod => mod._id !== modifier._id)
12
- .some(itemModifier =>
13
- modifierActions.isRelatedModifier({
14
- _id: itemModifier.modifierId || itemModifier._id,
15
- modifier,
16
- })
17
- ) &&
18
- Array.isArray(otherItems) &&
19
- modifierActions.isGroupOfItems(modifier) &&
20
- !modifier.properties.group.items.some(relatedItem =>
21
- otherItems.some(
22
- otherItem =>
23
- actions.isRelatedItem(otherItem) &&
24
- otherItem.itemId === relatedItem._id
25
- )
26
- )
10
+ !actions.hasModifier({ item, modifier, relatedItems })
27
11
  ) {
28
12
  invalidModifiers.push(modifier);
29
13
  }
@@ -6,7 +6,11 @@ module.exports = ({ modifierActions, settings }) =>
6
6
  if (!item || !Array.isArray(item.modifiers)) return [];
7
7
 
8
8
  let modifierTags = item.modifiers
9
- .filter(each => modifierActions.isValid(each))
9
+ .filter(
10
+ each =>
11
+ modifierActions.isValid(each) &&
12
+ (!modifierActions.isGroup(each) || modifierActions.isDepartment(each))
13
+ )
10
14
  .map(modifier => {
11
15
  const { name, _id } = modifier;
12
16
 
@@ -73,6 +73,8 @@ module.exports = ({ utils, _, actions, itemActions, modifierActions }) => {
73
73
  let newItemid = helpers.getObjectID();
74
74
 
75
75
  newItems.forEach(newItem => {
76
+ newItemid = helpers.getObjectID();
77
+
76
78
  for (let j = 0; j < newItem.quantity; j += 1) {
77
79
  const item = {
78
80
  ...newItem,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkpos/pricing",
3
- "version": "1.0.69",
3
+ "version": "1.0.71",
4
4
  "description": "Pricing calculator",
5
5
  "author": "Dark POS",
6
6
  "license": "ISC",
@@ -49,5 +49,5 @@
49
49
  "supertest": "^6.2.3",
50
50
  "supervisor": "^0.12.0"
51
51
  },
52
- "gitHead": "eb168a1c07915c479303713d45c4d40ebf692689"
52
+ "gitHead": "95b6471cd80c91a665a81a66fe95e12cdf45ca27"
53
53
  }