@darkpos/pricing 1.0.139 → 1.0.140
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 +21 -0
- package/lib/item/getOverpaidAmount.js +7 -0
- package/lib/item/getPaidStatus.js +8 -8
- package/lib/item/index.js +4 -0
- package/lib/item/isOverpaid.js +7 -0
- package/lib/order/getOverpaidAmount.js +8 -0
- package/lib/order/index.js +2 -0
- package/package.json +2 -2
|
@@ -3808,6 +3808,27 @@ describe('Order actions', () => {
|
|
|
3808
3808
|
expect(newOrder2.items[0].status).toMatchObject({ paid: { value: true } });
|
|
3809
3809
|
});
|
|
3810
3810
|
|
|
3811
|
+
test('Mark paid status true if totalPaid is greater than total', () => {
|
|
3812
|
+
const orderItem = {
|
|
3813
|
+
price: 25,
|
|
3814
|
+
quantity: 1,
|
|
3815
|
+
status: {},
|
|
3816
|
+
totalPaid: 30,
|
|
3817
|
+
};
|
|
3818
|
+
const pricing = usePricing({
|
|
3819
|
+
store: { _settings: { order: { autoMarkAsPaid: false } } },
|
|
3820
|
+
});
|
|
3821
|
+
const order = { items: [orderItem], status: {} };
|
|
3822
|
+
const newOrder = pricing.order.calculate(order);
|
|
3823
|
+
|
|
3824
|
+
expect(newOrder).toHaveProperty('total', 25);
|
|
3825
|
+
expect(newOrder).toHaveProperty('totalPaid', 30);
|
|
3826
|
+
expect(newOrder.status).toMatchObject({ paid: true });
|
|
3827
|
+
expect(newOrder.items[0].status).toMatchObject({
|
|
3828
|
+
paid: { value: true },
|
|
3829
|
+
});
|
|
3830
|
+
});
|
|
3831
|
+
|
|
3811
3832
|
test('Dont update status if not needed', () => {
|
|
3812
3833
|
const orderItem = {
|
|
3813
3834
|
price: 25,
|
|
@@ -9,21 +9,21 @@ module.exports = ({ actions, settings }) =>
|
|
|
9
9
|
const total = totalParam || 0;
|
|
10
10
|
const totalPaid = totalPaidParam || 0;
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
) {
|
|
12
|
+
const isPaid = actions.isPaid({ item: { status: localStatus } });
|
|
13
|
+
|
|
14
|
+
const paid = { value: true, date: new Date() };
|
|
15
|
+
|
|
16
|
+
if (isPaid && total !== 0 && total > totalPaid) {
|
|
17
17
|
return undefined;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
if (!isPaid && totalPaid > total) return paid;
|
|
21
|
+
|
|
20
22
|
if (!settings || !settings.order || !settings.order.autoMarkAsPaid) {
|
|
21
23
|
return localStatus.paid;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
if (!
|
|
25
|
-
return { value: true, date: new Date() };
|
|
26
|
-
}
|
|
26
|
+
if (!isPaid && total === 0) return paid;
|
|
27
27
|
|
|
28
28
|
return localStatus.paid;
|
|
29
29
|
};
|
package/lib/item/index.js
CHANGED
|
@@ -82,6 +82,8 @@ const getTaxes = require('./getTaxes');
|
|
|
82
82
|
const getAmountToPayById = require('./getAmountToPayById');
|
|
83
83
|
const applyPayment = require('./applyPayment');
|
|
84
84
|
const getBalanceForPaymentModifier = require('./getBalanceForPaymentModifier');
|
|
85
|
+
const isOverpaid = require('./isOverpaid');
|
|
86
|
+
const getOverpaidAmount = require('./getOverpaidAmount');
|
|
85
87
|
|
|
86
88
|
const itemActions = (deps = {}) => {
|
|
87
89
|
const actions = {};
|
|
@@ -177,6 +179,8 @@ const itemActions = (deps = {}) => {
|
|
|
177
179
|
getAmountToPayById: getAmountToPayById(innerDeps),
|
|
178
180
|
applyPayment: applyPayment(innerDeps),
|
|
179
181
|
getBalanceForPaymentModifier: getBalanceForPaymentModifier(innerDeps),
|
|
182
|
+
isOverpaid: isOverpaid(innerDeps),
|
|
183
|
+
getOverpaidAmount: getOverpaidAmount(innerDeps),
|
|
180
184
|
});
|
|
181
185
|
|
|
182
186
|
Object.keys(freezedActions).forEach(actionName => {
|
package/lib/order/index.js
CHANGED
|
@@ -100,6 +100,7 @@ const removeEmptyNotes = require('./removeEmptyNotes');
|
|
|
100
100
|
const getTaxes = require('./getTaxes');
|
|
101
101
|
const getPickedStatus = require('./getPickedStatus');
|
|
102
102
|
const calculateWithPayment = require('./calculateWithPayment');
|
|
103
|
+
const getOverpaidAmount = require('./getOverpaidAmount');
|
|
103
104
|
|
|
104
105
|
const orderActions = (deps = {}) => {
|
|
105
106
|
const actions = {};
|
|
@@ -211,6 +212,7 @@ const orderActions = (deps = {}) => {
|
|
|
211
212
|
getTaxes: getTaxes(innerDeps),
|
|
212
213
|
getPickedStatus: getPickedStatus(innerDeps),
|
|
213
214
|
calculateWithPayment: calculateWithPayment(innerDeps),
|
|
215
|
+
getOverpaidAmount: getOverpaidAmount(innerDeps),
|
|
214
216
|
});
|
|
215
217
|
|
|
216
218
|
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.140",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"supertest": "^6.2.3",
|
|
54
54
|
"supervisor": "^0.12.0"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "a679a827cb2a83762ae4ec5ce76ae5416b654a48"
|
|
57
57
|
}
|