Skip to content

Commit 96da5d7

Browse files
author
Yu Tang
committed
Merge remote-tracking branch 'origin/FearlessKiwis-MAGETWO-18521-Incorrect-tax-calculation-with-discount2' into develop
2 parents dd76d3f + 1a43d6e commit 96da5d7

File tree

5 files changed

+86
-5
lines changed
  • app/code/Magento
    • Sales
      • Block/Adminhtml/Order/Create/Items
      • Test/Unit/Block/Adminhtml/Order/Create/Items
      • view/adminhtml/templates/order/create/items
    • Tax/view/adminhtml/templates/order/create/items/price
    • Weee/view/adminhtml/templates/order/create/items/price

5 files changed

+86
-5
lines changed

app/code/Magento/Sales/Block/Adminhtml/Order/Create/Items/Grid.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,12 @@ public function getSubtotalWithDiscount()
286286
{
287287
$address = $this->getQuoteAddress();
288288
if ($this->displayTotalsIncludeTax()) {
289-
return $address->getSubtotal() + $address->getTaxAmount() + $this->getDiscountAmount();
289+
return $address->getSubtotal()
290+
+ $address->getTaxAmount()
291+
+ $address->getDiscountAmount()
292+
+ $address->getHiddenTaxAmount();
290293
} else {
291-
return $address->getSubtotal() + $this->getDiscountAmount();
294+
return $address->getSubtotal() + $address->getDiscountAmount();
292295
}
293296
}
294297

app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/Create/Items/GridTest.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ public function testGetItemRowTotalHtml()
339339

340340
$this->assertEquals($html, $grid->getItemRowTotalHtml($this->itemMock));
341341
}
342+
342343
public function testGetItemRowTotalWithDiscountHtml()
343344
{
344345
$html = '$34.28';
@@ -360,4 +361,81 @@ public function testGetItemRowTotalWithDiscountHtml()
360361

361362
$this->assertEquals($html, $grid->getItemRowTotalWithDiscountHtml($this->itemMock));
362363
}
364+
365+
/**
366+
* @param array $orderData
367+
* @param bool $displayTotalsIncludeTax
368+
* @param float $expected
369+
* @dataProvider getSubtotalWithDiscountDataProvider
370+
*/
371+
public function testGetSubtotalWithDiscount($orderData, $displayTotalsIncludeTax, $expected)
372+
{
373+
$quoteAddressMock = $this->getMock(
374+
'\Magento\Quote\Model\Quote\Address',
375+
['getSubtotal', 'getTaxAmount','getHiddenTaxAmount','getDiscountAmount'],
376+
[],
377+
'',
378+
false
379+
);
380+
$gridMock = $this->getMock(
381+
'Magento\Sales\Block\Adminhtml\Order\Create\Items\Grid',
382+
['getQuoteAddress','displayTotalsIncludeTax'],
383+
[],
384+
'',
385+
false
386+
);
387+
388+
$gridMock->expects($this->any())->method('getQuoteAddress')
389+
->will($this->returnValue($quoteAddressMock));
390+
$gridMock->expects($this->any())->method('displayTotalsIncludeTax')
391+
->will($this->returnValue($displayTotalsIncludeTax));
392+
393+
$quoteAddressMock->expects($this->once())
394+
->method('getSubtotal')
395+
->will($this->returnValue($orderData['subTotal']));
396+
397+
$quoteAddressMock->expects($this->any())
398+
->method('getTaxAmount')
399+
->will($this->returnValue($orderData['taxAmount']));
400+
401+
$quoteAddressMock->expects($this->any())
402+
->method('getHiddenTaxAmount')
403+
->will($this->returnValue($orderData['hiddenTaxAmount']));
404+
405+
$quoteAddressMock->expects($this->once())
406+
->method('getDiscountAmount')
407+
->will($this->returnValue($orderData['discountAmount']));
408+
409+
$this->assertEquals($expected, $gridMock->getSubtotalWithDiscount());
410+
}
411+
412+
/**
413+
* @return array
414+
*/
415+
public function getSubtotalWithDiscountDataProvider()
416+
{
417+
$result = [];
418+
$result['displayTotalsIncludeTaxTrue'] = [
419+
'orderData' => [
420+
'subTotal' => 32.59,
421+
'taxAmount' => 8.2,
422+
'hiddenTaxAmount' => 1.72,
423+
'discountAmount' => -10.24
424+
],
425+
'displayTotalsIncludeTax'=> true,
426+
'expected' => 32.27
427+
];
428+
$result['displayTotalsIncludeTaxFalse'] = [
429+
'orderData' => [
430+
'subTotal' => 66.67,
431+
'taxAmount' => 20,
432+
'hiddenTaxAmount' => 8,
433+
'discountAmount' => -34.67
434+
],
435+
'displayTotalsIncludeTax'=> false,
436+
'expected' => 32
437+
];
438+
return $result;
439+
}
440+
363441
}

app/code/Magento/Sales/view/adminhtml/templates/order/create/items/grid.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<td class="col-price"><strong><?php echo $block->formatPrice($block->getDiscountAmount()) ?></strong></td>
6565
<td class="col-price"><strong>
6666
<?php
67-
echo $block->formatPrice($block->getSubtotal() + $block->getDiscountAmount());
67+
echo $block->formatPrice($block->getSubtotalWithDiscount());
6868
?></strong></td>
6969
<td colspan="2">&nbsp;</td>
7070
</tr>

app/code/Magento/Tax/view/adminhtml/templates/order/create/items/price/total.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ $_item = $block->getItem();
2626
<?php if ($block->displayBothPrices($block->getStore())): ?>
2727
<br /><span class="label"><?php echo __('Incl. Tax'); ?>:</span>
2828
<?php endif; ?>
29-
<?php $_incl = $_item->getPriceInclTax() * $_item->getQty() - $_item->getTotalDiscountAmount(); ?>
29+
<?php $_incl = $block->getTotalAmount($_item); ?>
3030
<?php echo $block->formatPrice($_incl) ?>
3131
<?php endif; ?>

app/code/Magento/Weee/view/adminhtml/templates/order/create/items/price/total.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ $_item = $block->getItem();
4646
<?php if ($block->displayBothPrices()): ?>
4747
<br /><span class="label"><?php echo __('Incl. Tax'); ?>:</span>
4848
<?php endif; ?>
49-
<?php $_incl = $block->getRowDisplayPriceInclTax() - $_item->getTotalDiscountAmount(); ?>
49+
<?php $_incl = $block->getTotalAmount($_item); ?>
5050
<?php echo $block->formatPrice(max(0, $_incl)) ?>
5151
<?php if ($this->helper('Magento\Weee\Helper\Data')->getApplied($_item)): ?>
5252
<br />

0 commit comments

Comments
 (0)