@@ -108,6 +108,161 @@ public function testCollect()
108
108
);
109
109
}
110
110
111
+ /**
112
+ * Test taxes collection with full discount for quote.
113
+ *
114
+ * Test tax calculation with certain configuration and price calculation of items when the discount may be bigger than total
115
+ * This method will test the collector through $quote->collectTotals() method
116
+ *
117
+ * @see \Magento\SalesRule\Model\Utility::deltaRoundingFix
118
+ * @magentoDbIsolation enabled
119
+ * @magentoAppIsolation enabled
120
+ */
121
+ public function testFullDiscountWithDeltaRoundingFix ()
122
+ {
123
+ $ configData = array (
124
+ 'config_overrides ' =>
125
+ array (
126
+ 'tax/calculation/apply_after_discount ' => 0 ,
127
+ 'tax/calculation/discount_tax ' => 1 ,
128
+ 'tax/calculation/algorithm ' => 'ROW_BASE_CALCULATION ' ,
129
+ 'tax/classes/shipping_tax_class ' => SetupUtil::SHIPPING_TAX_CLASS ,
130
+ ),
131
+ 'tax_rate_overrides ' =>
132
+ array (
133
+ SetupUtil::TAX_RATE_TX => 18 ,
134
+ SetupUtil::TAX_RATE_SHIPPING => 0 ,
135
+ ),
136
+ 'tax_rule_overrides ' =>
137
+ array (
138
+ array (
139
+ 'code ' => 'Product Tax Rule ' ,
140
+ 'product_tax_class_ids ' =>
141
+ array (
142
+ SetupUtil::PRODUCT_TAX_CLASS_1
143
+ ),
144
+ ),
145
+ array (
146
+ 'code ' => 'Shipping Tax Rule ' ,
147
+ 'product_tax_class_ids ' =>
148
+ array (
149
+ SetupUtil::SHIPPING_TAX_CLASS
150
+ ),
151
+ 'tax_rate_ids ' =>
152
+ array (
153
+ SetupUtil::TAX_RATE_SHIPPING ,
154
+ ),
155
+ ),
156
+ ),
157
+ );
158
+
159
+ $ quoteData = array (
160
+ 'billing_address ' =>
161
+ array (
162
+ 'region_id ' => SetupUtil::REGION_TX ,
163
+ ),
164
+ 'shipping_address ' =>
165
+ array (
166
+ 'region_id ' => SetupUtil::REGION_TX ,
167
+ ),
168
+ 'items ' =>
169
+ [
170
+ [
171
+ 'sku ' => 'simple1 ' ,
172
+ 'price ' => 2542.37 ,
173
+ 'qty ' => 2 ,
174
+ ]
175
+ ],
176
+ 'shipping_method ' => 'free ' ,
177
+ 'shopping_cart_rules ' =>
178
+ array (
179
+ array (
180
+ 'discount_amount ' => 100 ,
181
+ ),
182
+ ),
183
+ );
184
+
185
+ $ expectedResults = array (
186
+ 'address_data ' =>
187
+ array (
188
+ 'subtotal ' => 5084.74 ,
189
+ 'base_subtotal ' => 5084.74 ,
190
+ 'subtotal_incl_tax ' => 5999.99 ,
191
+ 'base_subtotal_incl_tax ' => 5999.99 ,
192
+ 'tax_amount ' => 915.25 ,
193
+ 'base_tax_amount ' => 915.25 ,
194
+ 'shipping_amount ' => 0 ,
195
+ 'base_shipping_amount ' => 0 ,
196
+ 'shipping_incl_tax ' => 0 ,
197
+ 'base_shipping_incl_tax ' => 0 ,
198
+ 'shipping_tax_amount ' => 0 ,
199
+ 'base_shipping_tax_amount ' => 0 ,
200
+ 'discount_amount ' => -5999.99 ,
201
+ 'base_discount_amount ' => -5999.99 ,
202
+ 'discount_tax_compensation_amount ' => 0 ,
203
+ 'base_discount_tax_compensation_amount ' => 0 ,
204
+ 'shipping_discount_tax_compensation_amount ' => 0 ,
205
+ 'base_shipping_discount_tax_compensation_amount ' => 0 ,
206
+ 'grand_total ' => 0 ,
207
+ 'base_grand_total ' => 0 ,
208
+ 'applied_taxes ' =>
209
+ array (
210
+ SetupUtil::TAX_RATE_TX =>
211
+ array (
212
+ 'percent ' => 18 ,
213
+ 'amount ' => 915.25 ,
214
+ 'base_amount ' => 915.25 ,
215
+ 'rates ' =>
216
+ array (
217
+ array (
218
+ 'code ' => SetupUtil::TAX_RATE_TX ,
219
+ 'title ' => SetupUtil::TAX_RATE_TX ,
220
+ 'percent ' => 18 ,
221
+ ),
222
+ ),
223
+ )
224
+ ),
225
+ ),
226
+ 'items_data ' =>
227
+ array (
228
+ 'simple1 ' =>
229
+ array (
230
+ 'row_total ' => 5084.74 ,
231
+ 'base_row_total ' => 5084.74 ,
232
+ 'tax_percent ' => 18 ,
233
+ 'price ' => 2542.37 ,
234
+ 'base_price ' => 2542.37 ,
235
+ 'price_incl_tax ' => 3000 ,
236
+ 'base_price_incl_tax ' => 3000 ,
237
+ 'row_total_incl_tax ' => 5999.99 ,
238
+ 'base_row_total_incl_tax ' => 5999.99 ,
239
+ 'tax_amount ' => 915.25 ,
240
+ 'base_tax_amount ' => 915.25 ,
241
+ 'discount_amount ' => 5999.99 ,
242
+ 'base_discount_amount ' => 5999.99 ,
243
+ 'discount_percent ' => 100 ,
244
+ 'discount_tax_compensation_amount ' => 0 ,
245
+ 'base_discount_tax_compensation_amount ' => 0 ,
246
+ ),
247
+ ),
248
+ );
249
+
250
+ /** @var \Magento\Framework\ObjectManagerInterface $objectManager */
251
+ $ objectManager = Bootstrap::getObjectManager ();
252
+
253
+ //Setup tax configurations
254
+ $ this ->setupUtil = new SetupUtil ($ objectManager );
255
+ $ this ->setupUtil ->setupTax ($ configData );
256
+
257
+ $ quote = $ this ->setupUtil ->setupQuote ($ quoteData );
258
+
259
+ $ quote ->collectTotals ();
260
+
261
+ $ quoteAddress = $ quote ->getShippingAddress ();
262
+
263
+ $ this ->verifyResult ($ quoteAddress , $ expectedResults );
264
+ }
265
+
111
266
/**
112
267
* Verify fields in quote item
113
268
*
0 commit comments