@darkpos/pricing 1.0.24 → 1.0.26
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 +357 -174
- package/lib/constants/Modifier/Types.js +1 -0
- package/lib/item/calculate.js +3 -2
- package/lib/modifier/calculate.js +3 -1
- package/lib/modifier/createDiscountModifier.js +4 -1
- package/lib/modifier/createFeeModifier.js +27 -0
- package/lib/modifier/createIndirectModifier.js +6 -1
- package/lib/modifier/index.js +9 -0
- package/lib/modifier/isAdd.js +10 -0
- package/lib/modifier/isFee.js +6 -0
- package/lib/modifier/isFixedAdd.js +4 -0
- package/lib/modifier/isFixedFee.js +4 -0
- package/package.json +2 -2
|
@@ -10,6 +10,7 @@ const orderModifiersPartiallyPaid = require('../mocks/partially-paid/order-modif
|
|
|
10
10
|
const inputItemsPartiallyPaidOrder = require('../mocks/partially-paid/input-items.json');
|
|
11
11
|
|
|
12
12
|
const orderCredit = require('../mocks/order-credit.json');
|
|
13
|
+
const { Types } = require('../../lib/constants/Modifier/Compute');
|
|
13
14
|
|
|
14
15
|
const session = {
|
|
15
16
|
store: mockStores[0],
|
|
@@ -124,7 +125,7 @@ describe('Order actions', () => {
|
|
|
124
125
|
expect(newOrder).toHaveProperty('subTotals', {
|
|
125
126
|
discount: -2,
|
|
126
127
|
});
|
|
127
|
-
expect(newOrder.items[0]).toHaveProperty('total', 58.
|
|
128
|
+
expect(newOrder.items[0]).toHaveProperty('total', 58.285714285714285);
|
|
128
129
|
expect(newOrder.items[0]).toHaveProperty('subTotals', {
|
|
129
130
|
discount: -1.7142857142857142,
|
|
130
131
|
_included: 0,
|
|
@@ -134,7 +135,7 @@ describe('Order actions', () => {
|
|
|
134
135
|
_simple: 60,
|
|
135
136
|
_actual: 60,
|
|
136
137
|
});
|
|
137
|
-
expect(newOrder.items[1]).toHaveProperty('total', 9.
|
|
138
|
+
expect(newOrder.items[1]).toHaveProperty('total', 9.714285714285714);
|
|
138
139
|
expect(newOrder.items[1]).toHaveProperty('subTotals', {
|
|
139
140
|
discount: -0.2857142857142857,
|
|
140
141
|
_included: 0,
|
|
@@ -173,7 +174,7 @@ describe('Order actions', () => {
|
|
|
173
174
|
expect(newOrder).toHaveProperty('subTotals', {
|
|
174
175
|
discount: -2.06,
|
|
175
176
|
});
|
|
176
|
-
expect(newOrder.items[0]).toHaveProperty('total', 14.
|
|
177
|
+
expect(newOrder.items[0]).toHaveProperty('total', 14.391);
|
|
177
178
|
expect(newOrder.items[0]).toHaveProperty('subTotals', {
|
|
178
179
|
discount: -1.599,
|
|
179
180
|
_included: 0,
|
|
@@ -183,7 +184,7 @@ describe('Order actions', () => {
|
|
|
183
184
|
_simple: 15.99,
|
|
184
185
|
_actual: 15.99,
|
|
185
186
|
});
|
|
186
|
-
expect(newOrder.items[1]).toHaveProperty('total', 4.
|
|
187
|
+
expect(newOrder.items[1]).toHaveProperty('total', 4.185);
|
|
187
188
|
expect(newOrder.items[1]).toHaveProperty('subTotals', {
|
|
188
189
|
discount: -0.465,
|
|
189
190
|
_included: 0,
|
|
@@ -682,9 +683,9 @@ describe('Order actions', () => {
|
|
|
682
683
|
discount: -16.41,
|
|
683
684
|
tax: 7.21,
|
|
684
685
|
});
|
|
685
|
-
expect(newOrder.items[0]).toHaveProperty('total', 80.
|
|
686
|
-
expect(newOrder.items[1]).toHaveProperty('total', 13.
|
|
687
|
-
expect(newOrder.items[2]).toHaveProperty('total', 5.
|
|
686
|
+
expect(newOrder.items[0]).toHaveProperty('total', 80.597);
|
|
687
|
+
expect(newOrder.items[1]).toHaveProperty('total', 13.69233125);
|
|
688
|
+
expect(newOrder.items[2]).toHaveProperty('total', 5.90739375);
|
|
688
689
|
expect(newOrder.items[0].modifiers[0].compute).toHaveProperty(
|
|
689
690
|
'amount',
|
|
690
691
|
13.2
|
|
@@ -700,7 +701,7 @@ describe('Order actions', () => {
|
|
|
700
701
|
);
|
|
701
702
|
expect(newOrder.items[1].modifiers[1].compute).toHaveProperty(
|
|
702
703
|
'amount',
|
|
703
|
-
0.
|
|
704
|
+
0.98483125
|
|
704
705
|
);
|
|
705
706
|
|
|
706
707
|
expect(newOrder.items[2].modifiers[0].compute).toHaveProperty(
|
|
@@ -709,7 +710,7 @@ describe('Order actions', () => {
|
|
|
709
710
|
);
|
|
710
711
|
expect(newOrder.items[2].modifiers[1].compute).toHaveProperty(
|
|
711
712
|
'amount',
|
|
712
|
-
0.
|
|
713
|
+
0.42489375
|
|
713
714
|
);
|
|
714
715
|
});
|
|
715
716
|
|
|
@@ -774,9 +775,9 @@ describe('Order actions', () => {
|
|
|
774
775
|
discount: -16.41,
|
|
775
776
|
tax: 7.21,
|
|
776
777
|
});
|
|
777
|
-
expect(newOrder.items[0]).toHaveProperty('total', 80.
|
|
778
|
-
expect(newOrder.items[1]).toHaveProperty('total', 13.
|
|
779
|
-
expect(newOrder.items[2]).toHaveProperty('total', 5.
|
|
778
|
+
expect(newOrder.items[0]).toHaveProperty('total', 80.597);
|
|
779
|
+
expect(newOrder.items[1]).toHaveProperty('total', 13.69233125);
|
|
780
|
+
expect(newOrder.items[2]).toHaveProperty('total', 5.90739375);
|
|
780
781
|
expect(newOrder.items[0].modifiers[0].compute).toHaveProperty(
|
|
781
782
|
'amount',
|
|
782
783
|
13.2
|
|
@@ -866,9 +867,9 @@ describe('Order actions', () => {
|
|
|
866
867
|
discount: -16.41,
|
|
867
868
|
tax: 7.21,
|
|
868
869
|
});
|
|
869
|
-
expect(newOrder.items[0]).toHaveProperty('total', 80.
|
|
870
|
-
expect(newOrder.items[1]).toHaveProperty('total', 13.
|
|
871
|
-
expect(newOrder.items[2]).toHaveProperty('total', 5.
|
|
870
|
+
expect(newOrder.items[0]).toHaveProperty('total', 80.597);
|
|
871
|
+
expect(newOrder.items[1]).toHaveProperty('total', 13.69233125);
|
|
872
|
+
expect(newOrder.items[2]).toHaveProperty('total', 5.90739375);
|
|
872
873
|
expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
|
|
873
874
|
'amount',
|
|
874
875
|
-13.2
|
|
@@ -958,9 +959,9 @@ describe('Order actions', () => {
|
|
|
958
959
|
discount: -16.41,
|
|
959
960
|
tax: 7.21,
|
|
960
961
|
});
|
|
961
|
-
expect(newOrder.items[0]).toHaveProperty('total', 80.
|
|
962
|
-
expect(newOrder.items[1]).toHaveProperty('total', 13.
|
|
963
|
-
expect(newOrder.items[2]).toHaveProperty('total', 5.
|
|
962
|
+
expect(newOrder.items[0]).toHaveProperty('total', 80.597);
|
|
963
|
+
expect(newOrder.items[1]).toHaveProperty('total', 13.69233125);
|
|
964
|
+
expect(newOrder.items[2]).toHaveProperty('total', 5.90739375);
|
|
964
965
|
expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
|
|
965
966
|
'amount',
|
|
966
967
|
-13.2
|
|
@@ -976,7 +977,7 @@ describe('Order actions', () => {
|
|
|
976
977
|
);
|
|
977
978
|
expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
|
|
978
979
|
'amount',
|
|
979
|
-
0.
|
|
980
|
+
0.98483125
|
|
980
981
|
);
|
|
981
982
|
|
|
982
983
|
expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
|
|
@@ -985,7 +986,7 @@ describe('Order actions', () => {
|
|
|
985
986
|
);
|
|
986
987
|
expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
|
|
987
988
|
'amount',
|
|
988
|
-
0.
|
|
989
|
+
0.42489375
|
|
989
990
|
);
|
|
990
991
|
});
|
|
991
992
|
|
|
@@ -1139,16 +1140,16 @@ describe('Order actions', () => {
|
|
|
1139
1140
|
fixed: -1,
|
|
1140
1141
|
tax: 0.16,
|
|
1141
1142
|
});
|
|
1142
|
-
expect(newOrder.items[0]).toHaveProperty('total', 0.
|
|
1143
|
-
expect(newOrder.items[1]).toHaveProperty('total', 0.
|
|
1144
|
-
expect(newOrder.items[2]).toHaveProperty('total', 0.
|
|
1143
|
+
expect(newOrder.items[0]).toHaveProperty('total', 0.7183333333333333);
|
|
1144
|
+
expect(newOrder.items[1]).toHaveProperty('total', 0.7183333333333334);
|
|
1145
|
+
expect(newOrder.items[2]).toHaveProperty('total', 0.7183333333333334);
|
|
1145
1146
|
expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
|
|
1146
1147
|
'amount',
|
|
1147
1148
|
-0.3333333333333334
|
|
1148
1149
|
);
|
|
1149
1150
|
expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
|
|
1150
1151
|
'amount',
|
|
1151
|
-
0.
|
|
1152
|
+
0.05166666666666666
|
|
1152
1153
|
);
|
|
1153
1154
|
|
|
1154
1155
|
expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
|
|
@@ -1157,7 +1158,7 @@ describe('Order actions', () => {
|
|
|
1157
1158
|
);
|
|
1158
1159
|
expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
|
|
1159
1160
|
'amount',
|
|
1160
|
-
0.
|
|
1161
|
+
0.05166666666666667
|
|
1161
1162
|
);
|
|
1162
1163
|
|
|
1163
1164
|
expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
|
|
@@ -1166,7 +1167,7 @@ describe('Order actions', () => {
|
|
|
1166
1167
|
);
|
|
1167
1168
|
expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
|
|
1168
1169
|
'amount',
|
|
1169
|
-
0.
|
|
1170
|
+
0.05166666666666667
|
|
1170
1171
|
);
|
|
1171
1172
|
});
|
|
1172
1173
|
|
|
@@ -1261,19 +1262,19 @@ describe('Order actions', () => {
|
|
|
1261
1262
|
|
|
1262
1263
|
const [item1, item2, item3] = newOrder.items;
|
|
1263
1264
|
expect(newOrder).toHaveProperty('total', 12.5);
|
|
1264
|
-
expect(item1).toHaveProperty('total', 3.
|
|
1265
|
+
expect(item1).toHaveProperty('total', 3.653846153846154);
|
|
1265
1266
|
expect(item1.modifiers[1].compute).toHaveProperty(
|
|
1266
1267
|
'amount',
|
|
1267
1268
|
5.846153846153846
|
|
1268
1269
|
);
|
|
1269
1270
|
|
|
1270
|
-
expect(item2).toHaveProperty('total', 5.
|
|
1271
|
+
expect(item2).toHaveProperty('total', 5.3846153846153854615384615385);
|
|
1271
1272
|
expect(item2.modifiers[1].compute).toHaveProperty(
|
|
1272
1273
|
'amount',
|
|
1273
1274
|
8.615384615384615
|
|
1274
1275
|
);
|
|
1275
1276
|
|
|
1276
|
-
expect(item3).toHaveProperty('total', 3.
|
|
1277
|
+
expect(item3).toHaveProperty('total', 3.461538461538462);
|
|
1277
1278
|
expect(item3.modifiers[1].compute).toHaveProperty(
|
|
1278
1279
|
'amount',
|
|
1279
1280
|
5.538461538461538
|
|
@@ -1611,10 +1612,10 @@ describe('Order actions', () => {
|
|
|
1611
1612
|
discount: -10,
|
|
1612
1613
|
fee: 2,
|
|
1613
1614
|
});
|
|
1614
|
-
expect(newOrder.items[0]).toHaveProperty('total', 8.
|
|
1615
|
-
expect(newOrder.items[1]).toHaveProperty('total', 7.
|
|
1616
|
-
expect(newOrder.items[2]).toHaveProperty('total', 11.
|
|
1617
|
-
expect(newOrder.items[3]).toHaveProperty('total', 7.
|
|
1615
|
+
expect(newOrder.items[0]).toHaveProperty('total', 8.074852767962309);
|
|
1616
|
+
expect(newOrder.items[1]).toHaveProperty('total', 7.709658421672556);
|
|
1617
|
+
expect(newOrder.items[2]).toHaveProperty('total', 11.361601884570083);
|
|
1618
|
+
expect(newOrder.items[3]).toHaveProperty('total', 7.303886925795053);
|
|
1618
1619
|
});
|
|
1619
1620
|
test('Get calculated PARTIALLY PAID Order, multiple items and paymentModifiers', () => {
|
|
1620
1621
|
const paymentModifiers = orderModifiersPartiallyPaid.map(orderMod =>
|
|
@@ -1639,10 +1640,10 @@ describe('Order actions', () => {
|
|
|
1639
1640
|
discount: -10,
|
|
1640
1641
|
fee: 4,
|
|
1641
1642
|
});
|
|
1642
|
-
expect(newOrder.items[0]).toHaveProperty('total', 8.
|
|
1643
|
-
expect(newOrder.items[1]).toHaveProperty('total', 7.
|
|
1644
|
-
expect(newOrder.items[2]).toHaveProperty('total', 11.
|
|
1645
|
-
expect(newOrder.items[3]).toHaveProperty('total', 9.
|
|
1643
|
+
expect(newOrder.items[0]).toHaveProperty('total', 8.083543307086615);
|
|
1644
|
+
expect(newOrder.items[1]).toHaveProperty('total', 7.703779527559055);
|
|
1645
|
+
expect(newOrder.items[2]).toHaveProperty('total', 11.36191226096738);
|
|
1646
|
+
expect(newOrder.items[3]).toHaveProperty('total', 9.300764904386952);
|
|
1646
1647
|
});
|
|
1647
1648
|
|
|
1648
1649
|
test('CU-8678p4ky3. Get Balance to Pay from OrderItems', () => {
|
|
@@ -1917,144 +1918,326 @@ describe('Order actions', () => {
|
|
|
1917
1918
|
|
|
1918
1919
|
expect(balanceToPay).toBe(102.79);
|
|
1919
1920
|
});
|
|
1920
|
-
});
|
|
1921
1921
|
|
|
1922
|
-
test('CU-8678p4ky3. Get Calculated order. Multiple Items. 2 Modifiers. 1 Item tax. 1 Orde discount', () => {
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1922
|
+
test('CU-8678p4ky3. Get Calculated order. Multiple Items. 2 Modifiers. 1 Item tax. 1 Orde discount', () => {
|
|
1923
|
+
const taxMod = {
|
|
1924
|
+
_id: 2,
|
|
1925
|
+
name: `7.75% tax`,
|
|
1926
|
+
type: 'tax',
|
|
1927
|
+
compute: {
|
|
1928
|
+
amount: 7.75,
|
|
1929
|
+
type: 'percentage',
|
|
1930
|
+
action: 'add',
|
|
1931
|
+
},
|
|
1932
|
+
properties: {
|
|
1933
|
+
sort: 2,
|
|
1934
|
+
},
|
|
1935
|
+
};
|
|
1936
|
+
|
|
1937
|
+
const discountMod = {
|
|
1938
|
+
_id: 1,
|
|
1939
|
+
compute: {
|
|
1940
|
+
amount: 15,
|
|
1941
|
+
type: 'percentage',
|
|
1942
|
+
action: 'subtract',
|
|
1943
|
+
},
|
|
1944
|
+
name: `15%`,
|
|
1941
1945
|
type: 'percentage',
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
1946
|
+
properties: {
|
|
1947
|
+
sort: 1,
|
|
1948
|
+
},
|
|
1949
|
+
};
|
|
1950
|
+
|
|
1951
|
+
const item1 = {
|
|
1952
|
+
_id: 1,
|
|
1953
|
+
price: 35.95,
|
|
1954
|
+
quantity: 2,
|
|
1955
|
+
modifiers: [taxMod],
|
|
1956
|
+
};
|
|
1957
|
+
const item2 = {
|
|
1958
|
+
_id: 2,
|
|
1959
|
+
price: 28.95,
|
|
1960
|
+
quantity: 2,
|
|
1961
|
+
modifiers: [taxMod],
|
|
1962
|
+
};
|
|
1963
|
+
const item3 = {
|
|
1964
|
+
_id: 3,
|
|
1965
|
+
price: 17.95,
|
|
1966
|
+
quantity: 4,
|
|
1967
|
+
modifiers: [taxMod],
|
|
1968
|
+
};
|
|
1969
|
+
const item4 = {
|
|
1970
|
+
_id: 4,
|
|
1971
|
+
price: 158,
|
|
1972
|
+
quantity: 1,
|
|
1973
|
+
modifiers: [taxMod],
|
|
1974
|
+
};
|
|
1975
|
+
const item5 = {
|
|
1976
|
+
_id: 5,
|
|
1977
|
+
price: 148,
|
|
1978
|
+
quantity: 2,
|
|
1979
|
+
modifiers: [taxMod],
|
|
1980
|
+
};
|
|
1981
|
+
const item6 = {
|
|
1982
|
+
_id: 6,
|
|
1983
|
+
price: 120,
|
|
1984
|
+
quantity: 1,
|
|
1985
|
+
modifiers: [taxMod],
|
|
1986
|
+
};
|
|
1987
|
+
|
|
1988
|
+
const order = {
|
|
1989
|
+
items: [item1, item2, item3, item4, item5, item6],
|
|
1990
|
+
modifiers: [discountMod],
|
|
1991
|
+
};
|
|
1992
|
+
|
|
1993
|
+
const newOrder = pricingService.order.calculate(order);
|
|
1994
|
+
|
|
1995
|
+
expect(newOrder).toHaveProperty('total', 710.35);
|
|
1996
|
+
expect(newOrder).toHaveProperty('subTotal', 775.6);
|
|
1997
|
+
expect(newOrder).toHaveProperty('subTotals', {
|
|
1998
|
+
percentage: -116.34,
|
|
1999
|
+
tax: 51.09,
|
|
2000
|
+
});
|
|
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
|
+
expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
|
|
2008
|
+
'amount',
|
|
2009
|
+
-10.785
|
|
2010
|
+
);
|
|
2011
|
+
expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
|
|
2012
|
+
'amount',
|
|
2013
|
+
4.7364125
|
|
2014
|
+
);
|
|
2015
|
+
|
|
2016
|
+
expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
|
|
2017
|
+
'amount',
|
|
2018
|
+
-8.685
|
|
2019
|
+
);
|
|
2020
|
+
expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
|
|
2021
|
+
'amount',
|
|
2022
|
+
3.8141625
|
|
2023
|
+
);
|
|
2024
|
+
|
|
2025
|
+
expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
|
|
2026
|
+
'amount',
|
|
2027
|
+
-10.77
|
|
2028
|
+
);
|
|
2029
|
+
expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
|
|
2030
|
+
'amount',
|
|
2031
|
+
4.729825
|
|
2032
|
+
);
|
|
2033
|
+
|
|
2034
|
+
expect(newOrder.items[3].modifiers[0]._computed).toHaveProperty(
|
|
2035
|
+
'amount',
|
|
2036
|
+
-23.7
|
|
2037
|
+
);
|
|
2038
|
+
expect(newOrder.items[3].modifiers[1]._computed).toHaveProperty(
|
|
2039
|
+
'amount',
|
|
2040
|
+
10.40825
|
|
2041
|
+
);
|
|
2042
|
+
|
|
2043
|
+
expect(newOrder.items[4].modifiers[0]._computed).toHaveProperty(
|
|
2044
|
+
'amount',
|
|
2045
|
+
-44.4
|
|
2046
|
+
);
|
|
2047
|
+
expect(newOrder.items[4].modifiers[1]._computed).toHaveProperty(
|
|
2048
|
+
'amount',
|
|
2049
|
+
19.499
|
|
2050
|
+
);
|
|
2051
|
+
|
|
2052
|
+
expect(newOrder.items[5].modifiers[0]._computed).toHaveProperty(
|
|
2053
|
+
'amount',
|
|
2054
|
+
-18
|
|
2055
|
+
);
|
|
2056
|
+
expect(newOrder.items[5].modifiers[1]._computed).toHaveProperty(
|
|
2057
|
+
'amount',
|
|
2058
|
+
7.905
|
|
2059
|
+
);
|
|
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
|
+
});
|
|
2125
|
+
|
|
2126
|
+
test('CU-86dtxh2y5: #1- Get calculated Order, One item and fixed Fee Modifier', () => {
|
|
2127
|
+
const newOrderFixedModifier = pricingService.order.calculate({
|
|
2128
|
+
items: [
|
|
2129
|
+
{
|
|
2130
|
+
_id: 1,
|
|
2131
|
+
price: 5,
|
|
2132
|
+
quantity: 2,
|
|
2133
|
+
},
|
|
2134
|
+
],
|
|
2135
|
+
modifiers: [
|
|
2136
|
+
{
|
|
2137
|
+
compute: {
|
|
2138
|
+
amount: 10,
|
|
2139
|
+
type: 'fixed',
|
|
2140
|
+
action: 'add',
|
|
2141
|
+
},
|
|
2142
|
+
name: 'fee 10 USD',
|
|
2143
|
+
type: 'fee',
|
|
2144
|
+
},
|
|
2145
|
+
],
|
|
2146
|
+
});
|
|
2147
|
+
expect(newOrderFixedModifier).toHaveProperty('total', 20);
|
|
2148
|
+
});
|
|
2149
|
+
|
|
2150
|
+
test('CU-86dtxh2y5: #2.A- Get calculated Order, One item and fixed Fee Modifier (ignoreQuantity: false)', () => {
|
|
2151
|
+
const newOrderFixedModifier = pricingService.order.calculate({
|
|
2152
|
+
items: [
|
|
2153
|
+
{
|
|
2154
|
+
_id: 1,
|
|
2155
|
+
price: 5,
|
|
2156
|
+
quantity: 2,
|
|
2157
|
+
modifiers: [
|
|
2158
|
+
{
|
|
2159
|
+
compute: {
|
|
2160
|
+
amount: 20,
|
|
2161
|
+
type: 'fixed',
|
|
2162
|
+
action: 'add',
|
|
2163
|
+
},
|
|
2164
|
+
name: 'fee 20 USD',
|
|
2165
|
+
type: 'fee',
|
|
2166
|
+
},
|
|
2167
|
+
],
|
|
2168
|
+
},
|
|
2169
|
+
],
|
|
2170
|
+
});
|
|
2171
|
+
expect(newOrderFixedModifier).toHaveProperty('total', 50);
|
|
2172
|
+
});
|
|
2173
|
+
|
|
2174
|
+
test('CU-86dtxh2y5: #2.B- Get calculated Order, One item and fixed Fee Modifier (ignoreQuantity: true)', () => {
|
|
2175
|
+
const newOrderFixedModifier = pricingService.order.calculate({
|
|
2176
|
+
items: [
|
|
2177
|
+
{
|
|
2178
|
+
_id: 1,
|
|
2179
|
+
price: 5,
|
|
2180
|
+
quantity: 2,
|
|
2181
|
+
modifiers: [
|
|
2182
|
+
{
|
|
2183
|
+
compute: {
|
|
2184
|
+
amount: 20,
|
|
2185
|
+
type: 'fixed',
|
|
2186
|
+
action: 'add',
|
|
2187
|
+
},
|
|
2188
|
+
name: 'fee 20 USD',
|
|
2189
|
+
type: 'fee',
|
|
2190
|
+
properties: {
|
|
2191
|
+
ignoreQuantity: true,
|
|
2192
|
+
},
|
|
2193
|
+
},
|
|
2194
|
+
],
|
|
2195
|
+
},
|
|
2196
|
+
],
|
|
2197
|
+
});
|
|
2198
|
+
expect(newOrderFixedModifier).toHaveProperty('total', 30);
|
|
2199
|
+
});
|
|
2200
|
+
|
|
2201
|
+
test('CU-86dtxh2y5: #3- Get calculated Order, One item and fixed Fee Modifier, using createFeeModifier', () => {
|
|
2202
|
+
const newOrderFixedModifier = pricingService.order.calculate({
|
|
2203
|
+
items: [
|
|
2204
|
+
{
|
|
2205
|
+
_id: 1,
|
|
2206
|
+
price: 10,
|
|
2207
|
+
quantity: 2,
|
|
2208
|
+
},
|
|
2209
|
+
],
|
|
2210
|
+
modifiers: [
|
|
2211
|
+
pricingService.modifier.createFeeModifier({
|
|
2212
|
+
amount: 100,
|
|
2213
|
+
type: Types.FIXED,
|
|
2214
|
+
}),
|
|
2215
|
+
],
|
|
2216
|
+
});
|
|
2217
|
+
|
|
2218
|
+
expect(newOrderFixedModifier).toHaveProperty('total', 120);
|
|
2219
|
+
});
|
|
2220
|
+
|
|
2221
|
+
test('CU-86dtxh2y5: #4- Get calculated Order, One item and fixed Fee Modifier, using createFeeModifier (ignoreQuantity: true)', () => {
|
|
2222
|
+
const newOrderFixedModifier = pricingService.order.calculate({
|
|
2223
|
+
items: [
|
|
2224
|
+
{
|
|
2225
|
+
_id: 1,
|
|
2226
|
+
price: 10,
|
|
2227
|
+
quantity: 2,
|
|
2228
|
+
},
|
|
2229
|
+
],
|
|
2230
|
+
modifiers: [
|
|
2231
|
+
pricingService.modifier.createFeeModifier({
|
|
2232
|
+
amount: 100,
|
|
2233
|
+
type: Types.FIXED,
|
|
2234
|
+
properties: {
|
|
2235
|
+
ignoreQuantity: true,
|
|
2236
|
+
},
|
|
2237
|
+
}),
|
|
2238
|
+
],
|
|
2239
|
+
});
|
|
2240
|
+
|
|
2241
|
+
expect(newOrderFixedModifier).toHaveProperty('total', 120);
|
|
2000
2242
|
});
|
|
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);
|
|
2007
|
-
expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
|
|
2008
|
-
'amount',
|
|
2009
|
-
-10.785
|
|
2010
|
-
);
|
|
2011
|
-
expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
|
|
2012
|
-
'amount',
|
|
2013
|
-
4.7364125
|
|
2014
|
-
);
|
|
2015
|
-
|
|
2016
|
-
expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
|
|
2017
|
-
'amount',
|
|
2018
|
-
-8.685
|
|
2019
|
-
);
|
|
2020
|
-
expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
|
|
2021
|
-
'amount',
|
|
2022
|
-
3.8141625
|
|
2023
|
-
);
|
|
2024
|
-
|
|
2025
|
-
expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
|
|
2026
|
-
'amount',
|
|
2027
|
-
-10.77
|
|
2028
|
-
);
|
|
2029
|
-
expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
|
|
2030
|
-
'amount',
|
|
2031
|
-
4.729825
|
|
2032
|
-
);
|
|
2033
|
-
|
|
2034
|
-
expect(newOrder.items[3].modifiers[0]._computed).toHaveProperty(
|
|
2035
|
-
'amount',
|
|
2036
|
-
-23.7
|
|
2037
|
-
);
|
|
2038
|
-
expect(newOrder.items[3].modifiers[1]._computed).toHaveProperty(
|
|
2039
|
-
'amount',
|
|
2040
|
-
10.40825
|
|
2041
|
-
);
|
|
2042
|
-
|
|
2043
|
-
expect(newOrder.items[4].modifiers[0]._computed).toHaveProperty(
|
|
2044
|
-
'amount',
|
|
2045
|
-
-44.4
|
|
2046
|
-
);
|
|
2047
|
-
expect(newOrder.items[4].modifiers[1]._computed).toHaveProperty(
|
|
2048
|
-
'amount',
|
|
2049
|
-
19.499
|
|
2050
|
-
);
|
|
2051
|
-
|
|
2052
|
-
expect(newOrder.items[5].modifiers[0]._computed).toHaveProperty(
|
|
2053
|
-
'amount',
|
|
2054
|
-
-18
|
|
2055
|
-
);
|
|
2056
|
-
expect(newOrder.items[5].modifiers[1]._computed).toHaveProperty(
|
|
2057
|
-
'amount',
|
|
2058
|
-
7.905
|
|
2059
|
-
);
|
|
2060
2243
|
});
|
package/lib/item/calculate.js
CHANGED
|
@@ -73,7 +73,8 @@ module.exports = ({ _, utils, actions, modifierActions }) => {
|
|
|
73
73
|
let computedAmount =
|
|
74
74
|
_modifier.compute.type === 'percentage' ||
|
|
75
75
|
modifierActions.isIgnoreQuantity(_modifier) ||
|
|
76
|
-
|
|
76
|
+
(!modifierActions.isFixedAdd(_modifier) &&
|
|
77
|
+
math.gt(math.abs(computedAmountCalc), computedPriceCalc))
|
|
77
78
|
? _computed.amount
|
|
78
79
|
: computedAmountCalc;
|
|
79
80
|
|
|
@@ -98,7 +99,7 @@ module.exports = ({ _, utils, actions, modifierActions }) => {
|
|
|
98
99
|
|
|
99
100
|
subTotals._actual = math.add(subTotals._simple, subTotals._included);
|
|
100
101
|
|
|
101
|
-
const total =
|
|
102
|
+
const total = actions.getTotal({ subTotals });
|
|
102
103
|
|
|
103
104
|
return {
|
|
104
105
|
...item,
|
|
@@ -19,7 +19,9 @@ module.exports = ({ _, constants, utils, localization, actions }) => {
|
|
|
19
19
|
const maxAmountProp = actions.getProperty(modifier, 'maxAmount');
|
|
20
20
|
|
|
21
21
|
if (!options.skip) {
|
|
22
|
-
const maxAmountCalc =
|
|
22
|
+
const maxAmountCalc = actions.isFixedAdd(modifier)
|
|
23
|
+
? amount
|
|
24
|
+
: math.mul(options.price, options.quantity);
|
|
23
25
|
|
|
24
26
|
const maxAmount = maxAmountProp
|
|
25
27
|
? math.min(maxAmountProp, maxAmountCalc)
|
|
@@ -2,7 +2,7 @@ module.exports = ({ constants, actions, localization }) => {
|
|
|
2
2
|
const { Modifier } = constants;
|
|
3
3
|
|
|
4
4
|
return function createDiscountModifier(params) {
|
|
5
|
-
const { amount, type } = params;
|
|
5
|
+
const { amount, type, properties } = params;
|
|
6
6
|
const { formatAmount } = localization;
|
|
7
7
|
|
|
8
8
|
const name =
|
|
@@ -18,6 +18,9 @@ module.exports = ({ constants, actions, localization }) => {
|
|
|
18
18
|
},
|
|
19
19
|
type: Modifier.Types.DISCOUNT,
|
|
20
20
|
name: `${name} ${Modifier.Types.DISCOUNT}`,
|
|
21
|
+
properties: {
|
|
22
|
+
...properties,
|
|
23
|
+
},
|
|
21
24
|
});
|
|
22
25
|
};
|
|
23
26
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module.exports = ({ constants, actions, localization }) => {
|
|
2
|
+
const { Modifier } = constants;
|
|
3
|
+
|
|
4
|
+
return function createFeeModifier(params) {
|
|
5
|
+
const { amount, type, properties } = params;
|
|
6
|
+
const { formatAmount } = localization;
|
|
7
|
+
|
|
8
|
+
const name =
|
|
9
|
+
type === Modifier.Compute.Types.PERCENTAGE
|
|
10
|
+
? `${amount}%`
|
|
11
|
+
: `${formatAmount(amount)}`;
|
|
12
|
+
|
|
13
|
+
return actions.create({
|
|
14
|
+
compute: {
|
|
15
|
+
action: Modifier.Compute.Actions.ADD,
|
|
16
|
+
amount,
|
|
17
|
+
type,
|
|
18
|
+
},
|
|
19
|
+
type: Modifier.Types.FEE,
|
|
20
|
+
name: `${name} ${Modifier.Types.FEE}`,
|
|
21
|
+
properties: {
|
|
22
|
+
ignoreQuantity: true,
|
|
23
|
+
...properties,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
};
|
|
@@ -35,10 +35,15 @@ module.exports = ({ _, utils, constants, actions }) => {
|
|
|
35
35
|
!math.isZero(options.orderTotal) &&
|
|
36
36
|
(type !== Modifier.Compute.Types.PERCENTAGE || modifier.type === 'credit')
|
|
37
37
|
) {
|
|
38
|
+
const modififierQuantity =
|
|
39
|
+
modifier.properties && modifier.properties.ignoreQuantity
|
|
40
|
+
? 1
|
|
41
|
+
: options.itemQuantity;
|
|
42
|
+
|
|
38
43
|
amountToApply = math.div(
|
|
39
44
|
math.mul(modifierAmount, options.itemTotal),
|
|
40
45
|
options.orderTotal,
|
|
41
|
-
|
|
46
|
+
modififierQuantity
|
|
42
47
|
);
|
|
43
48
|
}
|
|
44
49
|
|
package/lib/modifier/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const create = require('./create');
|
|
|
8
8
|
const createAmountOverrideModifier = require('./createAmountOverrideModifier');
|
|
9
9
|
const createCreditModifier = require('./createCreditModifier');
|
|
10
10
|
const createDiscountModifier = require('./createDiscountModifier');
|
|
11
|
+
const createFeeModifier = require('./createFeeModifier');
|
|
11
12
|
const createGroupValuesModifier = require('./createGroupValuesModifier');
|
|
12
13
|
const createIndirectModifier = require('./createIndirectModifier');
|
|
13
14
|
const createSubscriptionModifier = require('./createSubscriptionModifier');
|
|
@@ -120,6 +121,10 @@ const isPaymentModifier = require('./isPaymentModifier');
|
|
|
120
121
|
const createPaymentModifier = require('./createPaymentModifier');
|
|
121
122
|
const isSubtract = require('./isSubtract');
|
|
122
123
|
const isFixed = require('./isFixed');
|
|
124
|
+
const isFixedAdd = require('./isFixedAdd');
|
|
125
|
+
const isFee = require('./isFee');
|
|
126
|
+
const isAdd = require('./isAdd');
|
|
127
|
+
|
|
123
128
|
const isFixedDiscount = require('./isFixedDiscount');
|
|
124
129
|
const removeLocked = require('./removeLocked');
|
|
125
130
|
const hasItems = require('./hasItems');
|
|
@@ -143,6 +148,7 @@ const modifierActions = (deps = {}) => {
|
|
|
143
148
|
createAmountOverrideModifier: createAmountOverrideModifier(innerDeps),
|
|
144
149
|
createCreditModifier: createCreditModifier(innerDeps),
|
|
145
150
|
createDiscountModifier: createDiscountModifier(innerDeps),
|
|
151
|
+
createFeeModifier: createFeeModifier(innerDeps),
|
|
146
152
|
createGroupValuesModifier: createGroupValuesModifier(innerDeps),
|
|
147
153
|
createIndirectModifier: createIndirectModifier(innerDeps),
|
|
148
154
|
createSubscriptionModifier: createSubscriptionModifier(innerDeps),
|
|
@@ -260,6 +266,9 @@ const modifierActions = (deps = {}) => {
|
|
|
260
266
|
removeLocked: removeLocked(innerDeps),
|
|
261
267
|
hasItems: hasItems(innerDeps),
|
|
262
268
|
getLockedModifiers: getLockedModifiers(innerDeps),
|
|
269
|
+
isFixedAdd: isFixedAdd(innerDeps),
|
|
270
|
+
isFee: isFee(innerDeps),
|
|
271
|
+
isAdd: isAdd(innerDeps),
|
|
263
272
|
});
|
|
264
273
|
|
|
265
274
|
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.26",
|
|
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": "
|
|
39
|
+
"gitHead": "bc31fb0ba85c5eba20c2d0df28ac5f858566372c"
|
|
40
40
|
}
|