Skip to content

Commit 8d10356

Browse files
committed
MAGETWO-53366: Tax Report does not display any records
- adding extension attribute instead of modifying data interface on api - fixing tests
1 parent 41de3eb commit 8d10356

File tree

6 files changed

+183
-90
lines changed

6 files changed

+183
-90
lines changed

app/code/Magento/Tax/Api/Data/OrderTaxDetailsAppliedTaxInterface.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,6 @@ public function getBaseAmount();
8888
*/
8989
public function setBaseAmount($baseAmount);
9090

91-
/**
92-
*
93-
* @return \Magento\Tax\Api\Data\AppliedTaxRateInterface[]
94-
*/
95-
public function getRates();
96-
97-
/**
98-
*
99-
* @param \Magento\Tax\Api\Data\AppliedTaxRateInterface[] $rates
100-
* @return $this
101-
*/
102-
public function setRates($rates);
103-
10491
/**
10592
* Retrieve existing extension attributes object or create a new one.
10693
*

app/code/Magento/Tax/Model/Plugin/OrderSave.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ protected function saveOrderTax(\Magento\Sales\Api\Data\OrderInterface $order)
7878
$ratesIdQuoteItemId = [];
7979
foreach ($taxesForItems as $taxesArray) {
8080
foreach ($taxesArray['applied_taxes'] as $rates) {
81-
if (count($rates['rates']) == 1) {
81+
/** @var \Magento\Tax\Api\Data\AppliedTaxRateInterface $rates */
82+
$taxRates = $rates['extension_attributes']->getRates();
83+
if (count($taxRates) == 1) {
8284
$ratesIdQuoteItemId[$rates['id']][] = [
8385
'id' => $taxesArray['item_id'],
8486
'percent' => $rates['percent'],
85-
'code' => $rates['rates'][0]['code'],
87+
'code' => $taxRates[0]['code'],
8688
'associated_item_id' => $taxesArray['associated_item_id'],
8789
'item_type' => $taxesArray['type'],
8890
'amount' => $rates['amount'],
@@ -92,7 +94,7 @@ protected function saveOrderTax(\Magento\Sales\Api\Data\OrderInterface $order)
9294
];
9395
} else {
9496
$percentSum = 0;
95-
foreach ($rates['rates'] as $rate) {
97+
foreach ($taxRates as $rate) {
9698
$realAmount = $rates['amount'] * $rate['percent'] / $rates['percent'];
9799
$realBaseAmount = $rates['base_amount'] * $rate['percent'] / $rates['percent'];
98100
$ratesIdQuoteItemId[$rates['id']][] = [
@@ -114,7 +116,8 @@ protected function saveOrderTax(\Magento\Sales\Api\Data\OrderInterface $order)
114116

115117
foreach ($taxes as $row) {
116118
$id = $row['id'];
117-
foreach ($row['rates'] as $tax) {
119+
$taxRates = $row['extension_attributes']->getRates();
120+
foreach ($taxRates as $tax) {
118121
if ($row['percent'] == null) {
119122
$baseRealAmount = $row['base_amount'];
120123
} else {

app/code/Magento/Tax/Model/Quote/ToOrderConverter.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public function afterConvert(QuoteAddressToOrder $subject, OrderInterface $order
5858
$extensionAttributes = $this->orderExtensionFactory->create();
5959
}
6060
if (!empty($taxes)) {
61+
foreach ($taxes as $key => $tax) {
62+
$tax['extension_attributes']['rates'] = $tax['rates'];
63+
unset($tax['rates']);
64+
$taxes[$key] = $tax;
65+
}
6166
$extensionAttributes->setAppliedTaxes($taxes);
6267
$extensionAttributes->setConvertingFromQuote(true);
6368
}
@@ -71,10 +76,10 @@ public function afterConvert(QuoteAddressToOrder $subject, OrderInterface $order
7176
$itemAppliedTaxesModified[$key]['type'] = $itemAppliedTax['item_type'];
7277
$itemAppliedTaxesModified[$key]['item_id'] = $itemAppliedTax['item_id'];
7378
$itemAppliedTaxesModified[$key]['associated_item_id'] = $itemAppliedTax['associated_item_id'];
79+
$itemAppliedTax['extension_attributes']['rates'] = $itemAppliedTax['rates'];
80+
unset($itemAppliedTax['rates']);
7481
$itemAppliedTaxesModified[$key]['applied_taxes'][] = $itemAppliedTax;
7582
}
76-
} elseif (is_array($itemAppliedTaxItem) && empty($itemAppliedTaxItem)) {
77-
$itemAppliedTaxesModified[$key] = [];
7883
}
7984
}
8085
$extensionAttributes->setItemAppliedTaxes($itemAppliedTaxesModified);

app/code/Magento/Tax/Test/Unit/Model/Plugin/OrderSaveTest.php

Lines changed: 109 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,101 @@ public function testAfterSave(
214214
*/
215215
public function afterSaveDataProvider()
216216
{
217+
$orderTaxDetailsApplied = $this->getMockBuilder('\Magento\Tax\Api\Data\OrderTaxDetailsAppliedTaxInterface')
218+
->disableOriginalConstructor()
219+
->setMethods(['getRates'])
220+
->getMockForAbstractClass();
221+
222+
$orderTaxDetailsApplied->expects($this->at(0))
223+
->method('getRates')
224+
->willReturn(
225+
[
226+
[
227+
'percent' => 6,
228+
'code' => 'IL',
229+
'title' => 'IL',
230+
],
231+
[
232+
'percent' => 5,
233+
'code' => 'US',
234+
'title' => 'US',
235+
]
236+
]
237+
);
238+
239+
$orderTaxDetailsApplied->expects($this->at(1))
240+
->method('getRates')
241+
->willReturn(
242+
[
243+
[
244+
'percent' => 3,
245+
'code' => 'CityTax',
246+
'title' => 'CityTax',
247+
],
248+
]
249+
);
250+
251+
252+
$orderTaxDetailsApplied->expects($this->at(2))
253+
->method('getRates')
254+
->willReturn(
255+
[
256+
[
257+
'percent' => 6,
258+
'code' => 'IL',
259+
'title' => 'IL',
260+
],
261+
[
262+
'percent' => 5,
263+
'code' => 'US',
264+
'title' => 'US',
265+
],
266+
]
267+
);
268+
269+
$orderTaxDetailsApplied->expects($this->at(3))
270+
->method('getRates')
271+
->willReturn(
272+
[
273+
[
274+
'percent' => 3,
275+
'code' => 'CityTax',
276+
'title' => 'CityTax',
277+
],
278+
]
279+
);
280+
281+
$orderTaxDetailsApplied->expects($this->at(4))
282+
->method('getRates')
283+
->willReturn(
284+
[
285+
[
286+
'percent' => 6,
287+
'code' => 'IL',
288+
'title' => 'IL',
289+
],
290+
[
291+
'percent' => 5,
292+
'code' => 'US',
293+
'title' => 'US',
294+
],
295+
]
296+
);
297+
298+
299+
300+
$orderTaxDetailsApplied->expects($this->at(5))
301+
->method('getRates')
302+
->willReturn(
303+
[
304+
[
305+
'percent' => 3,
306+
'code' => 'CityTax',
307+
'title' => 'CityTax',
308+
],
309+
]
310+
);
311+
217312
return [
218313
//one item with shipping
219314
//three tax rates: state and national tax rates of 6 and 5 percent with priority 0
@@ -225,31 +320,14 @@ public function afterSaveDataProvider()
225320
'base_amount' => 0.66,
226321
'percent' => 11,
227322
'id' => 'ILUS',
228-
'rates' => [
229-
[
230-
'percent' => 6,
231-
'code' => 'IL',
232-
'title' => 'IL',
233-
],
234-
[
235-
'percent' => 5,
236-
'code' => 'US',
237-
'title' => 'US',
238-
],
239-
],
323+
'extension_attributes' => $orderTaxDetailsApplied,
240324
],
241325
[
242326
'amount' => 0.2,
243327
'base_amount' => 0.2,
244328
'percent' => 3.33,
245329
'id' => 'CityTax',
246-
'rates' => [
247-
[
248-
'percent' => 3,
249-
'code' => 'CityTax',
250-
'title' => 'CityTax',
251-
],
252-
],
330+
'extension_attributes' => $orderTaxDetailsApplied,
253331
],
254332
],
255333
'item_applied_taxes' => [
@@ -261,36 +339,19 @@ public function afterSaveDataProvider()
261339
'associated_item_id' => null,
262340
'applied_taxes' => [
263341
[
264-
'amount' => 0.11,
265-
'base_amount' => 0.11,
266-
'percent' => 11,
267-
'id' => 'ILUS',
268-
'rates' => [
269-
[
270-
'percent' => 6,
271-
'code' => 'IL',
272-
'title' => 'IL',
273-
],
274-
[
275-
'percent' => 5,
276-
'code' => 'US',
277-
'title' => 'US',
278-
],
279-
],
342+
'amount' => 0.11,
343+
'base_amount' => 0.11,
344+
'percent' => 11,
345+
'id' => 'ILUS',
346+
'extension_attributes' => $orderTaxDetailsApplied,
280347
],
281348
//city tax
282349
[
283350
'amount' => 0.03,
284351
'base_amount' => 0.03,
285352
'percent' => 3.33,
286353
'id' => 'CityTax',
287-
'rates' => [
288-
[
289-
'percent' => 3,
290-
'code' => 'CityTax',
291-
'title' => 'CityTax',
292-
],
293-
]
354+
'extension_attributes' => $orderTaxDetailsApplied,
294355
],
295356
],
296357
],
@@ -302,36 +363,19 @@ public function afterSaveDataProvider()
302363
'associated_item_id' => null,
303364
'applied_taxes' => [
304365
[
305-
'amount' => 0.55,
306-
'base_amount' => 0.55,
307-
'percent' => 11,
308-
'id' => 'ILUS',
309-
'rates' => [
310-
[
311-
'percent' => 6,
312-
'code' => 'IL',
313-
'title' => 'IL',
314-
],
315-
[
316-
'percent' => 5,
317-
'code' => 'US',
318-
'title' => 'US',
319-
],
320-
],
366+
'amount' => 0.55,
367+
'base_amount' => 0.55,
368+
'percent' => 11,
369+
'id' => 'ILUS',
370+
'extension_attributes' => $orderTaxDetailsApplied,
321371
],
322372
//city tax
323373
[
324374
'amount' => 0.17,
325375
'base_amount' => 0.17,
326376
'percent' => 3.33,
327377
'id' => 'CityTax',
328-
'rates' => [
329-
[
330-
'percent' => 3,
331-
'code' => 'CityTax',
332-
'title' => 'CityTax',
333-
],
334-
],
378+
'extension_attributes' => $orderTaxDetailsApplied,
335379
],
336380
],
337381
],

0 commit comments

Comments
 (0)