@darkpos/pricing 1.0.40 → 1.0.43
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.
- package/__TEST__/item/getItemsModifierDescription.test.js +141 -0
- package/__TEST__/mocks/items/item1Mock.json +73 -0
- package/__TEST__/mocks/items/item2Mock.json +73 -0
- package/__TEST__/mocks/items/item3Mock.json +73 -0
- package/__TEST__/modifier/getGroupedModifierLabels.test.js +95 -0
- package/__TEST__/modifier/getGroupedModifiers.test.js +65 -0
- package/__TEST__/modifier/getNotesToModifierTags.test.js +78 -0
- package/__TEST__/modifier/isOptionsOverride.test.js +46 -0
- package/__TEST__/order/createSuborder.test.js +36 -0
- package/__TEST__/order/getSuborder.test.js +89 -0
- package/__TEST__/order/pickEndDate.test.js +3 -3
- package/lib/item/getItemModifiersDescription.js +39 -7
- package/lib/modifier/getGroupedModifierLabels.js +10 -0
- package/lib/modifier/getGroupedModifiers.js +21 -0
- package/lib/modifier/getNotesToModifierTags.js +21 -0
- package/lib/modifier/index.js +8 -0
- package/lib/modifier/isOptionsOverride.js +9 -0
- package/lib/order/createSuborder.js +17 -0
- package/lib/order/getSuborder.js +49 -0
- package/lib/order/index.js +4 -0
- package/lib/order/pickEndDate.js +24 -27
- package/lib/order/splitByDepartments.js +3 -48
- package/package.json +2 -2
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
const _ = require('lodash');
|
|
2
|
+
const getItemModifiersDescriptionFunction = require('../../lib/item/getItemModifiersDescription');
|
|
3
|
+
|
|
4
|
+
describe('getItemModifiersDescription Function', () => {
|
|
5
|
+
const modifierActions = {
|
|
6
|
+
isHidden: jest.fn(),
|
|
7
|
+
isAmountOverride: jest.fn(),
|
|
8
|
+
isDepartment: jest.fn(),
|
|
9
|
+
isDirect: jest.fn(),
|
|
10
|
+
isGroupOfValues: jest.fn(),
|
|
11
|
+
getSelectedValues: jest.fn(),
|
|
12
|
+
getGroupedModifiers: jest.fn(),
|
|
13
|
+
getNotesToModifierTags: jest.fn(),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const settings = {
|
|
17
|
+
order: {
|
|
18
|
+
groupModifiers: false,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const getItemModifiersDescription = getItemModifiersDescriptionFunction({
|
|
23
|
+
modifierActions,
|
|
24
|
+
_,
|
|
25
|
+
settings,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
jest.clearAllMocks();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('should return an empty array if item or modifiers are not provided', () => {
|
|
33
|
+
const result = getItemModifiersDescription(null);
|
|
34
|
+
expect(result).toEqual([]);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('should filter and map modifiers correctly', () => {
|
|
38
|
+
const item = {
|
|
39
|
+
modifiers: [
|
|
40
|
+
{
|
|
41
|
+
_id: 'mod1',
|
|
42
|
+
name: 'Modifier 1',
|
|
43
|
+
_computed: { description: 'Desc 1' },
|
|
44
|
+
},
|
|
45
|
+
{ _id: 'mod2', name: 'Modifier 2' },
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
modifierActions.isHidden
|
|
50
|
+
.mockReturnValueOnce(false)
|
|
51
|
+
.mockReturnValueOnce(false);
|
|
52
|
+
modifierActions.isAmountOverride
|
|
53
|
+
.mockReturnValueOnce(false)
|
|
54
|
+
.mockReturnValueOnce(false);
|
|
55
|
+
modifierActions.isDepartment
|
|
56
|
+
.mockReturnValueOnce(false)
|
|
57
|
+
.mockReturnValueOnce(false);
|
|
58
|
+
modifierActions.isDirect
|
|
59
|
+
.mockReturnValueOnce(true)
|
|
60
|
+
.mockReturnValueOnce(true);
|
|
61
|
+
modifierActions.isGroupOfValues
|
|
62
|
+
.mockReturnValueOnce(false)
|
|
63
|
+
.mockReturnValueOnce(false);
|
|
64
|
+
modifierActions.getNotesToModifierTags.mockReturnValueOnce([
|
|
65
|
+
{ label: 'Desc 1', value: 'mod1' },
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
const result = getItemModifiersDescription(item);
|
|
69
|
+
|
|
70
|
+
expect(result).toEqual([{ label: 'Desc 1', value: 'mod1' }]);
|
|
71
|
+
|
|
72
|
+
expect(modifierActions.isHidden).toHaveBeenCalledTimes(2);
|
|
73
|
+
expect(modifierActions.isAmountOverride).toHaveBeenCalledTimes(2);
|
|
74
|
+
expect(modifierActions.isDepartment).toHaveBeenCalledTimes(2);
|
|
75
|
+
expect(modifierActions.isDirect).toHaveBeenCalledTimes(2);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('should handle selected override options in the modifier', () => {
|
|
79
|
+
const item = {
|
|
80
|
+
modifiers: [
|
|
81
|
+
{
|
|
82
|
+
_id: 'mod1',
|
|
83
|
+
name: 'Modifier 1',
|
|
84
|
+
compute: { amount: 100 },
|
|
85
|
+
properties: { override: { selected: { selectedUnit: 'kg' } } },
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
modifierActions.isHidden.mockReturnValueOnce(false);
|
|
91
|
+
modifierActions.isAmountOverride.mockReturnValueOnce(false);
|
|
92
|
+
modifierActions.isDepartment.mockReturnValueOnce(false);
|
|
93
|
+
modifierActions.isDirect.mockReturnValueOnce(true);
|
|
94
|
+
modifierActions.getNotesToModifierTags.mockReturnValueOnce([
|
|
95
|
+
{
|
|
96
|
+
label: 'Modifier 1 100 kg',
|
|
97
|
+
value: 'mod1',
|
|
98
|
+
data: item.modifiers[0],
|
|
99
|
+
quantity: 0,
|
|
100
|
+
},
|
|
101
|
+
]);
|
|
102
|
+
const result = getItemModifiersDescription(item);
|
|
103
|
+
|
|
104
|
+
expect(result).toEqual([
|
|
105
|
+
{
|
|
106
|
+
label: 'Modifier 1 100 kg',
|
|
107
|
+
value: 'mod1',
|
|
108
|
+
data: item.modifiers[0],
|
|
109
|
+
quantity: 0,
|
|
110
|
+
},
|
|
111
|
+
]);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('should group modifiers when groupModifiers setting is true', () => {
|
|
115
|
+
const item = {
|
|
116
|
+
modifiers: [
|
|
117
|
+
{
|
|
118
|
+
_id: 'mod1',
|
|
119
|
+
name: 'Modifier 1',
|
|
120
|
+
_computed: { description: 'Desc 1' },
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
settings.order.groupModifiers = true;
|
|
126
|
+
modifierActions.isHidden.mockReturnValueOnce(false);
|
|
127
|
+
modifierActions.isAmountOverride.mockReturnValueOnce(false);
|
|
128
|
+
modifierActions.isDepartment.mockReturnValueOnce(false);
|
|
129
|
+
modifierActions.isDirect.mockReturnValueOnce(true);
|
|
130
|
+
modifierActions.getGroupedModifiers.mockReturnValueOnce([
|
|
131
|
+
{ label: 'Grouped Modifier', value: 'mod1' },
|
|
132
|
+
]);
|
|
133
|
+
modifierActions.getNotesToModifierTags.mockReturnValueOnce([
|
|
134
|
+
{ label: 'Grouped Modifier', value: 'mod1' },
|
|
135
|
+
]);
|
|
136
|
+
|
|
137
|
+
const result = getItemModifiersDescription(item);
|
|
138
|
+
|
|
139
|
+
expect(result).toEqual([{ label: 'Grouped Modifier', value: 'mod1' }]);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"location": {},
|
|
3
|
+
"status": {
|
|
4
|
+
"picked": {
|
|
5
|
+
"value": false,
|
|
6
|
+
"date": ""
|
|
7
|
+
},
|
|
8
|
+
"paid": {
|
|
9
|
+
"value": false,
|
|
10
|
+
"date": ""
|
|
11
|
+
},
|
|
12
|
+
"tracker": []
|
|
13
|
+
},
|
|
14
|
+
"name": "Dummy Pants 1",
|
|
15
|
+
"description": "Dummy Pants 1",
|
|
16
|
+
"pieces": 1,
|
|
17
|
+
"modifiersTotalAmount": 0,
|
|
18
|
+
"total": 2,
|
|
19
|
+
"totalPaid": 0,
|
|
20
|
+
"price": 2,
|
|
21
|
+
"quantity": 1,
|
|
22
|
+
"path": ",66da070aac2d4ae39904050f,66da131a81cf1303bc32a2c7,",
|
|
23
|
+
"notes": [],
|
|
24
|
+
"serial": null,
|
|
25
|
+
"sku": "DUN-PAN1",
|
|
26
|
+
"modifiers": [],
|
|
27
|
+
"_id": "66ec759cd57e32c3455724a0",
|
|
28
|
+
"weight": null,
|
|
29
|
+
"properties": null,
|
|
30
|
+
"hasInventory": true,
|
|
31
|
+
"inventoryType": "pull",
|
|
32
|
+
"category": null,
|
|
33
|
+
"priceLevels": [
|
|
34
|
+
{
|
|
35
|
+
"value": 10,
|
|
36
|
+
"tags": [
|
|
37
|
+
"default"
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"value": 2,
|
|
42
|
+
"tags": [
|
|
43
|
+
"vip"
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"value": 10,
|
|
48
|
+
"tags": [
|
|
49
|
+
"default",
|
|
50
|
+
"press only"
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"value": 2,
|
|
55
|
+
"tags": [
|
|
56
|
+
"vip",
|
|
57
|
+
"press only"
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"costLevels": [],
|
|
62
|
+
"itemId": "66da11fdac2d4ae39904465e",
|
|
63
|
+
"menuRuleId": "66da132381cf1303bc32a2c8",
|
|
64
|
+
"__typename": "OrderItem",
|
|
65
|
+
"subTotals": {
|
|
66
|
+
"_included": 0,
|
|
67
|
+
"_xincluded": 0,
|
|
68
|
+
"_direct": 0,
|
|
69
|
+
"_xdirect": 0,
|
|
70
|
+
"_simple": 2,
|
|
71
|
+
"_actual": 2
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"location": {},
|
|
3
|
+
"status": {
|
|
4
|
+
"picked": {
|
|
5
|
+
"value": false,
|
|
6
|
+
"date": ""
|
|
7
|
+
},
|
|
8
|
+
"paid": {
|
|
9
|
+
"value": false,
|
|
10
|
+
"date": ""
|
|
11
|
+
},
|
|
12
|
+
"tracker": []
|
|
13
|
+
},
|
|
14
|
+
"name": "Dummy Pants 2",
|
|
15
|
+
"description": "Dummy Pants 2",
|
|
16
|
+
"pieces": 1,
|
|
17
|
+
"modifiersTotalAmount": 0,
|
|
18
|
+
"total": 2,
|
|
19
|
+
"totalPaid": 0,
|
|
20
|
+
"price": 2,
|
|
21
|
+
"quantity": 1,
|
|
22
|
+
"path": ",66da070aac2d4ae39904050f,66da131a81cf1303bc32a2c7,",
|
|
23
|
+
"notes": [],
|
|
24
|
+
"serial": null,
|
|
25
|
+
"sku": "DUN-PAN2",
|
|
26
|
+
"modifiers": [],
|
|
27
|
+
"_id": "66ec759cd57e32c3455724a0",
|
|
28
|
+
"weight": null,
|
|
29
|
+
"properties": null,
|
|
30
|
+
"hasInventory": true,
|
|
31
|
+
"inventoryType": "pull",
|
|
32
|
+
"category": null,
|
|
33
|
+
"priceLevels": [
|
|
34
|
+
{
|
|
35
|
+
"value": 10,
|
|
36
|
+
"tags": [
|
|
37
|
+
"default"
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"value": 2,
|
|
42
|
+
"tags": [
|
|
43
|
+
"vip"
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"value": 10,
|
|
48
|
+
"tags": [
|
|
49
|
+
"default",
|
|
50
|
+
"press only"
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"value": 2,
|
|
55
|
+
"tags": [
|
|
56
|
+
"vip",
|
|
57
|
+
"press only"
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"costLevels": [],
|
|
62
|
+
"itemId": "66da11fdac2d4ae39904465e",
|
|
63
|
+
"menuRuleId": "66da132381cf1303bc32a2c8",
|
|
64
|
+
"__typename": "OrderItem",
|
|
65
|
+
"subTotals": {
|
|
66
|
+
"_included": 0,
|
|
67
|
+
"_xincluded": 0,
|
|
68
|
+
"_direct": 0,
|
|
69
|
+
"_xdirect": 0,
|
|
70
|
+
"_simple": 2,
|
|
71
|
+
"_actual": 2
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"location": {},
|
|
3
|
+
"status": {
|
|
4
|
+
"picked": {
|
|
5
|
+
"value": false,
|
|
6
|
+
"date": ""
|
|
7
|
+
},
|
|
8
|
+
"paid": {
|
|
9
|
+
"value": false,
|
|
10
|
+
"date": ""
|
|
11
|
+
},
|
|
12
|
+
"tracker": []
|
|
13
|
+
},
|
|
14
|
+
"name": "Dummy Pants 3",
|
|
15
|
+
"description": "Dummy Pants 3",
|
|
16
|
+
"pieces": 1,
|
|
17
|
+
"modifiersTotalAmount": 0,
|
|
18
|
+
"total": 2,
|
|
19
|
+
"totalPaid": 0,
|
|
20
|
+
"price": 2,
|
|
21
|
+
"quantity": 1,
|
|
22
|
+
"path": ",66da070aac2d4ae39904050f,66da131a81cf1303bc32a2c7,",
|
|
23
|
+
"notes": [],
|
|
24
|
+
"serial": null,
|
|
25
|
+
"sku": "DUN-PAN3",
|
|
26
|
+
"modifiers": [],
|
|
27
|
+
"_id": "66ec759cd57e32c3455724a0",
|
|
28
|
+
"weight": null,
|
|
29
|
+
"properties": null,
|
|
30
|
+
"hasInventory": true,
|
|
31
|
+
"inventoryType": "pull",
|
|
32
|
+
"category": null,
|
|
33
|
+
"priceLevels": [
|
|
34
|
+
{
|
|
35
|
+
"value": 10,
|
|
36
|
+
"tags": [
|
|
37
|
+
"default"
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"value": 2,
|
|
42
|
+
"tags": [
|
|
43
|
+
"vip"
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"value": 10,
|
|
48
|
+
"tags": [
|
|
49
|
+
"default",
|
|
50
|
+
"press only"
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"value": 2,
|
|
55
|
+
"tags": [
|
|
56
|
+
"vip",
|
|
57
|
+
"press only"
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"costLevels": [],
|
|
62
|
+
"itemId": "66da11fdac2d4ae39904465e",
|
|
63
|
+
"menuRuleId": "66da132381cf1303bc32a2c8",
|
|
64
|
+
"__typename": "OrderItem",
|
|
65
|
+
"subTotals": {
|
|
66
|
+
"_included": 0,
|
|
67
|
+
"_xincluded": 0,
|
|
68
|
+
"_direct": 0,
|
|
69
|
+
"_xdirect": 0,
|
|
70
|
+
"_simple": 2,
|
|
71
|
+
"_actual": 2
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const getGroupedModifierLabelsFunction = require('../../lib/modifier/getGroupedModifierLabels');
|
|
2
|
+
|
|
3
|
+
describe('getGroupedModifierLabels Function', () => {
|
|
4
|
+
const actions = {
|
|
5
|
+
getGroupedModifiers: jest.fn(),
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const getGroupedModifierLabels = getGroupedModifierLabelsFunction({
|
|
9
|
+
actions,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
jest.clearAllMocks();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('should return an empty array if no modifiers are provided', () => {
|
|
17
|
+
actions.getGroupedModifiers.mockReturnValueOnce([]);
|
|
18
|
+
|
|
19
|
+
const result = getGroupedModifierLabels([]);
|
|
20
|
+
|
|
21
|
+
expect(result).toEqual([]);
|
|
22
|
+
expect(actions.getGroupedModifiers).toHaveBeenCalledWith([]);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('should map modifiers to labels and group them by modifierId', () => {
|
|
26
|
+
const modifiers = [
|
|
27
|
+
{ name: 'Modifier 1', modifierId: 'mod1' },
|
|
28
|
+
{ name: 'Modifier 2', modifierId: 'mod2' },
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const groupedModifiers = [
|
|
32
|
+
{ label: '1 Modifier 1', value: 'mod1', data: modifiers[0], quantity: 1 },
|
|
33
|
+
{ label: '1 Modifier 2', value: 'mod2', data: modifiers[1], quantity: 1 },
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
actions.getGroupedModifiers.mockReturnValueOnce(groupedModifiers);
|
|
37
|
+
|
|
38
|
+
const result = getGroupedModifierLabels(modifiers);
|
|
39
|
+
|
|
40
|
+
expect(result).toEqual(['1 Modifier 1', '1 Modifier 2']);
|
|
41
|
+
expect(actions.getGroupedModifiers).toHaveBeenCalledWith([
|
|
42
|
+
{ label: 'Modifier 1', value: 'mod1', data: modifiers[0], quantity: 1 },
|
|
43
|
+
{ label: 'Modifier 2', value: 'mod2', data: modifiers[1], quantity: 1 },
|
|
44
|
+
]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('should group modifiers with the same modifierId and increment quantity', () => {
|
|
48
|
+
const modifiers = [
|
|
49
|
+
{ name: 'Modifier 1', modifierId: 'mod1' },
|
|
50
|
+
{ name: 'Modifier 1', modifierId: 'mod1' }, // Same modifierId
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
const groupedModifiers = [
|
|
54
|
+
{ label: '2 Modifier 1', value: 'mod1', data: modifiers[0], quantity: 2 },
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
actions.getGroupedModifiers.mockReturnValueOnce(groupedModifiers);
|
|
58
|
+
|
|
59
|
+
const result = getGroupedModifierLabels(modifiers);
|
|
60
|
+
|
|
61
|
+
expect(result).toEqual(['2 Modifier 1']);
|
|
62
|
+
expect(actions.getGroupedModifiers).toHaveBeenCalledWith([
|
|
63
|
+
{ label: 'Modifier 1', value: 'mod1', data: modifiers[0], quantity: 1 },
|
|
64
|
+
{ label: 'Modifier 1', value: 'mod1', data: modifiers[1], quantity: 1 },
|
|
65
|
+
]);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('should handle a single modifier correctly', () => {
|
|
69
|
+
const modifiers = [{ name: 'Modifier 1', modifierId: 'mod1' }];
|
|
70
|
+
|
|
71
|
+
const groupedModifiers = [
|
|
72
|
+
{ label: '1 Modifier 1', value: 'mod1', data: modifiers[0], quantity: 1 },
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
actions.getGroupedModifiers.mockReturnValueOnce(groupedModifiers);
|
|
76
|
+
|
|
77
|
+
const result = getGroupedModifierLabels(modifiers);
|
|
78
|
+
|
|
79
|
+
expect(result).toEqual(['1 Modifier 1']);
|
|
80
|
+
expect(actions.getGroupedModifiers).toHaveBeenCalledWith([
|
|
81
|
+
{ label: 'Modifier 1', value: 'mod1', data: modifiers[0], quantity: 1 },
|
|
82
|
+
]);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('should correctly handle an empty modifiers array', () => {
|
|
86
|
+
const modifiers = [];
|
|
87
|
+
|
|
88
|
+
actions.getGroupedModifiers.mockReturnValueOnce([]);
|
|
89
|
+
|
|
90
|
+
const result = getGroupedModifierLabels(modifiers);
|
|
91
|
+
|
|
92
|
+
expect(result).toEqual([]);
|
|
93
|
+
expect(actions.getGroupedModifiers).toHaveBeenCalledWith([]);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const getGroupedModifiersFunction = require('../../lib/modifier/getGroupedModifiers');
|
|
2
|
+
|
|
3
|
+
describe('getGroupedModifiers Function', () => {
|
|
4
|
+
const getGroupedModifiers = getGroupedModifiersFunction();
|
|
5
|
+
|
|
6
|
+
test('should return an empty array if no tags are provided', () => {
|
|
7
|
+
const result = getGroupedModifiers([]);
|
|
8
|
+
expect(result).toEqual([]);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test('should group modifiers by modifierId and increment quantity', () => {
|
|
12
|
+
const tags = [
|
|
13
|
+
{ label: 'Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
|
|
14
|
+
{ label: 'Modifier 2', data: { modifierId: 'mod2' }, quantity: 1 },
|
|
15
|
+
{ label: 'Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const result = getGroupedModifiers(tags);
|
|
19
|
+
|
|
20
|
+
expect(result).toEqual([
|
|
21
|
+
{ label: '2 Modifier 1', data: { modifierId: 'mod1' }, quantity: 2 },
|
|
22
|
+
{ label: '1 Modifier 2', data: { modifierId: 'mod2' }, quantity: 1 },
|
|
23
|
+
]);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('should correctly handle tags with different modifierIds', () => {
|
|
27
|
+
const tags = [
|
|
28
|
+
{ label: 'Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
|
|
29
|
+
{ label: 'Modifier 2', data: { modifierId: 'mod2' }, quantity: 1 },
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const result = getGroupedModifiers(tags);
|
|
33
|
+
|
|
34
|
+
expect(result).toEqual([
|
|
35
|
+
{ label: '1 Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
|
|
36
|
+
{ label: '1 Modifier 2', data: { modifierId: 'mod2' }, quantity: 1 },
|
|
37
|
+
]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('should not modify original tags array', () => {
|
|
41
|
+
const tags = [
|
|
42
|
+
{ label: 'Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
|
|
43
|
+
{ label: 'Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
const originalTagsCopy = [...tags];
|
|
47
|
+
|
|
48
|
+
getGroupedModifiers(tags);
|
|
49
|
+
|
|
50
|
+
expect(tags).toEqual(originalTagsCopy); // Ensure original array is not mutated
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('should format the label to include the quantity', () => {
|
|
54
|
+
const tags = [
|
|
55
|
+
{ label: 'Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
|
|
56
|
+
{ label: 'Modifier 1', data: { modifierId: 'mod1' }, quantity: 1 },
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
const result = getGroupedModifiers(tags);
|
|
60
|
+
|
|
61
|
+
expect(result).toEqual([
|
|
62
|
+
{ label: '2 Modifier 1', data: { modifierId: 'mod1' }, quantity: 2 },
|
|
63
|
+
]);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const getNotesToModifierTagsFunction = require('../../lib/modifier/getNotesToModifierTags');
|
|
2
|
+
|
|
3
|
+
describe('getNotesToModifierTags Function', () => {
|
|
4
|
+
const getNotesToModifierTags = getNotesToModifierTagsFunction();
|
|
5
|
+
|
|
6
|
+
test('should return modifierTags if no notes are provided', () => {
|
|
7
|
+
const modifierTags = [
|
|
8
|
+
{ label: 'Modifier 1', value: 'mod1', data: {}, quantity: 1 },
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
const result = getNotesToModifierTags({ notes: null, modifierTags });
|
|
12
|
+
expect(result).toEqual(modifierTags);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('should return modifierTags if notes array is empty', () => {
|
|
16
|
+
const modifierTags = [
|
|
17
|
+
{ label: 'Modifier 1', value: 'mod1', data: {}, quantity: 1 },
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
const result = getNotesToModifierTags({ notes: [], modifierTags });
|
|
21
|
+
expect(result).toEqual(modifierTags);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('should filter out notes that are null or have a url', () => {
|
|
25
|
+
const notes = [
|
|
26
|
+
{ message: 'Note 1' },
|
|
27
|
+
{ message: 'Note 2', url: 'http://example.com' }, // Should be filtered out
|
|
28
|
+
null, // Should be filtered out
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const modifierTags = [
|
|
32
|
+
{ label: 'Modifier 1', value: 'mod1', data: {}, quantity: 1 },
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
const result = getNotesToModifierTags({ notes, modifierTags });
|
|
36
|
+
|
|
37
|
+
expect(result).toEqual([
|
|
38
|
+
{ label: 'Modifier 1', value: 'mod1', data: {}, quantity: 1 },
|
|
39
|
+
{ label: 'Note 1', value: '0', data: { message: 'Note 1' }, quantity: 1 },
|
|
40
|
+
]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('should map notes to noteTags and append to modifierTags', () => {
|
|
44
|
+
const notes = [{ message: 'Note 1' }, { message: 'Note 2' }];
|
|
45
|
+
|
|
46
|
+
const modifierTags = [
|
|
47
|
+
{ label: 'Modifier 1', value: 'mod1', data: {}, quantity: 1 },
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
const result = getNotesToModifierTags({ notes, modifierTags });
|
|
51
|
+
|
|
52
|
+
expect(result).toEqual([
|
|
53
|
+
{ label: 'Modifier 1', value: 'mod1', data: {}, quantity: 1 },
|
|
54
|
+
{ label: 'Note 1', value: '0', data: { message: 'Note 1' }, quantity: 1 },
|
|
55
|
+
{ label: 'Note 2', value: '1', data: { message: 'Note 2' }, quantity: 1 },
|
|
56
|
+
]);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('should handle case where notes contain falsy values', () => {
|
|
60
|
+
const notes = [null, undefined, { message: 'Valid Note' }];
|
|
61
|
+
|
|
62
|
+
const modifierTags = [
|
|
63
|
+
{ label: 'Modifier 1', value: 'mod1', data: {}, quantity: 1 },
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
const result = getNotesToModifierTags({ notes, modifierTags });
|
|
67
|
+
|
|
68
|
+
expect(result).toEqual([
|
|
69
|
+
{ label: 'Modifier 1', value: 'mod1', data: {}, quantity: 1 },
|
|
70
|
+
{
|
|
71
|
+
label: 'Valid Note',
|
|
72
|
+
value: '0',
|
|
73
|
+
data: { message: 'Valid Note' },
|
|
74
|
+
quantity: 1,
|
|
75
|
+
},
|
|
76
|
+
]);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const isOptionsOverrideFunction = require('../../lib/modifier/isOptionsOverride');
|
|
2
|
+
|
|
3
|
+
describe('isOptionsOverride Function', () => {
|
|
4
|
+
const isOptionsOverride = isOptionsOverrideFunction();
|
|
5
|
+
|
|
6
|
+
test('should return false when no modifier is provided', () => {
|
|
7
|
+
const result = isOptionsOverride(null);
|
|
8
|
+
expect(result).toBe(false);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test('should return false when modifier does not have properties', () => {
|
|
12
|
+
const modifier = { someKey: 'someValue' };
|
|
13
|
+
const result = isOptionsOverride(modifier);
|
|
14
|
+
expect(result).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('should return false when modifier properties do not have override', () => {
|
|
18
|
+
const modifier = { properties: {} };
|
|
19
|
+
const result = isOptionsOverride(modifier);
|
|
20
|
+
expect(result).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('should return false when override has no options', () => {
|
|
24
|
+
const modifier = {
|
|
25
|
+
properties: {
|
|
26
|
+
override: {
|
|
27
|
+
options: [],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
const result = isOptionsOverride(modifier);
|
|
32
|
+
expect(result).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('should return true when override has options', () => {
|
|
36
|
+
const modifier = {
|
|
37
|
+
properties: {
|
|
38
|
+
override: {
|
|
39
|
+
options: ['option1', 'option2'],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
const result = isOptionsOverride(modifier);
|
|
44
|
+
expect(result).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const usePricing = require('../../index');
|
|
2
|
+
const mockStores = require('../mocks/stores');
|
|
3
|
+
const orderMock = require('../modifier/mocks/orderMock.json');
|
|
4
|
+
const item1Mock = require('../mocks/items/item1Mock.json');
|
|
5
|
+
const item2Mock = require('../mocks/items/item2Mock.json');
|
|
6
|
+
const item3Mock = require('../mocks/items/item3Mock.json');
|
|
7
|
+
|
|
8
|
+
const session = {
|
|
9
|
+
store: mockStores[0],
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const pricingService = usePricing(session);
|
|
13
|
+
|
|
14
|
+
describe('Create suborder', () => {
|
|
15
|
+
test('Create a suborder with one order', () => {
|
|
16
|
+
const subOrders = pricingService.order.createSuborder(orderMock);
|
|
17
|
+
const order = {
|
|
18
|
+
...orderMock,
|
|
19
|
+
orders: subOrders,
|
|
20
|
+
};
|
|
21
|
+
expect(order.orders).toHaveLength(1);
|
|
22
|
+
expect(subOrders).toHaveLength(1);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('Create suborder with multiple items in the order', () => {
|
|
26
|
+
const multipleItemsOrderMock = {
|
|
27
|
+
...orderMock,
|
|
28
|
+
items: [item1Mock, item2Mock, item3Mock], // assuming items is an array of items
|
|
29
|
+
};
|
|
30
|
+
const subOrders = pricingService.order.createSuborder(
|
|
31
|
+
multipleItemsOrderMock
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
expect(subOrders[0].items).toHaveLength(3); // Suborders should match number of items
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const usePricing = require('../../index');
|
|
2
|
+
const mockStores = require('../mocks/stores');
|
|
3
|
+
const orderMock = require('../modifier/mocks/orderMock.json');
|
|
4
|
+
|
|
5
|
+
const session = {
|
|
6
|
+
store: mockStores[0],
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const pricingService = usePricing(session);
|
|
10
|
+
|
|
11
|
+
const mockItem = {
|
|
12
|
+
location: {},
|
|
13
|
+
status: {
|
|
14
|
+
picked: {
|
|
15
|
+
value: false,
|
|
16
|
+
date: '',
|
|
17
|
+
},
|
|
18
|
+
paid: {
|
|
19
|
+
value: false,
|
|
20
|
+
date: '',
|
|
21
|
+
},
|
|
22
|
+
tracker: [],
|
|
23
|
+
},
|
|
24
|
+
name: 'Andre Pants 2',
|
|
25
|
+
description: 'Andre Pants 2',
|
|
26
|
+
pieces: 1,
|
|
27
|
+
modifiersTotalAmount: 0,
|
|
28
|
+
total: 2,
|
|
29
|
+
totalPaid: 0,
|
|
30
|
+
price: 2,
|
|
31
|
+
quantity: 1,
|
|
32
|
+
path: ',66da070aac2d4ae39904050f,66da131a81cf1303bc32a2c7,',
|
|
33
|
+
notes: [],
|
|
34
|
+
serial: null,
|
|
35
|
+
sku: 'AND-PAN2',
|
|
36
|
+
modifiers: [],
|
|
37
|
+
_id: '66ec759cd57e32c3455724a0',
|
|
38
|
+
weight: null,
|
|
39
|
+
properties: null,
|
|
40
|
+
hasInventory: true,
|
|
41
|
+
inventoryType: 'pull',
|
|
42
|
+
category: null,
|
|
43
|
+
priceLevels: [
|
|
44
|
+
{
|
|
45
|
+
value: 10,
|
|
46
|
+
tags: ['default'],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
value: 2,
|
|
50
|
+
tags: ['vip'],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
value: 10,
|
|
54
|
+
tags: ['default', 'press only'],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
value: 2,
|
|
58
|
+
tags: ['vip', 'press only'],
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
costLevels: [],
|
|
62
|
+
itemId: '66da11fdac2d4ae39904465e',
|
|
63
|
+
menuRuleId: '66da132381cf1303bc32a2c8',
|
|
64
|
+
__typename: 'OrderItem',
|
|
65
|
+
subTotals: {
|
|
66
|
+
_included: 0,
|
|
67
|
+
_xincluded: 0,
|
|
68
|
+
_direct: 0,
|
|
69
|
+
_xdirect: 0,
|
|
70
|
+
_simple: 2,
|
|
71
|
+
_actual: 2,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
describe('Get sub order', () => {
|
|
76
|
+
test('Get a suborder with one item', () => {
|
|
77
|
+
const order = orderMock;
|
|
78
|
+
const create = pricingService.order.getSuborder({ order });
|
|
79
|
+
const newSubOrders = [create(order.items, 1)];
|
|
80
|
+
expect(newSubOrders).toHaveLength(1);
|
|
81
|
+
});
|
|
82
|
+
test('Get a suborder with multiple items', () => {
|
|
83
|
+
const order = orderMock;
|
|
84
|
+
const create = pricingService.order.getSuborder({ order });
|
|
85
|
+
order.items = [...order.items, mockItem];
|
|
86
|
+
const newSubOrders = [create(order.items, 2)];
|
|
87
|
+
expect(newSubOrders).toHaveLength(1);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -56,8 +56,8 @@ describe('pickEndDate function', () => {
|
|
|
56
56
|
|
|
57
57
|
const expectedDate = now
|
|
58
58
|
.clone()
|
|
59
|
-
.add(
|
|
60
|
-
.set({ hour:
|
|
59
|
+
.add(3, 'days')
|
|
60
|
+
.set({ hour: 0, minute: 0, second: 0 })
|
|
61
61
|
.utc()
|
|
62
62
|
.format();
|
|
63
63
|
|
|
@@ -113,7 +113,7 @@ describe('pickEndDate function', () => {
|
|
|
113
113
|
const expectedDate = now
|
|
114
114
|
.clone()
|
|
115
115
|
.add(2, 'days') // Skips the closed Wednesday, goes to Thursday
|
|
116
|
-
.set({ hour:
|
|
116
|
+
.set({ hour: 0, minute: 0, second: 0 })
|
|
117
117
|
.utc()
|
|
118
118
|
.format();
|
|
119
119
|
|
|
@@ -1,22 +1,54 @@
|
|
|
1
|
-
module.exports = ({ modifierActions }) =>
|
|
1
|
+
module.exports = ({ modifierActions, _, settings }) =>
|
|
2
2
|
function getItemModifiersDescription(item) {
|
|
3
|
+
const groupModifiers =
|
|
4
|
+
settings && settings.order && settings.order.groupModifiers;
|
|
3
5
|
if (!item || !Array.isArray(item.modifiers)) return [];
|
|
4
|
-
|
|
6
|
+
let description = item.modifiers
|
|
5
7
|
.filter(
|
|
6
8
|
each =>
|
|
7
9
|
!modifierActions.isHidden(each) &&
|
|
8
10
|
!modifierActions.isAmountOverride(each) &&
|
|
11
|
+
!modifierActions.isDepartment(each) &&
|
|
9
12
|
modifierActions.isDirect(each)
|
|
10
13
|
)
|
|
11
14
|
.map(modifier => {
|
|
12
|
-
const { name } = modifier;
|
|
15
|
+
const { name, _id, compute = {} } = modifier;
|
|
13
16
|
let label = name;
|
|
14
17
|
if (modifierActions.isGroupOfValues(modifier))
|
|
15
18
|
label = modifierActions.getSelectedValues(modifier) || label;
|
|
19
|
+
const selectedOverrideOptions = _.get(
|
|
20
|
+
modifier,
|
|
21
|
+
'properties.override.selected'
|
|
22
|
+
);
|
|
23
|
+
if (
|
|
24
|
+
modifier &&
|
|
25
|
+
!modifier.included &&
|
|
26
|
+
modifier._computed &&
|
|
27
|
+
modifier._computed.description
|
|
28
|
+
) {
|
|
29
|
+
label = modifier._computed.description;
|
|
30
|
+
}
|
|
16
31
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
32
|
+
const modifierValue = {
|
|
33
|
+
label,
|
|
34
|
+
value: _id,
|
|
35
|
+
data: modifier,
|
|
36
|
+
quantity: 1,
|
|
37
|
+
};
|
|
20
38
|
|
|
21
|
-
|
|
39
|
+
if (selectedOverrideOptions) {
|
|
40
|
+
modifierValue.label = `${name} ${compute.amount} ${selectedOverrideOptions.selectedUnit}`;
|
|
41
|
+
modifierValue.quantity = 0;
|
|
42
|
+
}
|
|
43
|
+
return modifierValue;
|
|
44
|
+
});
|
|
45
|
+
if (groupModifiers) {
|
|
46
|
+
description = modifierActions.getGroupedModifiers(description);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const descriptions = modifierActions.getNotesToModifierTags({
|
|
50
|
+
notes: item.notes,
|
|
51
|
+
modifierTags: description,
|
|
52
|
+
});
|
|
53
|
+
return descriptions;
|
|
22
54
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module.exports = ({ actions }) =>
|
|
2
|
+
function getGroupedModifierLabels(modifiers) {
|
|
3
|
+
const gModifiers = modifiers.map(modifier => ({
|
|
4
|
+
label: modifier.name,
|
|
5
|
+
value: modifier.modifierId,
|
|
6
|
+
data: modifier,
|
|
7
|
+
quantity: 1,
|
|
8
|
+
}));
|
|
9
|
+
return actions.getGroupedModifiers(gModifiers).map(tag => tag.label);
|
|
10
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module.exports = () =>
|
|
2
|
+
function getGroupedModifiers(tags) {
|
|
3
|
+
return tags
|
|
4
|
+
.reduce((acc, curr) => {
|
|
5
|
+
const found = acc.find(
|
|
6
|
+
item => item.data.modifierId === curr.data.modifierId
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
if (found) {
|
|
10
|
+
found.quantity += 1;
|
|
11
|
+
} else {
|
|
12
|
+
acc.push({ ...curr });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return acc;
|
|
16
|
+
}, [])
|
|
17
|
+
.map(tag => ({
|
|
18
|
+
...tag,
|
|
19
|
+
label: `${tag.quantity} ${tag.label}`,
|
|
20
|
+
}));
|
|
21
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module.exports = () =>
|
|
2
|
+
function getNotesToModifierTags({ notes, modifierTags }) {
|
|
3
|
+
let noteTags = [];
|
|
4
|
+
if (notes && notes.length > 0) {
|
|
5
|
+
noteTags =
|
|
6
|
+
notes
|
|
7
|
+
.filter(Boolean)
|
|
8
|
+
.filter(item => item && !item.url)
|
|
9
|
+
.map((note, index) => {
|
|
10
|
+
const { message } = note;
|
|
11
|
+
return {
|
|
12
|
+
label: message,
|
|
13
|
+
value: index.toString(),
|
|
14
|
+
data: note,
|
|
15
|
+
quantity: 1,
|
|
16
|
+
};
|
|
17
|
+
}) || [];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return modifierTags.concat(noteTags);
|
|
21
|
+
};
|
package/lib/modifier/index.js
CHANGED
|
@@ -129,6 +129,10 @@ const isFixedDiscount = require('./isFixedDiscount');
|
|
|
129
129
|
const removeLocked = require('./removeLocked');
|
|
130
130
|
const hasItems = require('./hasItems');
|
|
131
131
|
const getLockedModifiers = require('./getLockedModifiers');
|
|
132
|
+
const getGroupedModifiers = require('./getGroupedModifiers');
|
|
133
|
+
const getNotesToModifierTags = require('./getNotesToModifierTags');
|
|
134
|
+
const isOptionsOverride = require('./isOptionsOverride');
|
|
135
|
+
const getGroupedModifierLabels = require('./getGroupedModifierLabels');
|
|
132
136
|
|
|
133
137
|
const modifierActions = (deps = {}) => {
|
|
134
138
|
const actions = {};
|
|
@@ -269,6 +273,10 @@ const modifierActions = (deps = {}) => {
|
|
|
269
273
|
isFee: isFee(innerDeps),
|
|
270
274
|
isAdd: isAdd(innerDeps),
|
|
271
275
|
mutateModifier: mutateModifier(innerDeps),
|
|
276
|
+
getGroupedModifiers: getGroupedModifiers(innerDeps),
|
|
277
|
+
getNotesToModifierTags: getNotesToModifierTags(innerDeps),
|
|
278
|
+
isOptionsOverride: isOptionsOverride(innerDeps),
|
|
279
|
+
getGroupedModifierLabels: getGroupedModifierLabels(innerDeps),
|
|
272
280
|
});
|
|
273
281
|
|
|
274
282
|
Object.keys(freezedActions).forEach(actionName => {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
module.exports = () =>
|
|
2
|
+
function isOptionsOverride(modifier) {
|
|
3
|
+
if (!modifier || !modifier.properties || !modifier.properties.override)
|
|
4
|
+
return false;
|
|
5
|
+
return (
|
|
6
|
+
modifier.properties.override.options &&
|
|
7
|
+
modifier.properties.override.options.length > 0
|
|
8
|
+
);
|
|
9
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module.exports = ({ actions }) =>
|
|
2
|
+
function createSuborder(order) {
|
|
3
|
+
const create = actions.getSuborder({ order });
|
|
4
|
+
let subOrders = order.orders || [];
|
|
5
|
+
const newSubOrders = [create(order.items, 1)];
|
|
6
|
+
subOrders = [...subOrders, ...newSubOrders].map((subOrder, idx) => ({
|
|
7
|
+
...subOrder,
|
|
8
|
+
displayId: `${order.displayId}-${idx + 1}`,
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
subOrders = actions.spreadModifiers({
|
|
12
|
+
parentOrder: order,
|
|
13
|
+
subOrders,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return subOrders;
|
|
17
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module.exports = ({ utils, _, settings }) => {
|
|
2
|
+
const orderSettings = _.get(settings, 'order');
|
|
3
|
+
const { date, helpers } = utils;
|
|
4
|
+
const noteDefaults = {
|
|
5
|
+
message: '',
|
|
6
|
+
attributes: [],
|
|
7
|
+
date: date.toISOString(),
|
|
8
|
+
user: null,
|
|
9
|
+
url: '',
|
|
10
|
+
__typename: 'Note',
|
|
11
|
+
};
|
|
12
|
+
const getSubOrder =
|
|
13
|
+
({ order }) =>
|
|
14
|
+
(items, index) => {
|
|
15
|
+
let displayId = '';
|
|
16
|
+
if (orderSettings.allowSuborder)
|
|
17
|
+
displayId = `${order.displayId}-${index}`;
|
|
18
|
+
else if (index === 1) displayId = order.displayId;
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
...order,
|
|
22
|
+
_id: helpers.getObjectID(),
|
|
23
|
+
displayId,
|
|
24
|
+
discount: 0,
|
|
25
|
+
tax: 0,
|
|
26
|
+
totalPaid: 0,
|
|
27
|
+
total: 0,
|
|
28
|
+
status: {
|
|
29
|
+
order: 'open',
|
|
30
|
+
delivery: order.status.delivery,
|
|
31
|
+
detailed: order.status.detailed,
|
|
32
|
+
fullyPaid: false,
|
|
33
|
+
fullyPicked: false,
|
|
34
|
+
},
|
|
35
|
+
parentId: orderSettings.allowSuborder ? order._id : null,
|
|
36
|
+
items,
|
|
37
|
+
modifiers: [],
|
|
38
|
+
notes: [
|
|
39
|
+
...(order.notes || []),
|
|
40
|
+
{
|
|
41
|
+
...noteDefaults,
|
|
42
|
+
message: `Suborder from ${order.displayId}`, // ask about this message
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
return getSubOrder;
|
|
49
|
+
};
|
package/lib/order/index.js
CHANGED
|
@@ -86,6 +86,8 @@ const validateFixedModifiersTotal = require('./validateFixedModifiersTotal');
|
|
|
86
86
|
const markModifiersAsLocked = require('./markModifiersAsLocked');
|
|
87
87
|
const removeModifiers = require('./removeModifiers');
|
|
88
88
|
const addModifiers = require('./addModifiers');
|
|
89
|
+
const createSuborder = require('./createSuborder');
|
|
90
|
+
const getSuborder = require('./getSuborder');
|
|
89
91
|
|
|
90
92
|
const orderActions = (deps = {}) => {
|
|
91
93
|
const actions = {};
|
|
@@ -184,6 +186,8 @@ const orderActions = (deps = {}) => {
|
|
|
184
186
|
markModifiersAsLocked: markModifiersAsLocked(innerDeps),
|
|
185
187
|
removeModifiers: removeModifiers(innerDeps),
|
|
186
188
|
addModifiers: addModifiers(innerDeps),
|
|
189
|
+
createSuborder: createSuborder(innerDeps),
|
|
190
|
+
getSuborder: getSuborder(innerDeps),
|
|
187
191
|
});
|
|
188
192
|
|
|
189
193
|
Object.keys(freezedActions).forEach(actionName => {
|
package/lib/order/pickEndDate.js
CHANGED
|
@@ -23,42 +23,39 @@ module.exports = ({ settings, _, moment }) => {
|
|
|
23
23
|
|
|
24
24
|
const todayTZ = moment().tz(timezone);
|
|
25
25
|
let endDateTZ = todayTZ.clone();
|
|
26
|
-
|
|
27
26
|
const closedDays = getClosedDays();
|
|
28
|
-
|
|
27
|
+
const todayHours = todayTZ.get('hours');
|
|
28
|
+
const todayMinutes = todayTZ.get('minutes');
|
|
29
29
|
if (
|
|
30
|
-
(cutHour &&
|
|
31
|
-
(
|
|
32
|
-
todayTZ.get('minutes') > cutHour.minute)
|
|
30
|
+
(cutHour && todayHours > cutHour.hour) ||
|
|
31
|
+
(todayHours >= cutHour.hour && todayMinutes > cutHour.minute)
|
|
33
32
|
) {
|
|
34
|
-
endDateTZ = endDateTZ.add(cutDay, 'days');
|
|
33
|
+
endDateTZ = endDateTZ.add(cutDay, 'days'); // if the cut day is zero should we add a day based on hours? ask Nabil/Vicky
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// is endDateISOWeekday a sunday?
|
|
45
|
-
const shouldSkip =
|
|
46
|
-
skipDays.includes(endDateISOWeekday) || endDateISOWeekday === 7;
|
|
47
|
-
// if addDaysCounter is greater than loop, than we shouldn't add more days
|
|
48
|
-
// day condition stays working until addDaysCounter is greater than loop
|
|
49
|
-
if (
|
|
50
|
-
!shouldSkip ||
|
|
51
|
-
// eslint-disable-next-line no-loop-func
|
|
52
|
-
!closedDays.some(closedDay => closedDay.date.isSame(endDateTZ, 'day'))
|
|
53
|
-
) {
|
|
54
|
-
// eslint-disable-next-line no-plusplus
|
|
55
|
-
addDaysCounter++;
|
|
36
|
+
endDateTZ.add(addDays, 'days');
|
|
37
|
+
// do the logic related to skipdays
|
|
38
|
+
// if the date already pass the skip day, do nothing
|
|
39
|
+
// if the date is the same as one of the skip day, check the next skip day if any, then add one more day
|
|
40
|
+
skipDays.forEach(day => {
|
|
41
|
+
if (todayTZ.isoWeekday() <= day) {
|
|
42
|
+
endDateTZ.add(1, 'days');
|
|
56
43
|
}
|
|
57
|
-
}
|
|
44
|
+
});
|
|
58
45
|
|
|
46
|
+
/**
|
|
47
|
+
* setting the hour and minute so we can compare with closedDays
|
|
48
|
+
*/
|
|
59
49
|
if (hour !== undefined) endDateTZ.set('hour', hour);
|
|
60
50
|
if (minute !== undefined) endDateTZ.set('minute', minute);
|
|
61
|
-
|
|
51
|
+
closedDays.forEach(closed => {
|
|
52
|
+
const closedDay = moment(closed.date);
|
|
53
|
+
closedDay.set('hour', hour);
|
|
54
|
+
closedDay.set('minute', minute);
|
|
55
|
+
if (endDateTZ.startOf('day').isSame(closedDay, 'day')) {
|
|
56
|
+
endDateTZ.add(1, 'days');
|
|
57
|
+
}
|
|
58
|
+
});
|
|
62
59
|
|
|
63
60
|
return moment.utc(endDateTZ).format();
|
|
64
61
|
};
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
module.exports = ({ utils, _, itemActions, modifierActions
|
|
2
|
-
const
|
|
3
|
-
const { date, helpers } = utils;
|
|
4
|
-
const noteDefaults = {
|
|
5
|
-
message: '',
|
|
6
|
-
attributes: [],
|
|
7
|
-
date: date.toISOString(),
|
|
8
|
-
user: null,
|
|
9
|
-
url: '',
|
|
10
|
-
__typename: 'Note',
|
|
11
|
-
};
|
|
1
|
+
module.exports = ({ utils, _, actions, itemActions, modifierActions }) => {
|
|
2
|
+
const { helpers } = utils;
|
|
12
3
|
|
|
13
4
|
const joinItemQuantity = orders =>
|
|
14
5
|
orders.map(order => {
|
|
@@ -39,42 +30,6 @@ module.exports = ({ utils, _, itemActions, modifierActions, settings }) => {
|
|
|
39
30
|
return { ...order, items };
|
|
40
31
|
});
|
|
41
32
|
|
|
42
|
-
const getOrder =
|
|
43
|
-
({ order, name }) =>
|
|
44
|
-
(items, index) => {
|
|
45
|
-
let displayId = '';
|
|
46
|
-
if (orderSettings.allowSuborder)
|
|
47
|
-
displayId = `${order.displayId}-${index}`;
|
|
48
|
-
else if (index === 1) displayId = order.displayId;
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
...order,
|
|
52
|
-
_id: helpers.getObjectID(),
|
|
53
|
-
displayId,
|
|
54
|
-
discount: 0,
|
|
55
|
-
tax: 0,
|
|
56
|
-
totalPaid: 0,
|
|
57
|
-
total: 0,
|
|
58
|
-
status: {
|
|
59
|
-
order: 'open',
|
|
60
|
-
delivery: order.status.delivery,
|
|
61
|
-
detailed: order.status.detailed,
|
|
62
|
-
fullyPaid: false,
|
|
63
|
-
fullyPicked: false,
|
|
64
|
-
},
|
|
65
|
-
parentId: orderSettings.allowSuborder ? order._id : null,
|
|
66
|
-
items,
|
|
67
|
-
modifiers: [],
|
|
68
|
-
notes: [
|
|
69
|
-
...(order.notes || []),
|
|
70
|
-
{
|
|
71
|
-
...noteDefaults,
|
|
72
|
-
message: `Split from ${order.displayId}, for department ${name}`,
|
|
73
|
-
},
|
|
74
|
-
],
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
|
|
78
33
|
const getDepartmentName = item => {
|
|
79
34
|
const deps = itemActions.getDepartmentModifiers(item);
|
|
80
35
|
return (deps.length && deps[0].name) || 'other';
|
|
@@ -91,7 +46,7 @@ module.exports = ({ utils, _, itemActions, modifierActions, settings }) => {
|
|
|
91
46
|
|
|
92
47
|
orders.forEach(each => {
|
|
93
48
|
const [name, newItems] = each;
|
|
94
|
-
const create =
|
|
49
|
+
const create = actions.getSuborder({ order, name });
|
|
95
50
|
// Assuming there is one department in the item
|
|
96
51
|
const department = itemActions.getDepartmentModifiers(newItems[0])[0];
|
|
97
52
|
const departmentName = getDepartmentName(newItems[0]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.43",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"supertest": "^6.2.3",
|
|
37
37
|
"supervisor": "^0.12.0"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "60a1eef3eb458c750cda95b701904c8ea7e68157"
|
|
40
40
|
}
|