@darkpos/pricing 1.0.24 → 1.0.25

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.
@@ -124,7 +124,7 @@ describe('Order actions', () => {
124
124
  expect(newOrder).toHaveProperty('subTotals', {
125
125
  discount: -2,
126
126
  });
127
- expect(newOrder.items[0]).toHaveProperty('total', 58.29);
127
+ expect(newOrder.items[0]).toHaveProperty('total', 58.285714285714285);
128
128
  expect(newOrder.items[0]).toHaveProperty('subTotals', {
129
129
  discount: -1.7142857142857142,
130
130
  _included: 0,
@@ -134,7 +134,7 @@ describe('Order actions', () => {
134
134
  _simple: 60,
135
135
  _actual: 60,
136
136
  });
137
- expect(newOrder.items[1]).toHaveProperty('total', 9.71);
137
+ expect(newOrder.items[1]).toHaveProperty('total', 9.714285714285714);
138
138
  expect(newOrder.items[1]).toHaveProperty('subTotals', {
139
139
  discount: -0.2857142857142857,
140
140
  _included: 0,
@@ -173,7 +173,7 @@ describe('Order actions', () => {
173
173
  expect(newOrder).toHaveProperty('subTotals', {
174
174
  discount: -2.06,
175
175
  });
176
- expect(newOrder.items[0]).toHaveProperty('total', 14.39);
176
+ expect(newOrder.items[0]).toHaveProperty('total', 14.391);
177
177
  expect(newOrder.items[0]).toHaveProperty('subTotals', {
178
178
  discount: -1.599,
179
179
  _included: 0,
@@ -183,7 +183,7 @@ describe('Order actions', () => {
183
183
  _simple: 15.99,
184
184
  _actual: 15.99,
185
185
  });
186
- expect(newOrder.items[1]).toHaveProperty('total', 4.19);
186
+ expect(newOrder.items[1]).toHaveProperty('total', 4.185);
187
187
  expect(newOrder.items[1]).toHaveProperty('subTotals', {
188
188
  discount: -0.465,
189
189
  _included: 0,
@@ -682,9 +682,9 @@ describe('Order actions', () => {
682
682
  discount: -16.41,
683
683
  tax: 7.21,
684
684
  });
685
- expect(newOrder.items[0]).toHaveProperty('total', 80.6);
686
- expect(newOrder.items[1]).toHaveProperty('total', 13.69);
687
- expect(newOrder.items[2]).toHaveProperty('total', 5.91);
685
+ expect(newOrder.items[0]).toHaveProperty('total', 80.597);
686
+ expect(newOrder.items[1]).toHaveProperty('total', 13.69233125);
687
+ expect(newOrder.items[2]).toHaveProperty('total', 5.90739375);
688
688
  expect(newOrder.items[0].modifiers[0].compute).toHaveProperty(
689
689
  'amount',
690
690
  13.2
@@ -700,7 +700,7 @@ describe('Order actions', () => {
700
700
  );
701
701
  expect(newOrder.items[1].modifiers[1].compute).toHaveProperty(
702
702
  'amount',
703
- 0.985025
703
+ 0.98483125
704
704
  );
705
705
 
706
706
  expect(newOrder.items[2].modifiers[0].compute).toHaveProperty(
@@ -709,7 +709,7 @@ describe('Order actions', () => {
709
709
  );
710
710
  expect(newOrder.items[2].modifiers[1].compute).toHaveProperty(
711
711
  'amount',
712
- 0.4247
712
+ 0.42489375
713
713
  );
714
714
  });
715
715
 
@@ -774,9 +774,9 @@ describe('Order actions', () => {
774
774
  discount: -16.41,
775
775
  tax: 7.21,
776
776
  });
777
- expect(newOrder.items[0]).toHaveProperty('total', 80.6);
778
- expect(newOrder.items[1]).toHaveProperty('total', 13.69);
779
- expect(newOrder.items[2]).toHaveProperty('total', 5.91);
777
+ expect(newOrder.items[0]).toHaveProperty('total', 80.597);
778
+ expect(newOrder.items[1]).toHaveProperty('total', 13.69233125);
779
+ expect(newOrder.items[2]).toHaveProperty('total', 5.90739375);
780
780
  expect(newOrder.items[0].modifiers[0].compute).toHaveProperty(
781
781
  'amount',
782
782
  13.2
@@ -866,9 +866,9 @@ describe('Order actions', () => {
866
866
  discount: -16.41,
867
867
  tax: 7.21,
868
868
  });
869
- expect(newOrder.items[0]).toHaveProperty('total', 80.6);
870
- expect(newOrder.items[1]).toHaveProperty('total', 13.69);
871
- expect(newOrder.items[2]).toHaveProperty('total', 5.91);
869
+ expect(newOrder.items[0]).toHaveProperty('total', 80.597);
870
+ expect(newOrder.items[1]).toHaveProperty('total', 13.69233125);
871
+ expect(newOrder.items[2]).toHaveProperty('total', 5.90739375);
872
872
  expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
873
873
  'amount',
874
874
  -13.2
@@ -958,9 +958,9 @@ describe('Order actions', () => {
958
958
  discount: -16.41,
959
959
  tax: 7.21,
960
960
  });
961
- expect(newOrder.items[0]).toHaveProperty('total', 80.6);
962
- expect(newOrder.items[1]).toHaveProperty('total', 13.69);
963
- expect(newOrder.items[2]).toHaveProperty('total', 5.91);
961
+ expect(newOrder.items[0]).toHaveProperty('total', 80.597);
962
+ expect(newOrder.items[1]).toHaveProperty('total', 13.69233125);
963
+ expect(newOrder.items[2]).toHaveProperty('total', 5.90739375);
964
964
  expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
965
965
  'amount',
966
966
  -13.2
@@ -976,7 +976,7 @@ describe('Order actions', () => {
976
976
  );
977
977
  expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
978
978
  'amount',
979
- 0.985025
979
+ 0.98483125
980
980
  );
981
981
 
982
982
  expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
@@ -985,7 +985,7 @@ describe('Order actions', () => {
985
985
  );
986
986
  expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
987
987
  'amount',
988
- 0.4247
988
+ 0.42489375
989
989
  );
990
990
  });
991
991
 
@@ -1139,16 +1139,16 @@ describe('Order actions', () => {
1139
1139
  fixed: -1,
1140
1140
  tax: 0.16,
1141
1141
  });
1142
- expect(newOrder.items[0]).toHaveProperty('total', 0.72);
1143
- expect(newOrder.items[1]).toHaveProperty('total', 0.72);
1144
- expect(newOrder.items[2]).toHaveProperty('total', 0.72);
1142
+ expect(newOrder.items[0]).toHaveProperty('total', 0.7183333333333333);
1143
+ expect(newOrder.items[1]).toHaveProperty('total', 0.7183333333333334);
1144
+ expect(newOrder.items[2]).toHaveProperty('total', 0.7183333333333334);
1145
1145
  expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
1146
1146
  'amount',
1147
1147
  -0.3333333333333334
1148
1148
  );
1149
1149
  expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
1150
1150
  'amount',
1151
- 0.051925
1151
+ 0.05166666666666666
1152
1152
  );
1153
1153
 
1154
1154
  expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
@@ -1157,7 +1157,7 @@ describe('Order actions', () => {
1157
1157
  );
1158
1158
  expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
1159
1159
  'amount',
1160
- 0.051925
1160
+ 0.05166666666666667
1161
1161
  );
1162
1162
 
1163
1163
  expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
@@ -1166,7 +1166,7 @@ describe('Order actions', () => {
1166
1166
  );
1167
1167
  expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
1168
1168
  'amount',
1169
- 0.051925
1169
+ 0.05166666666666667
1170
1170
  );
1171
1171
  });
1172
1172
 
@@ -1261,19 +1261,19 @@ describe('Order actions', () => {
1261
1261
 
1262
1262
  const [item1, item2, item3] = newOrder.items;
1263
1263
  expect(newOrder).toHaveProperty('total', 12.5);
1264
- expect(item1).toHaveProperty('total', 3.65);
1264
+ expect(item1).toHaveProperty('total', 3.653846153846154);
1265
1265
  expect(item1.modifiers[1].compute).toHaveProperty(
1266
1266
  'amount',
1267
1267
  5.846153846153846
1268
1268
  );
1269
1269
 
1270
- expect(item2).toHaveProperty('total', 5.38);
1270
+ expect(item2).toHaveProperty('total', 5.3846153846153854615384615385);
1271
1271
  expect(item2.modifiers[1].compute).toHaveProperty(
1272
1272
  'amount',
1273
1273
  8.615384615384615
1274
1274
  );
1275
1275
 
1276
- expect(item3).toHaveProperty('total', 3.46);
1276
+ expect(item3).toHaveProperty('total', 3.461538461538462);
1277
1277
  expect(item3.modifiers[1].compute).toHaveProperty(
1278
1278
  'amount',
1279
1279
  5.538461538461538
@@ -1611,10 +1611,10 @@ describe('Order actions', () => {
1611
1611
  discount: -10,
1612
1612
  fee: 2,
1613
1613
  });
1614
- expect(newOrder.items[0]).toHaveProperty('total', 8.07);
1615
- expect(newOrder.items[1]).toHaveProperty('total', 7.71);
1616
- expect(newOrder.items[2]).toHaveProperty('total', 11.36);
1617
- expect(newOrder.items[3]).toHaveProperty('total', 7.3);
1614
+ expect(newOrder.items[0]).toHaveProperty('total', 8.074852767962309);
1615
+ expect(newOrder.items[1]).toHaveProperty('total', 7.709658421672556);
1616
+ expect(newOrder.items[2]).toHaveProperty('total', 11.361601884570083);
1617
+ expect(newOrder.items[3]).toHaveProperty('total', 7.303886925795053);
1618
1618
  });
1619
1619
  test('Get calculated PARTIALLY PAID Order, multiple items and paymentModifiers', () => {
1620
1620
  const paymentModifiers = orderModifiersPartiallyPaid.map(orderMod =>
@@ -1639,10 +1639,10 @@ describe('Order actions', () => {
1639
1639
  discount: -10,
1640
1640
  fee: 4,
1641
1641
  });
1642
- expect(newOrder.items[0]).toHaveProperty('total', 8.08);
1643
- expect(newOrder.items[1]).toHaveProperty('total', 7.7);
1644
- expect(newOrder.items[2]).toHaveProperty('total', 11.36);
1645
- expect(newOrder.items[3]).toHaveProperty('total', 9.3);
1642
+ expect(newOrder.items[0]).toHaveProperty('total', 8.083543307086615);
1643
+ expect(newOrder.items[1]).toHaveProperty('total', 7.703779527559055);
1644
+ expect(newOrder.items[2]).toHaveProperty('total', 11.36191226096738);
1645
+ expect(newOrder.items[3]).toHaveProperty('total', 9.300764904386952);
1646
1646
  });
1647
1647
 
1648
1648
  test('CU-8678p4ky3. Get Balance to Pay from OrderItems', () => {
@@ -1998,12 +1998,12 @@ test('CU-8678p4ky3. Get Calculated order. Multiple Items. 2 Modifiers. 1 Item ta
1998
1998
  percentage: -116.34,
1999
1999
  tax: 51.09,
2000
2000
  });
2001
- expect(newOrder.items[0]).toHaveProperty('total', 65.85);
2002
- expect(newOrder.items[1]).toHaveProperty('total', 53.03);
2003
- expect(newOrder.items[2]).toHaveProperty('total', 65.76);
2004
- expect(newOrder.items[3]).toHaveProperty('total', 144.71);
2005
- expect(newOrder.items[4]).toHaveProperty('total', 271.1);
2006
- expect(newOrder.items[5]).toHaveProperty('total', 109.91);
2001
+ expect(newOrder.items[0]).toHaveProperty('total', 65.8514125);
2002
+ expect(newOrder.items[1]).toHaveProperty('total', 53.0291625);
2003
+ expect(newOrder.items[2]).toHaveProperty('total', 65.759825);
2004
+ expect(newOrder.items[3]).toHaveProperty('total', 144.70825);
2005
+ expect(newOrder.items[4]).toHaveProperty('total', 271.099);
2006
+ expect(newOrder.items[5]).toHaveProperty('total', 109.905);
2007
2007
  expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
2008
2008
  'amount',
2009
2009
  -10.785
@@ -2058,3 +2058,67 @@ test('CU-8678p4ky3. Get Calculated order. Multiple Items. 2 Modifiers. 1 Item ta
2058
2058
  7.905
2059
2059
  );
2060
2060
  });
2061
+
2062
+ test('CU-8678tdrvq. Get Calculated order. Multiple Items. 1 Order tax', () => {
2063
+ const taxMod = {
2064
+ _id: 2,
2065
+ name: `7.75% tax`,
2066
+ type: 'tax',
2067
+ compute: {
2068
+ amount: 7.75,
2069
+ type: 'percentage',
2070
+ action: 'add',
2071
+ },
2072
+ properties: {
2073
+ sort: 2,
2074
+ },
2075
+ };
2076
+
2077
+ const item1 = {
2078
+ _id: 1,
2079
+ price: 38,
2080
+ quantity: 1,
2081
+ modifiers: [],
2082
+ };
2083
+ const item2 = {
2084
+ _id: 2,
2085
+ price: 42,
2086
+ quantity: 1,
2087
+ modifiers: [],
2088
+ };
2089
+ const item3 = {
2090
+ _id: 3,
2091
+ price: 48,
2092
+ quantity: 1,
2093
+ modifiers: [],
2094
+ };
2095
+
2096
+ const order = {
2097
+ items: [item1, item2, item3],
2098
+ modifiers: [taxMod],
2099
+ };
2100
+
2101
+ const newOrder = pricingService.order.calculate(order);
2102
+
2103
+ expect(newOrder).toHaveProperty('total', 137.92);
2104
+ expect(newOrder).toHaveProperty('subTotal', 128);
2105
+ expect(newOrder).toHaveProperty('subTotals', {
2106
+ tax: 9.92,
2107
+ });
2108
+ expect(newOrder.items[0]).toHaveProperty('total', 40.945);
2109
+ expect(newOrder.items[1]).toHaveProperty('total', 45.255);
2110
+ expect(newOrder.items[2]).toHaveProperty('total', 51.72);
2111
+ expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
2112
+ 'amount',
2113
+ 2.945
2114
+ );
2115
+
2116
+ expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
2117
+ 'amount',
2118
+ 3.255
2119
+ );
2120
+ expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
2121
+ 'amount',
2122
+ 3.72
2123
+ );
2124
+ });
@@ -98,7 +98,7 @@ module.exports = ({ _, utils, actions, modifierActions }) => {
98
98
 
99
99
  subTotals._actual = math.add(subTotals._simple, subTotals._included);
100
100
 
101
- const total = math.toDecimalPlaces(actions.getTotal({ subTotals }));
101
+ const total = actions.getTotal({ subTotals });
102
102
 
103
103
  return {
104
104
  ...item,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkpos/pricing",
3
- "version": "1.0.24",
3
+ "version": "1.0.25",
4
4
  "description": "Pricing calculator",
5
5
  "author": "Dark POS",
6
6
  "license": "ISC",
@@ -36,5 +36,5 @@
36
36
  "supertest": "^6.2.3",
37
37
  "supervisor": "^0.12.0"
38
38
  },
39
- "gitHead": "a5c31d32fc9c21bc3d643d02e1171438b38f6826"
39
+ "gitHead": "e8af4c6528df412d450ff6382f930723b32e6a1d"
40
40
  }