@darkpos/pricing 1.0.71 → 1.0.72
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.
|
@@ -1651,7 +1651,13 @@ describe('hasModifier Function', () => {
|
|
|
1651
1651
|
},
|
|
1652
1652
|
};
|
|
1653
1653
|
|
|
1654
|
-
const item = {
|
|
1654
|
+
const item = {
|
|
1655
|
+
_id: 1,
|
|
1656
|
+
itemId: 'ab',
|
|
1657
|
+
modifiers: [groupMod],
|
|
1658
|
+
price: 500,
|
|
1659
|
+
total: 10000,
|
|
1660
|
+
};
|
|
1655
1661
|
|
|
1656
1662
|
const order = {
|
|
1657
1663
|
items: [item],
|
|
@@ -1683,6 +1689,25 @@ describe('hasModifier Function', () => {
|
|
|
1683
1689
|
|
|
1684
1690
|
expect(updatedOrder.items.length).toBe(2);
|
|
1685
1691
|
|
|
1692
|
+
expect(updatedOrder.items[1]).toMatchObject({
|
|
1693
|
+
_id: 1,
|
|
1694
|
+
itemId: 'ab',
|
|
1695
|
+
modifiers: [
|
|
1696
|
+
{
|
|
1697
|
+
_id: 'groupMod10',
|
|
1698
|
+
attributes: ['group'],
|
|
1699
|
+
properties: {
|
|
1700
|
+
group: {
|
|
1701
|
+
items: [{ _id: 'abc', name: 'related item abc', itemId: 'abc' }],
|
|
1702
|
+
modifiers: [{ _id: '123', name: 'related mod' }],
|
|
1703
|
+
},
|
|
1704
|
+
},
|
|
1705
|
+
},
|
|
1706
|
+
],
|
|
1707
|
+
price: 500,
|
|
1708
|
+
total: 10000,
|
|
1709
|
+
});
|
|
1710
|
+
|
|
1686
1711
|
const result = pricingService.item.hasModifier({
|
|
1687
1712
|
item: updatedOrder.items[1],
|
|
1688
1713
|
modifier: groupMod,
|
|
@@ -1693,5 +1718,47 @@ describe('hasModifier Function', () => {
|
|
|
1693
1718
|
});
|
|
1694
1719
|
|
|
1695
1720
|
expect(result).toBe(true);
|
|
1721
|
+
|
|
1722
|
+
const { updatedOrder: updatedOrder2 } = pricingService.order.addItem({
|
|
1723
|
+
order,
|
|
1724
|
+
item: {
|
|
1725
|
+
...relatedModItem,
|
|
1726
|
+
properties: {
|
|
1727
|
+
relatedItem: true,
|
|
1728
|
+
parentItemId: item.itemId,
|
|
1729
|
+
parentId: item._id,
|
|
1730
|
+
includeParent: false,
|
|
1731
|
+
relatedItemId: relatedModItem._id,
|
|
1732
|
+
},
|
|
1733
|
+
},
|
|
1734
|
+
});
|
|
1735
|
+
|
|
1736
|
+
expect(updatedOrder2.items.length).toBe(2);
|
|
1737
|
+
|
|
1738
|
+
expect(updatedOrder2.items[1]).toMatchObject({
|
|
1739
|
+
_id: 1,
|
|
1740
|
+
itemId: 'ab',
|
|
1741
|
+
modifiers: [],
|
|
1742
|
+
price: 0,
|
|
1743
|
+
total: 0,
|
|
1744
|
+
subTotals: {
|
|
1745
|
+
_included: 0,
|
|
1746
|
+
_xincluded: 0,
|
|
1747
|
+
_direct: 0,
|
|
1748
|
+
_xdirect: 0,
|
|
1749
|
+
_actual: 0,
|
|
1750
|
+
},
|
|
1751
|
+
});
|
|
1752
|
+
|
|
1753
|
+
const result2 = pricingService.item.hasModifier({
|
|
1754
|
+
item: updatedOrder2.items[1],
|
|
1755
|
+
modifier: groupMod,
|
|
1756
|
+
relatedItems: pricingService.order.getRelatedItems({
|
|
1757
|
+
order: updatedOrder2,
|
|
1758
|
+
item: updatedOrder2.items[1],
|
|
1759
|
+
}),
|
|
1760
|
+
});
|
|
1761
|
+
|
|
1762
|
+
expect(result2).toBe(true);
|
|
1696
1763
|
});
|
|
1697
1764
|
});
|
|
@@ -6,7 +6,8 @@ module.exports = ({ actions, constants }) => {
|
|
|
6
6
|
actions.hasAttribute(modifier, Modifier.Attributes.GROUP) &&
|
|
7
7
|
properties &&
|
|
8
8
|
properties.group &&
|
|
9
|
-
(properties.group.modifiers || []).length
|
|
9
|
+
((properties.group.modifiers || []).length ||
|
|
10
|
+
!!properties.group.manualModifiers)
|
|
10
11
|
);
|
|
11
12
|
};
|
|
12
13
|
};
|
package/lib/order/addItem.js
CHANGED
|
@@ -168,8 +168,8 @@ module.exports = ({ actions, itemActions, modifierActions, settings, _ }) => {
|
|
|
168
168
|
if (!_.isEmpty(inheritedModifiers))
|
|
169
169
|
modifiersToAdd.push(...inheritedModifiers);
|
|
170
170
|
// Remove parent if it is only a repair Item
|
|
171
|
-
if (!itemActions.isParentIncluded(orderItem)) {
|
|
172
|
-
order = actions.
|
|
171
|
+
if (!itemActions.isParentIncluded(orderItem) && !!parent) {
|
|
172
|
+
order = actions.resetItem({ order, item: parent });
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
}
|
|
@@ -249,7 +249,11 @@ module.exports = ({ actions, itemActions, modifierActions, settings, _ }) => {
|
|
|
249
249
|
nextOrder.items.splice(idxToRemove, 1);
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
-
if (
|
|
252
|
+
if (
|
|
253
|
+
itemActions.isRelatedItem(item) &&
|
|
254
|
+
itemActions.hasAddModifiers(item) &&
|
|
255
|
+
itemActions.isParentIncluded(item)
|
|
256
|
+
) {
|
|
253
257
|
const parentItem = itemActions.getParentItem(nextOrder.items, item);
|
|
254
258
|
const parentIndex = actions.getItemIndex({
|
|
255
259
|
order: nextOrder,
|
package/lib/order/index.js
CHANGED
|
@@ -88,6 +88,7 @@ const applyPayment = require('./applyPayment');
|
|
|
88
88
|
const getBalance = require('./getBalance');
|
|
89
89
|
const getLastLocation = require('./getLastLocation');
|
|
90
90
|
const getModifierRelations = require('./getModifierRelations');
|
|
91
|
+
const resetItem = require('./resetItem');
|
|
91
92
|
|
|
92
93
|
const orderActions = (deps = {}) => {
|
|
93
94
|
const actions = {};
|
|
@@ -187,6 +188,7 @@ const orderActions = (deps = {}) => {
|
|
|
187
188
|
getOrdersBalance: getOrdersBalance(innerDeps),
|
|
188
189
|
getLastLocation: getLastLocation(innerDeps),
|
|
189
190
|
getModifierRelations: getModifierRelations(innerDeps),
|
|
191
|
+
resetItem: resetItem(innerDeps),
|
|
190
192
|
});
|
|
191
193
|
|
|
192
194
|
Object.keys(freezedActions).forEach(actionName => {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module.exports = ({ itemActions }) =>
|
|
2
|
+
function resetItem({ item, order }) {
|
|
3
|
+
if (!item) return undefined;
|
|
4
|
+
|
|
5
|
+
const itemReset = itemActions.calculate(
|
|
6
|
+
{
|
|
7
|
+
...item,
|
|
8
|
+
price: 0,
|
|
9
|
+
modifiers: [],
|
|
10
|
+
},
|
|
11
|
+
{}
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
const nextItems = order.items;
|
|
15
|
+
const parentIndex = order.items.findIndex(
|
|
16
|
+
eachItem => eachItem._id === itemReset._id
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
nextItems.splice(parentIndex, 1, itemReset);
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
...order,
|
|
23
|
+
items: nextItems,
|
|
24
|
+
};
|
|
25
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.72",
|
|
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": "
|
|
52
|
+
"gitHead": "2dc88094c2dbcebc04e0fbd817b45809a44dc403"
|
|
53
53
|
}
|