@darkpos/pricing 1.0.153 → 1.0.154

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.
@@ -135,6 +135,21 @@ describe('getOverPaidOrders tests', () => {
135
135
  expect(result.overPaidOrders).toHaveLength(0);
136
136
  expect(result.overPaidAmount).toBe(0);
137
137
  });
138
+
139
+ test('includes a void order paid exactly to its total as refundable', () => {
140
+ const order = pricingService.order.voidOrder({
141
+ ...baseOrder,
142
+ totalPaid: 30,
143
+ });
144
+
145
+ const result = pricingService.payment.getOverPaidOrders({
146
+ orders: [order],
147
+ });
148
+
149
+ expect(result.overPaidOrders).toHaveLength(1);
150
+ expect(result.overPaidOrders[0].refundableAmount).toBe(30);
151
+ expect(result.overPaidAmount).toBe(30);
152
+ });
138
153
  });
139
154
 
140
155
  describe('capOverPaidItem tests', () => {
@@ -3,17 +3,20 @@ module.exports = ({ orderActions, utils }) =>
3
3
  const overPaidOrders = [];
4
4
  let overPaidAmount = 0;
5
5
 
6
- const appendIfOverPaid = currentOrder => {
6
+ const appendIfRefundable = currentOrder => {
7
7
  const overPaidTotal = orderActions.getOverPaidAmount({
8
8
  order: currentOrder,
9
9
  });
10
+ const refundableAmount = orderActions.isVoid(currentOrder)
11
+ ? currentOrder.totalPaid || 0
12
+ : overPaidTotal;
10
13
 
11
- if (overPaidTotal > 0) {
14
+ if (refundableAmount > 0) {
12
15
  overPaidOrders.push({
13
16
  ...currentOrder,
14
- refundableAmount: overPaidTotal,
17
+ refundableAmount,
15
18
  });
16
- overPaidAmount = utils.math.add(overPaidAmount, overPaidTotal);
19
+ overPaidAmount = utils.math.add(overPaidAmount, refundableAmount);
17
20
  }
18
21
  };
19
22
 
@@ -23,12 +26,12 @@ module.exports = ({ orderActions, utils }) =>
23
26
  const childOrders = order.orders || [];
24
27
 
25
28
  if (childOrders.length > 0) {
26
- childOrders.forEach(appendIfOverPaid);
29
+ childOrders.forEach(appendIfRefundable);
27
30
  return;
28
31
  }
29
32
  }
30
33
 
31
- appendIfOverPaid(order);
34
+ appendIfRefundable(order);
32
35
  });
33
36
 
34
37
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkpos/pricing",
3
- "version": "1.0.153",
3
+ "version": "1.0.154",
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": "495fd0beca96603861fccf52ba2a5618fc632e7a"
57
+ "gitHead": "6d06392dd10f6fba50228db77331e4073cf2e3bf"
58
58
  }