@darkpos/pricing 1.0.50 → 1.0.51
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.
|
@@ -353,4 +353,46 @@ describe('Auto Split', () => {
|
|
|
353
353
|
expect(subOrders[0].items[0].quantity).toEqual(1);
|
|
354
354
|
expect(subOrders[1].items[0].quantity).toEqual(1);
|
|
355
355
|
});
|
|
356
|
+
|
|
357
|
+
test('Auto split -> No departments. Should return items withouth joining them.', () => {
|
|
358
|
+
const { autoSplit } = pricingService.order;
|
|
359
|
+
|
|
360
|
+
const item1 = {
|
|
361
|
+
_id: '111',
|
|
362
|
+
itemId: '444',
|
|
363
|
+
modifiers: [{ _id: '123' }],
|
|
364
|
+
quantity: 1,
|
|
365
|
+
pieces: 2,
|
|
366
|
+
weight: 25,
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
const item2 = {
|
|
370
|
+
_id: '222',
|
|
371
|
+
itemId: '444',
|
|
372
|
+
modifiers: [{ _id: '234' }, { _id: '456' }],
|
|
373
|
+
quantity: 5,
|
|
374
|
+
pieces: 2,
|
|
375
|
+
weight: 25,
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
const subOrders = autoSplit({
|
|
379
|
+
parentOrder: {
|
|
380
|
+
items: [item1, item2],
|
|
381
|
+
status: {},
|
|
382
|
+
modifiers: [],
|
|
383
|
+
displayId: 1,
|
|
384
|
+
},
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
expect(subOrders.length).toEqual(1);
|
|
388
|
+
expect(subOrders[0].items.length).toEqual(2);
|
|
389
|
+
expect(subOrders[0].items[0].quantity).toEqual(1);
|
|
390
|
+
expect(subOrders[0].items[0].modifiers.length).toEqual(1);
|
|
391
|
+
expect(subOrders[0].items[0].modifiers[0]._id).toEqual('123');
|
|
392
|
+
|
|
393
|
+
expect(subOrders[0].items[1].quantity).toEqual(5);
|
|
394
|
+
expect(subOrders[0].items[1].modifiers.length).toEqual(2);
|
|
395
|
+
expect(subOrders[0].items[1].modifiers[0]._id).toEqual('234');
|
|
396
|
+
expect(subOrders[0].items[1].modifiers[1]._id).toEqual('456');
|
|
397
|
+
});
|
|
356
398
|
});
|
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
module.exports = ({ utils, _, actions, itemActions, modifierActions }) => {
|
|
2
2
|
const { helpers } = utils;
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const getDepartmentName = item => {
|
|
5
|
+
const deps = itemActions.getDepartmentModifiers(item);
|
|
6
|
+
return (deps.length && deps[0].name) || 'other';
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const isSplitByPieces = splitUnit => splitUnit === 'pieces';
|
|
10
|
+
const isSplitByWeight = splitUnit => splitUnit === 'weight';
|
|
11
|
+
|
|
12
|
+
const joinItemQuantityById = orders =>
|
|
5
13
|
orders.map(order => {
|
|
6
14
|
const items = order.items.reduce((arr, item) => {
|
|
7
15
|
const _items = arr;
|
|
8
|
-
const index = _items.findIndex(each =>
|
|
9
|
-
const preSubs = modifierActions.getSubscriptionModifiers(
|
|
10
|
-
each.modifiers
|
|
11
|
-
);
|
|
12
|
-
const curSubs = modifierActions.getSubscriptionModifiers(
|
|
13
|
-
item.modifiers
|
|
14
|
-
);
|
|
15
|
-
return (
|
|
16
|
-
each.itemId === item.itemId &&
|
|
17
|
-
((!each.serial && !item.serial) || each.serial === item.serial) &&
|
|
18
|
-
((preSubs.length < 1 && curSubs.length < 1) ||
|
|
19
|
-
(preSubs.length > 0 && curSubs.length > 0))
|
|
20
|
-
);
|
|
21
|
-
});
|
|
16
|
+
const index = _items.findIndex(each => each._id === item._id);
|
|
22
17
|
if (index !== -1)
|
|
23
18
|
_items[index] = {
|
|
24
19
|
..._items[index],
|
|
@@ -30,14 +25,6 @@ module.exports = ({ utils, _, actions, itemActions, modifierActions }) => {
|
|
|
30
25
|
return { ...order, items };
|
|
31
26
|
});
|
|
32
27
|
|
|
33
|
-
const getDepartmentName = item => {
|
|
34
|
-
const deps = itemActions.getDepartmentModifiers(item);
|
|
35
|
-
return (deps.length && deps[0].name) || 'other';
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const isSplitByPieces = splitUnit => splitUnit === 'pieces';
|
|
39
|
-
const isSplitByWeight = splitUnit => splitUnit === 'weight';
|
|
40
|
-
|
|
41
28
|
return function splitByDepartments(order) {
|
|
42
29
|
const { items } = order;
|
|
43
30
|
const itemsByDepartments = _.groupBy(items, getDepartmentName);
|
|
@@ -83,12 +70,14 @@ module.exports = ({ utils, _, actions, itemActions, modifierActions }) => {
|
|
|
83
70
|
const totalCount = getItemsTotalCount(newItems);
|
|
84
71
|
|
|
85
72
|
if (department && autoSplit && maxItems && totalCount > maxItems) {
|
|
73
|
+
let newItemid = helpers.getObjectID();
|
|
74
|
+
|
|
86
75
|
newItems.forEach(newItem => {
|
|
87
76
|
for (let j = 0; j < newItem.quantity; j += 1) {
|
|
88
77
|
const item = {
|
|
89
78
|
...newItem,
|
|
90
79
|
quantity: 1,
|
|
91
|
-
_id:
|
|
80
|
+
_id: newItemid,
|
|
92
81
|
};
|
|
93
82
|
const totalCountPerItem = getItemTotalCount(item);
|
|
94
83
|
|
|
@@ -99,14 +88,20 @@ module.exports = ({ utils, _, actions, itemActions, modifierActions }) => {
|
|
|
99
88
|
maxItems &&
|
|
100
89
|
departmentName === getDepartmentName(newOrder.items[0])
|
|
101
90
|
);
|
|
102
|
-
if (index > -1)
|
|
103
|
-
|
|
91
|
+
if (index > -1) {
|
|
92
|
+
splitOrders[index].items.push(item);
|
|
93
|
+
} else {
|
|
94
|
+
newItemid = helpers.getObjectID();
|
|
95
|
+
splitOrders.push(
|
|
96
|
+
create([{ ...item, _id: newItemid }], splitOrders.length + 1)
|
|
97
|
+
);
|
|
98
|
+
}
|
|
104
99
|
}
|
|
105
100
|
});
|
|
106
101
|
} else splitOrders.push(create(newItems, splitOrders.length + 1));
|
|
107
102
|
});
|
|
108
103
|
|
|
109
|
-
splitOrders =
|
|
104
|
+
splitOrders = joinItemQuantityById(splitOrders);
|
|
110
105
|
|
|
111
106
|
return splitOrders;
|
|
112
107
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.51",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"test:validateConditions": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/order/validateConditionsCalculate.test.js",
|
|
18
18
|
"test:hasModifier": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/modifier/hasModifier.test.js",
|
|
19
19
|
"test:item": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/item.test.js",
|
|
20
|
+
"test:split": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/order/split.test.js",
|
|
20
21
|
"lint": "eslint --quiet lib/"
|
|
21
22
|
},
|
|
22
23
|
"publishConfig": {
|
|
@@ -40,5 +41,5 @@
|
|
|
40
41
|
"supertest": "^6.2.3",
|
|
41
42
|
"supervisor": "^0.12.0"
|
|
42
43
|
},
|
|
43
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "256cf9e7f41cbdf88d38713f8edae725ec5e855e"
|
|
44
45
|
}
|