@darkpos/pricing 1.0.87 → 1.0.89
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__/mocks/setPieces/ordersMock.js +107 -0
- package/__TEST__/order/order.test.js +74 -0
- package/__TEST__/order/setPieces.test.js +51 -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 +6 -0
- package/lib/order/isFullyPaid.js +6 -0
- package/lib/order/setPieces.js +24 -0
- package/package.json +3 -3
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
const orders = [
|
|
2
|
+
{
|
|
3
|
+
end: {
|
|
4
|
+
requestDate: '2025-05-07T20:28:00Z',
|
|
5
|
+
actualDate: '',
|
|
6
|
+
location: {
|
|
7
|
+
name: 'PPSOL',
|
|
8
|
+
locationType: 'store',
|
|
9
|
+
storeId: '67b78ebcb1f0420011470f2b',
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
properties: {
|
|
13
|
+
pieceCount: '',
|
|
14
|
+
pieces: [
|
|
15
|
+
{
|
|
16
|
+
departmentId: '67fea241af24e570c032b33f',
|
|
17
|
+
name: 'Dry Cleaning',
|
|
18
|
+
code: 'D',
|
|
19
|
+
tagSize: 'small',
|
|
20
|
+
count: '',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
departmentId: '67fea241af24e570c032b340',
|
|
24
|
+
name: 'Laundry',
|
|
25
|
+
code: 'L',
|
|
26
|
+
tagSize: 'small',
|
|
27
|
+
count: '',
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
notify: {},
|
|
31
|
+
print: ['quick-order-receipt'],
|
|
32
|
+
},
|
|
33
|
+
customer: {
|
|
34
|
+
_id: '67f6dedcf5384804f5a42e43',
|
|
35
|
+
},
|
|
36
|
+
status: {
|
|
37
|
+
order: 'open',
|
|
38
|
+
detailed: false,
|
|
39
|
+
},
|
|
40
|
+
subTotal: 0,
|
|
41
|
+
subTotals: {},
|
|
42
|
+
total: 0,
|
|
43
|
+
tax: 0,
|
|
44
|
+
start: {
|
|
45
|
+
requestDate: '2025-05-07T19:28',
|
|
46
|
+
actualDate: '2025-05-07T19:28',
|
|
47
|
+
location: {
|
|
48
|
+
name: 'PPSOL',
|
|
49
|
+
locationType: 'store',
|
|
50
|
+
storeId: '67b78ebcb1f0420011470f2b',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
end: {
|
|
56
|
+
requestDate: '2025-05-07T20:30:00Z',
|
|
57
|
+
actualDate: '',
|
|
58
|
+
location: {
|
|
59
|
+
name: 'Sunshine Cleaners',
|
|
60
|
+
locationType: 'store',
|
|
61
|
+
storeId: '67e1c09c05b96100127280a8',
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
properties: {
|
|
65
|
+
pieceCount: '10',
|
|
66
|
+
pieces: [
|
|
67
|
+
{
|
|
68
|
+
departmentId: '67fea241af24e570c032b33f',
|
|
69
|
+
name: 'Dry Cleaning',
|
|
70
|
+
code: 'D',
|
|
71
|
+
tagSize: 'small',
|
|
72
|
+
count: '5',
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
departmentId: '67fea241af24e570c032b340',
|
|
76
|
+
name: 'Laundry',
|
|
77
|
+
code: 'L',
|
|
78
|
+
tagSize: 'small',
|
|
79
|
+
count: '5',
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
notify: {},
|
|
83
|
+
print: ['quick-order-receipt'],
|
|
84
|
+
},
|
|
85
|
+
customer: {
|
|
86
|
+
_id: '67edaa1721d00ec86d54071e',
|
|
87
|
+
},
|
|
88
|
+
status: {
|
|
89
|
+
order: 'open',
|
|
90
|
+
detailed: false,
|
|
91
|
+
},
|
|
92
|
+
subTotal: 0,
|
|
93
|
+
subTotals: {},
|
|
94
|
+
total: 0,
|
|
95
|
+
tax: 0,
|
|
96
|
+
start: {
|
|
97
|
+
requestDate: '2025-05-07T19:30',
|
|
98
|
+
actualDate: '2025-05-07T19:30',
|
|
99
|
+
location: {
|
|
100
|
+
name: 'Sunshine Cleaners',
|
|
101
|
+
locationType: 'store',
|
|
102
|
+
storeId: '67e1c09c05b96100127280a8',
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
];
|
|
107
|
+
module.exports = orders;
|
|
@@ -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
|
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const utils = require('@darkpos/utils');
|
|
2
|
+
const usePricing = require('../../index');
|
|
3
|
+
const mockStores = require('../mocks/stores');
|
|
4
|
+
const orders = require('../mocks/setPieces/ordersMock');
|
|
5
|
+
|
|
6
|
+
const session = {
|
|
7
|
+
store: mockStores[0],
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const pricingService = usePricing(session);
|
|
11
|
+
|
|
12
|
+
describe('set pieces', () => {
|
|
13
|
+
test('Normalize pieces that are not numbers', () => {
|
|
14
|
+
const order = orders[0];
|
|
15
|
+
|
|
16
|
+
const newOrder = pricingService.order.setPieces({ order });
|
|
17
|
+
expect(newOrder.properties.pieceCount).toBe(0);
|
|
18
|
+
newOrder.properties.pieces.map(item => expect(item.count).toBe(0));
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('Normalize pieces that are strings into numbers', () => {
|
|
22
|
+
const order = orders[1];
|
|
23
|
+
|
|
24
|
+
const newOrder = pricingService.order.setPieces({ order });
|
|
25
|
+
expect(newOrder.properties.pieceCount).toBe(10);
|
|
26
|
+
expect(typeof newOrder.properties.pieceCount).toBe('number');
|
|
27
|
+
newOrder.properties.pieces.map(item => {
|
|
28
|
+
expect(item.count).toBe(5);
|
|
29
|
+
expect(typeof item.count).toBe('number');
|
|
30
|
+
return {};
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
test('utils helpers to toNumberOrZero', () => {
|
|
34
|
+
const number1 = 0;
|
|
35
|
+
const number2 = '';
|
|
36
|
+
const number3 = NaN;
|
|
37
|
+
const number4 = 'abc';
|
|
38
|
+
const number5 = 10;
|
|
39
|
+
|
|
40
|
+
const value1 = utils.helpers.toNumberOrZero(number1);
|
|
41
|
+
const value2 = utils.helpers.toNumberOrZero(number2);
|
|
42
|
+
const value3 = utils.helpers.toNumberOrZero(number3);
|
|
43
|
+
const value4 = utils.helpers.toNumberOrZero(number4);
|
|
44
|
+
const value5 = utils.helpers.toNumberOrZero(number5);
|
|
45
|
+
expect(value1).toBe(0);
|
|
46
|
+
expect(value2).toBe(0);
|
|
47
|
+
expect(value3).toBe(0);
|
|
48
|
+
expect(value4).toBe(0);
|
|
49
|
+
expect(value5).toBe(10);
|
|
50
|
+
});
|
|
51
|
+
});
|
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,9 @@ 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');
|
|
96
|
+
const setPieces = require('./setPieces');
|
|
94
97
|
|
|
95
98
|
const orderActions = (deps = {}) => {
|
|
96
99
|
const actions = {};
|
|
@@ -193,6 +196,9 @@ const orderActions = (deps = {}) => {
|
|
|
193
196
|
splitItems: splitItems(innerDeps),
|
|
194
197
|
getNewItems: getNewItems(innerDeps),
|
|
195
198
|
mapSubOrders: mapSubOrders(innerDeps),
|
|
199
|
+
isFullyPaid: isFullyPaid(innerDeps),
|
|
200
|
+
getUpdatedStatus: getUpdatedStatus(innerDeps),
|
|
201
|
+
setPieces: setPieces(innerDeps),
|
|
196
202
|
});
|
|
197
203
|
|
|
198
204
|
Object.keys(freezedActions).forEach(actionName => {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module.exports = ({ utils }) => {
|
|
2
|
+
const { helpers } = utils;
|
|
3
|
+
return function setPieces({ order }) {
|
|
4
|
+
const nextOrder = {
|
|
5
|
+
...order,
|
|
6
|
+
properties: {
|
|
7
|
+
...(order.properties || {}),
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
nextOrder.properties.pieceCount = helpers.toNumberOrZero(
|
|
12
|
+
nextOrder.properties.pieceCount
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
if (Array.isArray(nextOrder.properties.pieces)) {
|
|
16
|
+
nextOrder.properties.pieces = nextOrder.properties.pieces.map(pc => ({
|
|
17
|
+
...pc,
|
|
18
|
+
count: helpers.toNumberOrZero(pc.count),
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return nextOrder;
|
|
23
|
+
};
|
|
24
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.89",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@darkpos/utils": "^1.0.
|
|
36
|
+
"@darkpos/utils": "^1.0.13",
|
|
37
37
|
"crypto-js": "^4.2.0",
|
|
38
38
|
"lodash": "^4.17.21",
|
|
39
39
|
"moment-timezone": "^0.5.34"
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"supertest": "^6.2.3",
|
|
52
52
|
"supervisor": "^0.12.0"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "94c96f8e898bff82463d49bfb39f27ef0e70909e"
|
|
55
55
|
}
|