@darkpos/pricing 1.0.87 → 1.0.88
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__/order/order.test.js +74 -0
- package/lib/item/calculate.js +1 -0
- package/lib/item/getUpdatedStatus.js +20 -0
- package/lib/item/index.js +2 -0
- package/lib/item/isFullyPaid.js +1 -1
- package/lib/item/updateAssemblyStatus.js +0 -0
- package/lib/order/calculate.js +7 -1
- package/lib/order/getUpdatedStatus.js +23 -0
- package/lib/order/index.js +4 -0
- package/lib/order/isFullyPaid.js +6 -0
- package/package.json +2 -2
|
@@ -3891,4 +3891,78 @@ describe('Order actions', () => {
|
|
|
3891
3891
|
discount: -1.09,
|
|
3892
3892
|
});
|
|
3893
3893
|
});
|
|
3894
|
+
|
|
3895
|
+
test('Mark paid status true if total is 0 and autoMarkAsPaid: true', () => {
|
|
3896
|
+
const orderItem = {
|
|
3897
|
+
price: 0,
|
|
3898
|
+
quantity: 1,
|
|
3899
|
+
};
|
|
3900
|
+
const order = { items: [orderItem] };
|
|
3901
|
+
const pricing = usePricing({
|
|
3902
|
+
store: { _settings: { order: { autoMarkAsPaid: true } } },
|
|
3903
|
+
});
|
|
3904
|
+
const newOrder = pricing.order.calculate(order);
|
|
3905
|
+
|
|
3906
|
+
expect(newOrder).toHaveProperty('total', 0);
|
|
3907
|
+
expect(newOrder.status).toMatchObject({ fullyPaid: true });
|
|
3908
|
+
expect(newOrder.items[0].total).toBe(0);
|
|
3909
|
+
expect(newOrder.items[0].status).toMatchObject({
|
|
3910
|
+
paid: {
|
|
3911
|
+
value: true,
|
|
3912
|
+
},
|
|
3913
|
+
});
|
|
3914
|
+
|
|
3915
|
+
const newOrder2 = pricingService.order.calculate(order);
|
|
3916
|
+
|
|
3917
|
+
expect(newOrder2).toHaveProperty('total', 0);
|
|
3918
|
+
expect(newOrder2.status).toBe(undefined);
|
|
3919
|
+
expect(newOrder2.items[0].total).toBe(0);
|
|
3920
|
+
expect(newOrder2.items[0].status).toBe(undefined);
|
|
3921
|
+
});
|
|
3922
|
+
|
|
3923
|
+
test('Unset paid status if total is > 0 and autoMarkAsPaid: true', () => {
|
|
3924
|
+
const orderItem = {
|
|
3925
|
+
price: 25,
|
|
3926
|
+
quantity: 1,
|
|
3927
|
+
status: {
|
|
3928
|
+
paid: { value: true, date: new Date() },
|
|
3929
|
+
},
|
|
3930
|
+
};
|
|
3931
|
+
const pricing = usePricing({
|
|
3932
|
+
store: { _settings: { order: { autoMarkAsPaid: true } } },
|
|
3933
|
+
});
|
|
3934
|
+
const order = { items: [orderItem], status: { fullyPaid: true } };
|
|
3935
|
+
const newOrder = pricing.order.calculate(order);
|
|
3936
|
+
|
|
3937
|
+
expect(newOrder).toHaveProperty('total', 25);
|
|
3938
|
+
expect(newOrder.status).toMatchObject({ fullyPaid: false });
|
|
3939
|
+
expect(newOrder.items[0].total).toBe(25);
|
|
3940
|
+
expect(newOrder.items[0].status).toMatchObject({
|
|
3941
|
+
paid: undefined,
|
|
3942
|
+
});
|
|
3943
|
+
|
|
3944
|
+
const newOrder2 = pricingService.order.calculate(order);
|
|
3945
|
+
|
|
3946
|
+
expect(newOrder2).toHaveProperty('total', 25);
|
|
3947
|
+
expect(newOrder2.status).toMatchObject({ fullyPaid: true });
|
|
3948
|
+
expect(newOrder2.items[0].total).toBe(25);
|
|
3949
|
+
expect(newOrder2.items[0].status).toMatchObject({ paid: { value: true } });
|
|
3950
|
+
});
|
|
3951
|
+
|
|
3952
|
+
test('Dont update status if not needed', () => {
|
|
3953
|
+
const orderItem = {
|
|
3954
|
+
price: 25,
|
|
3955
|
+
quantity: 1,
|
|
3956
|
+
};
|
|
3957
|
+
const pricing = usePricing({
|
|
3958
|
+
store: { _settings: { order: { autoMarkAsPaid: true } } },
|
|
3959
|
+
});
|
|
3960
|
+
const order = { items: [orderItem] };
|
|
3961
|
+
const newOrder = pricing.order.calculate(order);
|
|
3962
|
+
|
|
3963
|
+
expect(newOrder).toHaveProperty('total', 25);
|
|
3964
|
+
expect(newOrder.status).toMatchObject({});
|
|
3965
|
+
expect(newOrder.items[0].total).toBe(25);
|
|
3966
|
+
expect(newOrder.items[0].status).toMatchObject({});
|
|
3967
|
+
});
|
|
3894
3968
|
});
|
package/lib/item/calculate.js
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module.exports = ({ actions, settings }) =>
|
|
2
|
+
function getUpdatedStatus({ status, total }) {
|
|
3
|
+
if (!settings || !settings.order || !settings.order.autoMarkAsPaid)
|
|
4
|
+
return status;
|
|
5
|
+
|
|
6
|
+
const localStatus = status || {};
|
|
7
|
+
|
|
8
|
+
if (actions.isFullyPaid({ item: { status: localStatus } }) && total !== 0) {
|
|
9
|
+
return { ...localStatus, paid: undefined };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (
|
|
13
|
+
!actions.isFullyPaid({ item: { status: localStatus } }) &&
|
|
14
|
+
total === 0
|
|
15
|
+
) {
|
|
16
|
+
return { ...localStatus, paid: { value: true, date: new Date() } };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return localStatus;
|
|
20
|
+
};
|
package/lib/item/index.js
CHANGED
|
@@ -62,6 +62,7 @@ const getSubtotal = require('./getSubtotal');
|
|
|
62
62
|
const isSomeTagsMatch = require('./isSomeTagsMatch');
|
|
63
63
|
const getTotals = require('./getTotals');
|
|
64
64
|
const patchItem = require('./patchItem');
|
|
65
|
+
const getUpdatedStatus = require('./getUpdatedStatus');
|
|
65
66
|
|
|
66
67
|
const itemActions = (deps = {}) => {
|
|
67
68
|
const actions = {};
|
|
@@ -137,6 +138,7 @@ const itemActions = (deps = {}) => {
|
|
|
137
138
|
isSomeTagsMatch: isSomeTagsMatch(innerDeps),
|
|
138
139
|
getTotals: getTotals(innerDeps),
|
|
139
140
|
patchItem: patchItem(innerDeps),
|
|
141
|
+
getUpdatedStatus: getUpdatedStatus(innerDeps),
|
|
140
142
|
});
|
|
141
143
|
|
|
142
144
|
Object.keys(freezedActions).forEach(actionName => {
|
package/lib/item/isFullyPaid.js
CHANGED
|
File without changes
|
package/lib/order/calculate.js
CHANGED
|
@@ -150,9 +150,15 @@ module.exports = ({
|
|
|
150
150
|
if (difference > 0) addToItemTotal(difference);
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
+
const { subTotals, subTotal, total } =
|
|
154
|
+
itemActions.getItemsTotals(calculatedItems);
|
|
155
|
+
|
|
153
156
|
return {
|
|
154
157
|
...order,
|
|
155
|
-
|
|
158
|
+
subTotals,
|
|
159
|
+
subTotal,
|
|
160
|
+
total,
|
|
156
161
|
items: calculatedItems,
|
|
162
|
+
status: actions.getUpdatedStatus({ status: order.status, total }),
|
|
157
163
|
};
|
|
158
164
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module.exports = ({ actions, settings }) =>
|
|
2
|
+
function getUpdatedStatus({ status, total }) {
|
|
3
|
+
if (!settings || !settings.order || !settings.order.autoMarkAsPaid)
|
|
4
|
+
return status;
|
|
5
|
+
|
|
6
|
+
const localStatus = status || {};
|
|
7
|
+
|
|
8
|
+
if (
|
|
9
|
+
actions.isFullyPaid({ order: { status: localStatus } }) &&
|
|
10
|
+
total !== 0
|
|
11
|
+
) {
|
|
12
|
+
return { ...localStatus, fullyPaid: false };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (
|
|
16
|
+
!actions.isFullyPaid({ order: { status: localStatus } }) &&
|
|
17
|
+
total === 0
|
|
18
|
+
) {
|
|
19
|
+
return { ...localStatus, fullyPaid: true };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return localStatus;
|
|
23
|
+
};
|
package/lib/order/index.js
CHANGED
|
@@ -91,6 +91,8 @@ const resetItem = require('./resetItem');
|
|
|
91
91
|
const splitItems = require('./splitItems');
|
|
92
92
|
const getNewItems = require('./getNewItems');
|
|
93
93
|
const mapSubOrders = require('./mapSubOrders');
|
|
94
|
+
const isFullyPaid = require('./isFullyPaid');
|
|
95
|
+
const getUpdatedStatus = require('./getUpdatedStatus');
|
|
94
96
|
|
|
95
97
|
const orderActions = (deps = {}) => {
|
|
96
98
|
const actions = {};
|
|
@@ -193,6 +195,8 @@ const orderActions = (deps = {}) => {
|
|
|
193
195
|
splitItems: splitItems(innerDeps),
|
|
194
196
|
getNewItems: getNewItems(innerDeps),
|
|
195
197
|
mapSubOrders: mapSubOrders(innerDeps),
|
|
198
|
+
isFullyPaid: isFullyPaid(innerDeps),
|
|
199
|
+
getUpdatedStatus: getUpdatedStatus(innerDeps),
|
|
196
200
|
});
|
|
197
201
|
|
|
198
202
|
Object.keys(freezedActions).forEach(actionName => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.88",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"supertest": "^6.2.3",
|
|
52
52
|
"supervisor": "^0.12.0"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "3090bddbb5b0651296b29acf011c2bfe8db6d42d"
|
|
55
55
|
}
|