Skip to content

Commit 572309a

Browse files
author
Anna Bukatar
committed
ACP2E-889: Wrong value of grand total on order refunds which contain discount
1 parent 0117201 commit 572309a

File tree

2 files changed

+70
-4
lines changed
  • app/code/Magento/Sales

2 files changed

+70
-4
lines changed

app/code/Magento/Sales/Model/Order/Creditmemo/Total/Tax.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public function __construct(ResourceInvoice $resourceInvoice, array $data = [])
3131
}
3232

3333
/**
34-
* {@inheritdoc}
34+
* @inheritdoc
35+
*
3536
* @SuppressWarnings(PHPMD.NPathComplexity)
3637
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
3738
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -104,7 +105,9 @@ public function collect(Creditmemo $creditmemo)
104105
$baseShippingTaxAmount = $creditmemo->roundPrice($baseShippingTaxAmount, 'base');
105106
$totalDiscountTaxCompensation = $creditmemo->roundPrice($totalDiscountTaxCompensation);
106107
$baseTotalDiscountTaxCompensation = $creditmemo->roundPrice($baseTotalDiscountTaxCompensation, 'base');
107-
if ($taxFactor < 1 && $invoice->getShippingTaxAmount() > 0) {
108+
if ($taxFactor < 1 && $invoice->getShippingTaxAmount() > 0 ||
109+
($order->getShippingDiscountAmount() >= $order->getShippingAmount())
110+
) {
108111
$isPartialShippingRefunded = true;
109112
}
110113
$totalTax += $shippingTaxAmount;
@@ -136,7 +139,9 @@ public function collect(Creditmemo $creditmemo)
136139
$baseShippingDiscountTaxCompensationAmount,
137140
'base'
138141
);
139-
if ($part < 1 && $order->getShippingTaxAmount() > 0) {
142+
if ($part < 1 && ($order->getShippingTaxAmount() > 0 ||
143+
($order->getShippingDiscountAmount() >= $order->getShippingAmount()))
144+
) {
140145
$isPartialShippingRefunded = true;
141146
}
142147
} elseif ($shippingDelta == $creditmemo->getBaseShippingAmount()) {
@@ -187,7 +192,6 @@ public function collect(Creditmemo $creditmemo)
187192
$creditmemo->getBaseGrandTotal() + $baseTotalTax + $baseTotalDiscountTaxCompensation
188193
);
189194
return $this;
190-
191195
}
192196

193197
/**

app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Total/TaxTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,68 @@ public function collectDataProvider()
744744
],
745745
];
746746

747+
// scenario 7: 1 items, 1 invoiced, rowtotal of with 8.25 tax rate
748+
// shipping is partially returned
749+
$result['last_creditmemo_with_discount_for_entire_shipping_all_prices_including_tax'] = [
750+
'order_data' => [
751+
'data_fields' => [
752+
'shipping_tax_amount' => 0,
753+
'base_shipping_tax_amount' => 0,
754+
'shipping_discount_tax_compensation_amount' => 1.36,
755+
'base_shipping_discount_tax_compensation_amount' => 1.36,
756+
'tax_amount' => 1.22,
757+
'base_tax_amount' => 1.22,
758+
'tax_invoiced' => 1.22,
759+
'base_tax_invoiced' => 1.22,
760+
'shipping_amount' => 13.64,
761+
'shipping_discount_amount' => 15,
762+
'base_shipping_amount' => 13.64,
763+
'discount_tax_compensation_invoiced' => 1.73,
764+
'base_discount_tax_compensation_invoiced' => 1.73
765+
],
766+
],
767+
'creditmemo_data' => [
768+
'items' => [
769+
'item_1' => [
770+
'order_item' => [
771+
'qty_invoiced' => 1,
772+
'tax_invoiced' => 1.22,
773+
'base_tax_invoiced' => 1.22,
774+
'discount_tax_compensation_amount' => 1.73,
775+
'base_discount_tax_compensation_amount' => 1.73,
776+
'discount_tax_compensation_invoiced' => 1.73,
777+
'base_discount_tax_compensation_invoiced' => 1.73
778+
],
779+
'is_last' => true,
780+
'qty' => 1,
781+
],
782+
],
783+
'is_last' => true,
784+
'data_fields' => [
785+
'shipping_amount' => 0,
786+
'base_shipping_amount' => 0,
787+
'grand_total' => 10.45,
788+
'base_grand_total' => 10.45,
789+
'tax_amount' => 0,
790+
'base_tax_amount' => 0
791+
],
792+
],
793+
'expected_results' => [
794+
'creditmemo_items' => [
795+
'item_1' => [
796+
'tax_amount' => 1.22,
797+
'base_tax_amount' => 1.22,
798+
],
799+
],
800+
'creditmemo_data' => [
801+
'grand_total' => 13.4,
802+
'base_grand_total' => 13.4,
803+
'tax_amount' => 1.22,
804+
'base_tax_amount' => 1.22,
805+
],
806+
],
807+
];
808+
747809
return $result;
748810
}
749811

0 commit comments

Comments
 (0)