@darkpos/pricing 1.0.20 → 1.0.21
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/lib/order/addItem.js +105 -107
- package/lib/order/updateItemQuantity.js +5 -4
- package/package.json +2 -2
package/lib/order/addItem.js
CHANGED
|
@@ -126,125 +126,123 @@ module.exports = ({ actions, itemActions, modifierActions, settings, _ }) => {
|
|
|
126
126
|
|
|
127
127
|
// Default modifiers
|
|
128
128
|
if (idx === undefined && !_.isEmpty(item.modifiers))
|
|
129
|
-
modifiersToAdd.push(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (!_.isEmpty(modifiers)) modifiersToAdd.push(...modifiers);
|
|
129
|
+
modifiersToAdd.push(...item.modifiers.map(each => ({ ...each })));
|
|
130
|
+
|
|
131
|
+
const pendingItem = actions.getSelectedItem({ order, itemIndex });
|
|
132
|
+
|
|
133
|
+
if (pendingItem && pendingItem.isPending && !combined) {
|
|
134
|
+
idx = itemIndex;
|
|
135
|
+
combined = !!pendingItem.itemId;
|
|
136
|
+
orderItem.quantity = pendingItem.quantity;
|
|
137
|
+
orderItem.isPending = orderItem.isPending || !orderItem.itemId;
|
|
138
|
+
// add inventory
|
|
139
|
+
if (pendingItem.inventory) {
|
|
140
|
+
const inventory = getInventory(pendingItem);
|
|
141
|
+
if (inventory) {
|
|
142
|
+
orderItem.inventory = inventory;
|
|
143
|
+
if (inventory.serial) orderItem.serial = inventory.serial;
|
|
144
|
+
const modifiers = modifierActions.getEntityModifiers(inventory);
|
|
145
|
+
if (!_.isEmpty(modifiers)) modifiersToAdd.push(...modifiers);
|
|
146
|
+
}
|
|
148
147
|
}
|
|
149
148
|
}
|
|
150
|
-
}
|
|
151
149
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
150
|
+
if (overridenQuantity > -1) {
|
|
151
|
+
orderItem.quantity = overridenQuantity;
|
|
152
|
+
}
|
|
155
153
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
});
|
|
163
|
-
if (itemActions.isRelatedItem(orderItem)) {
|
|
164
|
-
const parent = itemActions.getParentItem(order.items, orderItem);
|
|
165
|
-
// get inherited modifiers
|
|
166
|
-
const inheritedModifiers = modifierActions.getInheritedModifiers({
|
|
167
|
-
parent,
|
|
168
|
-
child: item,
|
|
154
|
+
if (!combined) {
|
|
155
|
+
// add price
|
|
156
|
+
orderItem.price = itemActions.getItemPrice({
|
|
157
|
+
cache,
|
|
158
|
+
customer,
|
|
159
|
+
item: orderItem,
|
|
169
160
|
});
|
|
170
|
-
if (
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
161
|
+
if (itemActions.isRelatedItem(orderItem)) {
|
|
162
|
+
const parent = itemActions.getParentItem(order.items, orderItem);
|
|
163
|
+
// get inherited modifiers
|
|
164
|
+
const inheritedModifiers = modifierActions.getInheritedModifiers({
|
|
165
|
+
parent,
|
|
166
|
+
child: item,
|
|
167
|
+
});
|
|
168
|
+
if (!_.isEmpty(inheritedModifiers))
|
|
169
|
+
modifiersToAdd.push(...inheritedModifiers);
|
|
170
|
+
// Remove parent if it is only a repair Item
|
|
171
|
+
if (!itemActions.isParentIncluded(orderItem)) {
|
|
172
|
+
order = actions.removeItem({ order, item: parent, hard: false });
|
|
173
|
+
}
|
|
175
174
|
}
|
|
176
175
|
}
|
|
177
|
-
}
|
|
178
176
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
177
|
+
// add modifiers
|
|
178
|
+
let requiredModifiers = modifierActions.getItemModifiers({
|
|
179
|
+
modifiers: itemModifiers,
|
|
180
|
+
customer,
|
|
181
|
+
cache,
|
|
182
|
+
});
|
|
183
|
+
// Do not add again if they are already there
|
|
184
|
+
if (
|
|
185
|
+
!_.isEmpty(requiredModifiers) &&
|
|
186
|
+
combined &&
|
|
187
|
+
!_.isEmpty(orderItem.modifiers)
|
|
188
|
+
)
|
|
189
|
+
requiredModifiers = getUnselectedModifiers(orderItem, requiredModifiers);
|
|
190
|
+
if (!_.isEmpty(requiredModifiers)) {
|
|
191
|
+
modifiersToAdd.push(
|
|
192
|
+
...requiredModifiers.filter(
|
|
193
|
+
reqMod =>
|
|
194
|
+
!modifiersToAdd.find(
|
|
195
|
+
modToAdd => modToAdd.modifierId === reqMod.modifierId
|
|
196
|
+
)
|
|
197
|
+
)
|
|
198
|
+
);
|
|
199
|
+
}
|
|
202
200
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
201
|
+
orderItem = actions.getOrderItemSubscriptions({
|
|
202
|
+
order,
|
|
203
|
+
item: orderItem,
|
|
204
|
+
combined,
|
|
205
|
+
cache,
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const params = addOrderItem({
|
|
209
|
+
order,
|
|
210
|
+
item: orderItem,
|
|
211
|
+
itemIndex: idx,
|
|
212
|
+
});
|
|
213
|
+
let [nextOrder, nextItemIndex] = params;
|
|
214
|
+
const [, , nextItem] = params;
|
|
215
|
+
|
|
216
|
+
if (modifiersToAdd.length) {
|
|
217
|
+
nextOrder = modifiersToAdd.reduce(
|
|
218
|
+
(acc, modifier) =>
|
|
219
|
+
actions.addItemModifier({
|
|
220
|
+
itemIndex: nextItemIndex,
|
|
221
|
+
order: acc,
|
|
222
|
+
modifier,
|
|
223
|
+
cache,
|
|
224
|
+
}),
|
|
225
|
+
nextOrder
|
|
226
|
+
);
|
|
227
|
+
}
|
|
230
228
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
229
|
+
const { reArrangedOrder, newIndex } = reArrangeNewItem({
|
|
230
|
+
nextOrder,
|
|
231
|
+
nextItemIndex,
|
|
232
|
+
});
|
|
235
233
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
234
|
+
if (reArrangedOrder && newIndex) {
|
|
235
|
+
nextOrder = { ...reArrangedOrder };
|
|
236
|
+
nextItemIndex = newIndex;
|
|
237
|
+
}
|
|
240
238
|
|
|
241
|
-
|
|
239
|
+
// Need to delete any pending Items if the current was combined
|
|
242
240
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
241
|
+
if (combined && pendingItemIndex > -1 && idx !== itemIndex) {
|
|
242
|
+
const idxToRemove = actions.getPendingItemIndex(nextOrder);
|
|
243
|
+
nextOrder.items.splice(idxToRemove, 1);
|
|
244
|
+
}
|
|
247
245
|
|
|
248
|
-
|
|
249
|
-
};
|
|
246
|
+
return [nextOrder, nextItemIndex, nextItem];
|
|
247
|
+
};
|
|
250
248
|
};
|
|
@@ -14,12 +14,13 @@ module.exports = ({ actions, settings, _ }) => {
|
|
|
14
14
|
const updatedQuantity = reset
|
|
15
15
|
? quantity
|
|
16
16
|
: parseInt(`${item.quantity}${quantity}`, 10);
|
|
17
|
-
return actions.
|
|
17
|
+
return actions.updateItem({
|
|
18
18
|
order,
|
|
19
|
-
item,
|
|
20
19
|
itemIndex,
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
item: {
|
|
21
|
+
...item,
|
|
22
|
+
quantity: updatedQuantity,
|
|
23
|
+
},
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
26
|
if (isBefore) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.21",
|
|
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": "30595eb4b38240679c45e5eff7ac875719e9dcd0"
|
|
40
40
|
}
|