@darkpos/pricing 1.0.51 → 1.0.53
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 → getModifierTags.test.js} +35 -24
- package/__TEST__/item/getNoteTags.test.js +52 -0
- package/__TEST__/item.test.js +293 -0
- package/__TEST__/mocks/addItemMock.js +1 -1
- package/__TEST__/modifier/hasModifier.test.js +1 -1
- package/__TEST__/order/order-payment-modifier.test.js +12 -12
- package/__TEST__/order/order.test.js +44 -3
- package/lib/item/calculate.js +24 -5
- package/lib/item/getBasePrice.js +7 -0
- package/lib/item/getModifierTags.js +45 -0
- package/lib/{modifier/getNotesToModifierTags.js → item/getNoteTags.js} +2 -2
- package/lib/item/index.js +6 -2
- package/lib/item/removeModifier.js +3 -8
- package/lib/modifier/calculate.js +38 -5
- package/lib/modifier/index.js +2 -4
- package/lib/modifier/isGroup.js +1 -6
- package/lib/modifier/isOptionsSelectedOverride.js +7 -0
- package/lib/order/addItemModifier.js +15 -3
- package/lib/order/calculate.js +62 -59
- package/package.json +3 -2
- package/__TEST__/modifier/getNotesToModifierTags.test.js +0 -78
- package/__TEST__/modifier/isComputedOverride.test.js +0 -38
- package/lib/item/getItemModifiersDescription.js +0 -56
- package/lib/modifier/isComputedOverride.js +0 -8
package/lib/item/calculate.js
CHANGED
|
@@ -85,7 +85,14 @@ module.exports = ({ _, utils, actions, modifierActions }) => {
|
|
|
85
85
|
ceach => ceach.modifierId === each.modifierId
|
|
86
86
|
)
|
|
87
87
|
)
|
|
88
|
-
.map(each =>
|
|
88
|
+
.map(each =>
|
|
89
|
+
modifierActions.calculate(each, {
|
|
90
|
+
price,
|
|
91
|
+
quantity,
|
|
92
|
+
skip: true,
|
|
93
|
+
basePrice: actions.getBasePrice(item),
|
|
94
|
+
})
|
|
95
|
+
);
|
|
89
96
|
|
|
90
97
|
if (modifiersToCompute.length || paymentModifiersToCompute.length) {
|
|
91
98
|
// sort modifiers based on sort
|
|
@@ -130,6 +137,7 @@ module.exports = ({ _, utils, actions, modifierActions }) => {
|
|
|
130
137
|
{
|
|
131
138
|
price: computedPrice,
|
|
132
139
|
quantity,
|
|
140
|
+
basePrice: actions.getBasePrice(item),
|
|
133
141
|
}
|
|
134
142
|
);
|
|
135
143
|
|
|
@@ -147,11 +155,22 @@ module.exports = ({ _, utils, actions, modifierActions }) => {
|
|
|
147
155
|
|
|
148
156
|
// adding this computeField because now the compute from a modifier can be null
|
|
149
157
|
const computeField = getComputeModField(_modifier);
|
|
158
|
+
|
|
159
|
+
const isPercentage = computeField.type === 'percentage';
|
|
160
|
+
const isIgnoreQuantity = modifierActions.isIgnoreQuantity(_modifier);
|
|
161
|
+
const isNotFixedAddAndAmountGtPrice =
|
|
162
|
+
!modifierActions.isFixedAdd(_modifier) &&
|
|
163
|
+
math.gt(math.abs(computedAmountCalc), computedPriceCalc);
|
|
164
|
+
|
|
165
|
+
const isAmountOverrideAndNotMultiplier =
|
|
166
|
+
modifierActions.isAmountOverride(_modifier) &&
|
|
167
|
+
!modifierActions.isMultiplier(_modifier);
|
|
168
|
+
|
|
150
169
|
let computedAmount =
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
170
|
+
isPercentage ||
|
|
171
|
+
isIgnoreQuantity ||
|
|
172
|
+
isNotFixedAddAndAmountGtPrice ||
|
|
173
|
+
isAmountOverrideAndNotMultiplier
|
|
155
174
|
? _computed.amount
|
|
156
175
|
: computedAmountCalc;
|
|
157
176
|
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module.exports = ({ modifierActions, settings }) =>
|
|
2
|
+
function getModifierTags({ item, skipGrouping = false }) {
|
|
3
|
+
const groupModifiers =
|
|
4
|
+
settings && settings.order && settings.order.groupModifiers;
|
|
5
|
+
|
|
6
|
+
if (!item || !Array.isArray(item.modifiers)) return [];
|
|
7
|
+
|
|
8
|
+
let modifierTags = item.modifiers
|
|
9
|
+
.filter(
|
|
10
|
+
each => modifierActions.isValid(each) && !modifierActions.isGroup(each)
|
|
11
|
+
)
|
|
12
|
+
.map(modifier => {
|
|
13
|
+
const { name, _id } = modifier;
|
|
14
|
+
|
|
15
|
+
let label = name;
|
|
16
|
+
|
|
17
|
+
if (modifierActions.isGroupOfValues(modifier)) {
|
|
18
|
+
label = modifierActions.getSelectedValues(modifier) || label;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (
|
|
22
|
+
modifier &&
|
|
23
|
+
!modifier.included &&
|
|
24
|
+
modifier._computed &&
|
|
25
|
+
modifier._computed.description
|
|
26
|
+
) {
|
|
27
|
+
label = modifier._computed.description;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const modifierValue = {
|
|
31
|
+
label,
|
|
32
|
+
value: _id,
|
|
33
|
+
data: modifier,
|
|
34
|
+
quantity: 1,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return modifierValue;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (groupModifiers && !skipGrouping) {
|
|
41
|
+
modifierTags = modifierActions.getGroupedModifiers(modifierTags);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return modifierTags;
|
|
45
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module.exports = () =>
|
|
2
|
-
function
|
|
2
|
+
function getNoteTags({ notes }) {
|
|
3
3
|
let noteTags = [];
|
|
4
4
|
if (notes && notes.length > 0) {
|
|
5
5
|
noteTags =
|
|
@@ -17,5 +17,5 @@ module.exports = () =>
|
|
|
17
17
|
}) || [];
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
return
|
|
20
|
+
return noteTags;
|
|
21
21
|
};
|
package/lib/item/index.js
CHANGED
|
@@ -23,7 +23,7 @@ const getItemsTotals = require('./getItemsTotals');
|
|
|
23
23
|
const getNotIncludedModifiers = require('./getNotIncludedModifiers');
|
|
24
24
|
const hasModifierWithValue = require('./hasModifierWithValue');
|
|
25
25
|
const getItemsTotalPaid = require('./getItemsTotalPaid');
|
|
26
|
-
const
|
|
26
|
+
const getModifierTags = require('./getModifierTags');
|
|
27
27
|
const isRelatedItem = require('./isRelatedItem');
|
|
28
28
|
const getParentItem = require('./getParentItem');
|
|
29
29
|
const isParentIncluded = require('./isParentIncluded');
|
|
@@ -44,6 +44,8 @@ const getInvalidRequiredModifiers = require('./getInvalidRequiredModifiers');
|
|
|
44
44
|
const getPriceWithoutModifiers = require('./getPriceWithoutModifiers');
|
|
45
45
|
const getTotalsDifference = require('./getTotalsDifference');
|
|
46
46
|
const getTotalNeareastDifference = require('./getTotalNeareastDifference');
|
|
47
|
+
const getNoteTags = require('./getNoteTags');
|
|
48
|
+
const getBasePrice = require('./getBasePrice');
|
|
47
49
|
|
|
48
50
|
const itemActions = (deps = {}) => {
|
|
49
51
|
const actions = {};
|
|
@@ -79,7 +81,7 @@ const itemActions = (deps = {}) => {
|
|
|
79
81
|
getNotIncludedModifiers: getNotIncludedModifiers(innerDeps),
|
|
80
82
|
hasModifierWithValue: hasModifierWithValue(innerDeps),
|
|
81
83
|
getItemsTotalPaid: getItemsTotalPaid(innerDeps),
|
|
82
|
-
|
|
84
|
+
getModifierTags: getModifierTags(innerDeps),
|
|
83
85
|
isRelatedItem: isRelatedItem(innerDeps),
|
|
84
86
|
getParentItem: getParentItem(innerDeps),
|
|
85
87
|
isParentIncluded: isParentIncluded(innerDeps),
|
|
@@ -101,6 +103,8 @@ const itemActions = (deps = {}) => {
|
|
|
101
103
|
getPriceWithoutModifiers: getPriceWithoutModifiers(innerDeps),
|
|
102
104
|
getTotalsDifference: getTotalsDifference(innerDeps),
|
|
103
105
|
getTotalNeareastDifference: getTotalNeareastDifference(innerDeps),
|
|
106
|
+
getNoteTags: getNoteTags(innerDeps),
|
|
107
|
+
getBasePrice: getBasePrice(innerDeps),
|
|
104
108
|
});
|
|
105
109
|
|
|
106
110
|
Object.keys(freezedActions).forEach(actionName => {
|
|
@@ -56,10 +56,8 @@ module.exports = ({ modifierActions, _, actions }) => {
|
|
|
56
56
|
)
|
|
57
57
|
);
|
|
58
58
|
|
|
59
|
-
const hasOverride = modifiersToApply.find(
|
|
60
|
-
each
|
|
61
|
-
modifierActions.isOverride(each) ||
|
|
62
|
-
modifierActions.isComputedOverride(each)
|
|
59
|
+
const hasOverride = modifiersToApply.find(each =>
|
|
60
|
+
modifierActions.isOverride(each)
|
|
63
61
|
);
|
|
64
62
|
|
|
65
63
|
if (hasOverride) {
|
|
@@ -68,10 +66,7 @@ module.exports = ({ modifierActions, _, actions }) => {
|
|
|
68
66
|
|
|
69
67
|
if (modifierActions.isQuantityOverride(modifier)) nextItem.quantity = 1;
|
|
70
68
|
|
|
71
|
-
if (
|
|
72
|
-
modifierActions.isPriceOverride(modifier) ||
|
|
73
|
-
modifierActions.isComputedOverride(modifier)
|
|
74
|
-
)
|
|
69
|
+
if (modifierActions.isPriceOverride(modifier))
|
|
75
70
|
nextItem.price = actions.getItemPrice({
|
|
76
71
|
item: originalItem,
|
|
77
72
|
cache,
|
|
@@ -9,7 +9,7 @@ module.exports = ({ _, constants, utils, localization, actions }) => {
|
|
|
9
9
|
|
|
10
10
|
return function calculate(
|
|
11
11
|
_modifier = {},
|
|
12
|
-
options = { price: 0, quantity: 0, skip: false }
|
|
12
|
+
options = { price: 0, quantity: 0, skip: false, basePrice: 0 }
|
|
13
13
|
) {
|
|
14
14
|
const modifier = _modifier;
|
|
15
15
|
const { name } = modifier;
|
|
@@ -43,16 +43,49 @@ module.exports = ({ _, constants, utils, localization, actions }) => {
|
|
|
43
43
|
100
|
|
44
44
|
);
|
|
45
45
|
|
|
46
|
-
if (!type
|
|
47
|
-
_computed.amount = 0;
|
|
46
|
+
if (!type) _computed.amount = 0;
|
|
48
47
|
|
|
49
48
|
if (math.gt(math.abs(_computed.amount), maxAmount)) {
|
|
50
49
|
_computed.amount = maxAmount * multiplier;
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
const localAmount =
|
|
55
|
-
|
|
53
|
+
const localAmount =
|
|
54
|
+
!!_computed.amount && Number(_computed.amount) !== 0
|
|
55
|
+
? `${localization.formatAmount(_computed.amount)}`
|
|
56
|
+
: '';
|
|
57
|
+
|
|
58
|
+
const localBasePrice = localization.formatAmount(
|
|
59
|
+
options.basePrice || options.price || 0
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const isMultiplier = actions.isMultiplier(modifier);
|
|
63
|
+
|
|
64
|
+
_computed.description = `${name}${localAmount ? ` (${localAmount})` : ''}`;
|
|
65
|
+
|
|
66
|
+
if (actions.isPriceOverride(modifier)) {
|
|
67
|
+
_computed.description = isMultiplier
|
|
68
|
+
? `${name} (${compute.amount} Unit @ ${localBasePrice}/Unit)`
|
|
69
|
+
: `${name} (${localization.formatAmount(compute.amount)}/Unit)`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (actions.isAmountOverride(modifier) && isMultiplier) {
|
|
73
|
+
_computed.description = `${name} (${localization.formatAmount(
|
|
74
|
+
math.mul(_computed.amount, options.quantity)
|
|
75
|
+
)})`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (actions.isOptionsSelectedOverride(modifier)) {
|
|
79
|
+
const selectedOverrideOptions = _.get(
|
|
80
|
+
modifier,
|
|
81
|
+
'properties.override.selected'
|
|
82
|
+
);
|
|
83
|
+
_computed.description = isMultiplier
|
|
84
|
+
? `${name} (${compute.amount} Unit @ ${localBasePrice}/${selectedOverrideOptions.selectedUnit})`
|
|
85
|
+
: `${name} (${localization.formatAmount(compute.amount)}/${
|
|
86
|
+
selectedOverrideOptions.selectedUnit
|
|
87
|
+
})`;
|
|
88
|
+
}
|
|
56
89
|
|
|
57
90
|
return { ..._.cloneDeep(modifier), _computed };
|
|
58
91
|
};
|
package/lib/modifier/index.js
CHANGED
|
@@ -89,7 +89,6 @@ const isService = require('./isService');
|
|
|
89
89
|
const isSingleValue = require('./isSingleValue');
|
|
90
90
|
const isGroupOfItems = require('./isGroupOfItems');
|
|
91
91
|
const isOverride = require('./isOverride');
|
|
92
|
-
const isComputedOverride = require('./isComputedOverride');
|
|
93
92
|
const isDepartment = require('./isDepartment');
|
|
94
93
|
const isRequired = require('./isRequired');
|
|
95
94
|
const isMultiplier = require('./isMultiplier');
|
|
@@ -129,7 +128,6 @@ const hasItems = require('./hasItems');
|
|
|
129
128
|
const removeGroupData = require('./removeGroupData');
|
|
130
129
|
const isRelatedModifier = require('./isRelatedModifier');
|
|
131
130
|
const getGroupedModifiers = require('./getGroupedModifiers');
|
|
132
|
-
const getNotesToModifierTags = require('./getNotesToModifierTags');
|
|
133
131
|
const isOptionsOverride = require('./isOptionsOverride');
|
|
134
132
|
const getGroupedModifierLabels = require('./getGroupedModifierLabels');
|
|
135
133
|
const validate = require('./validate');
|
|
@@ -149,6 +147,7 @@ const isChild = require('./isChild');
|
|
|
149
147
|
const isExtractCalculatedValue = require('./isExtractCalculatedValue');
|
|
150
148
|
const getPriceWithoutModifier = require('./getPriceWithoutModifier');
|
|
151
149
|
const isGroup = require('./isGroup');
|
|
150
|
+
const isOptionsSelectedOverride = require('./isOptionsSelectedOverride');
|
|
152
151
|
|
|
153
152
|
const modifierActions = (deps = {}) => {
|
|
154
153
|
const actions = {};
|
|
@@ -250,7 +249,6 @@ const modifierActions = (deps = {}) => {
|
|
|
250
249
|
isSingleValue: isSingleValue(innerDeps),
|
|
251
250
|
isGroupOfItems: isGroupOfItems(innerDeps),
|
|
252
251
|
isOverride: isOverride(innerDeps),
|
|
253
|
-
isComputedOverride: isComputedOverride(innerDeps),
|
|
254
252
|
isDepartment: isDepartment(innerDeps),
|
|
255
253
|
isRequired: isRequired(innerDeps),
|
|
256
254
|
isMultiplier: isMultiplier(innerDeps),
|
|
@@ -289,7 +287,6 @@ const modifierActions = (deps = {}) => {
|
|
|
289
287
|
removeGroupData: removeGroupData(innerDeps),
|
|
290
288
|
isRelatedModifier: isRelatedModifier(innerDeps),
|
|
291
289
|
getGroupedModifiers: getGroupedModifiers(innerDeps),
|
|
292
|
-
getNotesToModifierTags: getNotesToModifierTags(innerDeps),
|
|
293
290
|
isOptionsOverride: isOptionsOverride(innerDeps),
|
|
294
291
|
getGroupedModifierLabels: getGroupedModifierLabels(innerDeps),
|
|
295
292
|
validate: validate(innerDeps),
|
|
@@ -311,6 +308,7 @@ const modifierActions = (deps = {}) => {
|
|
|
311
308
|
isExtractCalculatedValue: isExtractCalculatedValue(innerDeps),
|
|
312
309
|
getPriceWithoutModifier: getPriceWithoutModifier(innerDeps),
|
|
313
310
|
isGroup: isGroup(innerDeps),
|
|
311
|
+
isOptionsSelectedOverride: isOptionsSelectedOverride(innerDeps),
|
|
314
312
|
});
|
|
315
313
|
|
|
316
314
|
Object.keys(freezedActions).forEach(actionName => {
|
package/lib/modifier/isGroup.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
module.exports = ({ actions }) =>
|
|
2
2
|
function isGroup(modifier) {
|
|
3
3
|
if (!modifier) return false;
|
|
4
|
-
return !!(
|
|
5
|
-
actions.hasAttribute(modifier, 'group') ||
|
|
6
|
-
(modifier.properties &&
|
|
7
|
-
modifier.properties.group &&
|
|
8
|
-
Object.keys(modifier.properties.group) > 0)
|
|
9
|
-
);
|
|
4
|
+
return !!actions.hasAttribute(modifier, 'group');
|
|
10
5
|
};
|
|
@@ -143,13 +143,25 @@ module.exports = ({ actions, itemActions, modifierActions, utils, _ }) => {
|
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
if (modifierActions.isQuantityOverride(modifier)
|
|
147
|
-
|
|
146
|
+
if (modifierActions.isQuantityOverride(modifier)) {
|
|
147
|
+
if (modifier.compute && typeof modifier.compute.amount === 'number') {
|
|
148
|
+
item.quantity = modifier.compute.amount || 1;
|
|
149
|
+
} else if (typeof modifier.properties.override.fixedValue === 'number') {
|
|
150
|
+
item.quantity = modifier.properties.override.fixedValue;
|
|
151
|
+
}
|
|
148
152
|
}
|
|
149
153
|
|
|
150
|
-
if (isPriceOverride
|
|
154
|
+
if (isPriceOverride) {
|
|
155
|
+
item.properties = {
|
|
156
|
+
...(item.properties || {}),
|
|
157
|
+
basePrice: item.price,
|
|
158
|
+
};
|
|
151
159
|
item.price = getPrice({ modifier: modifierToAdd, item });
|
|
152
160
|
} else {
|
|
161
|
+
item.properties = {
|
|
162
|
+
...(item.properties || {}),
|
|
163
|
+
basePrice: item.price,
|
|
164
|
+
};
|
|
153
165
|
item.price = itemActions.getItemPrice({
|
|
154
166
|
item,
|
|
155
167
|
cache,
|
package/lib/order/calculate.js
CHANGED
|
@@ -40,89 +40,92 @@ module.exports = ({
|
|
|
40
40
|
),
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
+
let calculatedItems = itemsWNIM || [];
|
|
44
|
+
|
|
43
45
|
const newOrder = {
|
|
44
46
|
...order,
|
|
45
47
|
...itemActions.getItemsTotals(itemsWNIM),
|
|
46
48
|
items: itemsWNIM,
|
|
47
49
|
};
|
|
48
50
|
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
51
|
+
if (sortedOrderModifiers.length > 0) {
|
|
52
|
+
itemsWNIM = itemActions.calculate(itemsWNIM, {});
|
|
53
|
+
|
|
54
|
+
let tempItems = itemsWNIM || items;
|
|
55
|
+
let itemsWIM = _.cloneDeep(tempItems);
|
|
56
|
+
let prvSort = null;
|
|
57
|
+
|
|
58
|
+
let computedTotal = newOrder.total;
|
|
59
|
+
|
|
60
|
+
for (const modifier of sortedOrderModifiers) {
|
|
61
|
+
const isCredit = modifierActions.isCredit(modifier);
|
|
62
|
+
const sort = modifierActions.getProperty(modifier, 'sort');
|
|
63
|
+
|
|
64
|
+
if (prvSort !== sort) {
|
|
65
|
+
if (sort) {
|
|
66
|
+
tempItems = itemsWIM.map(item => ({
|
|
67
|
+
...item,
|
|
68
|
+
modifiers: modifierActions.getModifiersByMaxSort(
|
|
69
|
+
item.modifiers,
|
|
70
|
+
modifier.properties.sort
|
|
71
|
+
),
|
|
72
|
+
}));
|
|
73
|
+
} else {
|
|
74
|
+
tempItems = itemsWIM;
|
|
75
|
+
}
|
|
76
|
+
tempItems = itemActions.calculate(tempItems, options);
|
|
77
|
+
}
|
|
62
78
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
...item,
|
|
67
|
-
modifiers: modifierActions.getModifiersByMaxSort(
|
|
68
|
-
item.modifiers,
|
|
69
|
-
modifier.properties.sort
|
|
70
|
-
),
|
|
71
|
-
}));
|
|
72
|
-
} else {
|
|
73
|
-
tempItems = itemsWIM;
|
|
79
|
+
if (isCredit) {
|
|
80
|
+
const calculatedItemWIM = itemActions.calculate(itemsWIM, options);
|
|
81
|
+
computedTotal = itemActions.getItemsTotals(calculatedItemWIM).total;
|
|
74
82
|
}
|
|
75
|
-
tempItems = itemActions.calculate(tempItems, options);
|
|
76
|
-
}
|
|
77
83
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
84
|
+
if (modifierActions.hasItems({ modifier })) {
|
|
85
|
+
tempItems = itemActions.getItems(tempItems, modifier.items);
|
|
86
|
+
}
|
|
82
87
|
|
|
83
|
-
|
|
84
|
-
|
|
88
|
+
computedTotal = itemActions.getItemsTotals(tempItems).total;
|
|
89
|
+
|
|
90
|
+
const itemsModifiers = itemActions.addIndirectModifier({
|
|
91
|
+
orderTotal: computedTotal,
|
|
92
|
+
items: tempItems,
|
|
93
|
+
modifier,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// adding the modifiers to items
|
|
97
|
+
itemsWIM = itemsWIM.map(item => ({
|
|
98
|
+
...item,
|
|
99
|
+
modifiers: [
|
|
100
|
+
...(item.modifiers || []),
|
|
101
|
+
itemsModifiers[item._id],
|
|
102
|
+
].filter(Boolean),
|
|
103
|
+
}));
|
|
104
|
+
prvSort = sort;
|
|
85
105
|
}
|
|
86
106
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const itemsModifiers = itemActions.addIndirectModifier({
|
|
90
|
-
orderTotal: computedTotal,
|
|
91
|
-
items: tempItems,
|
|
92
|
-
modifier,
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// adding the modifiers to items
|
|
96
|
-
itemsWIM = itemsWIM.map(item => ({
|
|
97
|
-
...item,
|
|
98
|
-
modifiers: [...(item.modifiers || []), itemsModifiers[item._id]].filter(
|
|
99
|
-
Boolean
|
|
100
|
-
),
|
|
101
|
-
}));
|
|
102
|
-
prvSort = sort;
|
|
107
|
+
calculatedItems = itemActions.calculate(itemsWIM, options);
|
|
103
108
|
}
|
|
104
109
|
|
|
105
|
-
const calculatedItemWIM = itemActions.calculate(itemsWIM, options);
|
|
106
|
-
|
|
107
110
|
const addToItemTotal = difference => {
|
|
108
|
-
if (difference > 0 &&
|
|
109
|
-
|
|
110
|
-
utils.math.add(
|
|
111
|
+
if (difference > 0 && calculatedItems.length) {
|
|
112
|
+
calculatedItems[0].total = utils.math.toDecimalPlaces(
|
|
113
|
+
utils.math.add(calculatedItems[0].total, difference)
|
|
111
114
|
);
|
|
112
115
|
}
|
|
113
116
|
};
|
|
114
117
|
|
|
115
|
-
if (
|
|
118
|
+
if (calculatedItems.length > 1) {
|
|
116
119
|
const difference = itemActions.getTotalsDifference({
|
|
117
|
-
items:
|
|
120
|
+
items: calculatedItems,
|
|
118
121
|
});
|
|
119
122
|
|
|
120
123
|
addToItemTotal(difference);
|
|
121
124
|
}
|
|
122
125
|
|
|
123
|
-
if (storeActions.isNeareastMultiple() &&
|
|
126
|
+
if (storeActions.isNeareastMultiple() && calculatedItems.length > 0) {
|
|
124
127
|
const difference = itemActions.getTotalNeareastDifference({
|
|
125
|
-
items:
|
|
128
|
+
items: calculatedItems,
|
|
126
129
|
});
|
|
127
130
|
|
|
128
131
|
if (difference > 0) addToItemTotal(difference);
|
|
@@ -130,7 +133,7 @@ module.exports = ({
|
|
|
130
133
|
|
|
131
134
|
return {
|
|
132
135
|
...order,
|
|
133
|
-
...itemActions.getItemsTotals(
|
|
134
|
-
items:
|
|
136
|
+
...itemActions.getItemsTotals(calculatedItems),
|
|
137
|
+
items: calculatedItems,
|
|
135
138
|
};
|
|
136
139
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.53",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -18,6 +18,7 @@
|
|
|
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
20
|
"test:split": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/order/split.test.js",
|
|
21
|
+
"test:getModifierTags": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/item/getModifierTags.test.js",
|
|
21
22
|
"lint": "eslint --quiet lib/"
|
|
22
23
|
},
|
|
23
24
|
"publishConfig": {
|
|
@@ -41,5 +42,5 @@
|
|
|
41
42
|
"supertest": "^6.2.3",
|
|
42
43
|
"supervisor": "^0.12.0"
|
|
43
44
|
},
|
|
44
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "ad5528b8430430e2a34e124218dc4ac1d3da1681"
|
|
45
46
|
}
|
|
@@ -1,78 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
const isComputedOverrideFunction = require('../../lib/modifier/isComputedOverride');
|
|
2
|
-
|
|
3
|
-
describe('isComputedOverride Function', () => {
|
|
4
|
-
const Modifier = {
|
|
5
|
-
Attributes: {
|
|
6
|
-
OVERRIDE: 'override',
|
|
7
|
-
},
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const isComputedOverride = isComputedOverrideFunction({
|
|
11
|
-
constants: { Modifier },
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test('should return false if modifier is null or undefined', () => {
|
|
15
|
-
expect(isComputedOverride(null)).toBe(false);
|
|
16
|
-
expect(isComputedOverride(undefined)).toBe(false);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('should return false if modifier does not have compute property', () => {
|
|
20
|
-
const modifier = {};
|
|
21
|
-
expect(isComputedOverride(modifier)).toBe(false);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('should return false if compute does not have action property', () => {
|
|
25
|
-
const modifier = { compute: {} };
|
|
26
|
-
expect(isComputedOverride(modifier)).toBe(false);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('should return false if compute action is not OVERRIDE', () => {
|
|
30
|
-
const modifier = { compute: { action: 'other_action' } };
|
|
31
|
-
expect(isComputedOverride(modifier)).toBe(false);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('should return true if compute action is OVERRIDE', () => {
|
|
35
|
-
const modifier = { compute: { action: 'override' } };
|
|
36
|
-
expect(isComputedOverride(modifier)).toBe(true);
|
|
37
|
-
});
|
|
38
|
-
});
|