@darkpos/pricing 1.0.149 → 1.0.151
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.
|
@@ -77,6 +77,29 @@ describe('hasSerial function', () => {
|
|
|
77
77
|
expect(result).toBe(false);
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
+
test('returns false when the matching serial belongs to a pending item', () => {
|
|
81
|
+
const { hasSerial } = pricingService.order;
|
|
82
|
+
|
|
83
|
+
const order = {
|
|
84
|
+
items: [
|
|
85
|
+
{
|
|
86
|
+
_id: '1',
|
|
87
|
+
serial: 'ABC-123',
|
|
88
|
+
isPending: true,
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const item = {
|
|
94
|
+
_id: '2',
|
|
95
|
+
serial: 'ABC-123',
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const result = hasSerial({ order, item });
|
|
99
|
+
|
|
100
|
+
expect(result).toBe(false);
|
|
101
|
+
});
|
|
102
|
+
|
|
80
103
|
test('returns false when order or item is missing', () => {
|
|
81
104
|
const { hasSerial } = pricingService.order;
|
|
82
105
|
|
package/lib/item/index.js
CHANGED
|
@@ -69,6 +69,7 @@ const applyNotesOverridesToItem = require('./applyNotesOverridesToItem');
|
|
|
69
69
|
const getModifiersToNotCompute = require('./getModifiersToNotCompute');
|
|
70
70
|
const getSplitDepartment = require('./getSplitDepartment');
|
|
71
71
|
const isPriceChanged = require('./isPriceChanged');
|
|
72
|
+
const isPending = require('./isPending');
|
|
72
73
|
const isSerialRequired = require('./isSerialRequired');
|
|
73
74
|
const isSerialLengthValid = require('./isSerialLengthValid');
|
|
74
75
|
const getSerialStatus = require('./getSerialStatus');
|
|
@@ -166,6 +167,7 @@ const itemActions = (deps = {}) => {
|
|
|
166
167
|
getModifiersToNotCompute: getModifiersToNotCompute(innerDeps),
|
|
167
168
|
getSplitDepartment: getSplitDepartment(innerDeps),
|
|
168
169
|
isPriceChanged: isPriceChanged(innerDeps),
|
|
170
|
+
isPending: isPending(innerDeps),
|
|
169
171
|
isSerialRequired: isSerialRequired(innerDeps),
|
|
170
172
|
isSerialLengthValid: isSerialLengthValid(innerDeps),
|
|
171
173
|
getSerialStatus: getSerialStatus(innerDeps),
|
package/lib/order/addItem.js
CHANGED
|
@@ -130,11 +130,12 @@ module.exports = ({ actions, itemActions, modifierActions, settings, _ }) => {
|
|
|
130
130
|
|
|
131
131
|
const pendingItem = actions.getSelectedItem({ order, itemIndex });
|
|
132
132
|
|
|
133
|
-
if (pendingItem &&
|
|
133
|
+
if (pendingItem && itemActions.isPending(pendingItem) && !combined) {
|
|
134
134
|
idx = itemIndex;
|
|
135
135
|
combined = !!pendingItem.itemId;
|
|
136
136
|
orderItem.quantity = pendingItem.quantity;
|
|
137
|
-
orderItem.isPending =
|
|
137
|
+
orderItem.isPending =
|
|
138
|
+
itemActions.isPending(orderItem) || !orderItem.itemId;
|
|
138
139
|
// add inventory
|
|
139
140
|
if (pendingItem.inventory) {
|
|
140
141
|
const inventory = getInventory(pendingItem);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
module.exports = ({ actions, modifierActions }) => {
|
|
1
|
+
module.exports = ({ actions, modifierActions, _ }) => {
|
|
2
2
|
const getRemaining = (subscriptions, orderId) => {
|
|
3
3
|
const remaining = subscriptions.reduce((total, subscription) => {
|
|
4
|
-
const { usesLimit = 0, uses = 0, history = {} } = subscription;
|
|
4
|
+
const { usesLimit = 0, uses = 0, history = {} } = subscription.item || {};
|
|
5
5
|
const orderHistory = history[orderId] || 0;
|
|
6
6
|
return total + usesLimit + orderHistory - uses;
|
|
7
7
|
}, 0);
|
|
@@ -37,8 +37,18 @@ module.exports = ({ actions, modifierActions }) => {
|
|
|
37
37
|
|
|
38
38
|
const getSubscriptions = subscriptions =>
|
|
39
39
|
subscriptions
|
|
40
|
-
.map(each =>
|
|
41
|
-
.filter(Boolean)
|
|
40
|
+
.map(each => _.get(each, 'properties.subscription'))
|
|
41
|
+
.filter(Boolean)
|
|
42
|
+
.filter(each => {
|
|
43
|
+
const renewalType = _.get(each, 'item.renewalType');
|
|
44
|
+
const endDate = _.get(each, 'dateLimit.to');
|
|
45
|
+
const today = new Date();
|
|
46
|
+
|
|
47
|
+
if (renewalType === 'none' && endDate && new Date(endDate) < today)
|
|
48
|
+
return false;
|
|
49
|
+
|
|
50
|
+
return true;
|
|
51
|
+
});
|
|
42
52
|
|
|
43
53
|
return function hasRemainingSubscription({ order, item }) {
|
|
44
54
|
if (!order || !item || !item.itemId) return [false];
|
|
@@ -53,7 +63,9 @@ module.exports = ({ actions, modifierActions }) => {
|
|
|
53
63
|
subscriptions = getSubscriptions(subscriptions);
|
|
54
64
|
|
|
55
65
|
const isUnlimited = subscriptions.some(
|
|
56
|
-
each =>
|
|
66
|
+
each =>
|
|
67
|
+
!_.get(each, 'item.usesLimit') ||
|
|
68
|
+
_.get(each, 'item.renewalType') === 'limit_reached'
|
|
57
69
|
);
|
|
58
70
|
if (isUnlimited) return [true];
|
|
59
71
|
|
package/lib/order/hasSerial.js
CHANGED
|
@@ -21,7 +21,9 @@ module.exports = ({ itemActions }) =>
|
|
|
21
21
|
return order.items
|
|
22
22
|
.filter(
|
|
23
23
|
orderItem =>
|
|
24
|
-
orderItem._id !== item._id &&
|
|
24
|
+
orderItem._id !== item._id &&
|
|
25
|
+
!itemActions.isRelatedItem(orderItem) &&
|
|
26
|
+
!itemActions.isPending(orderItem)
|
|
25
27
|
)
|
|
26
28
|
.some(
|
|
27
29
|
orderItem => normalizeSerial(orderItem.serial) === normalizedSerial
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.151",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"supertest": "^6.2.3",
|
|
55
55
|
"supervisor": "^0.12.0"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "f95dc7f14dcf4673e5fe25cb2faeb5eee26fb592"
|
|
58
58
|
}
|