Skip to content

Commit 33473f6

Browse files
Chhandak.BaruaChhandak.Barua
authored andcommitted
ACP2E-707 Credit memo Refund Shipping (Incl. Tax) shows -0.01
1 parent 23f8aa5 commit 33473f6

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
6161
$baseAllowedAmountInclTaxDiff = $orderBaseShippingInclTax
6262
- $order->getBaseShippingRefunded()
6363
- $order->getBaseShippingTaxRefunded();
64-
$baseAllowedAmountInclTax = ($baseAllowedAmountInclTaxDiff > 0) ? $baseAllowedAmountInclTaxDiff : 0;
64+
$baseAllowedAmountInclTax = $this->getBaseAllowedAmountInclTax($baseAllowedAmountInclTaxDiff);
6565
// Check if the desired shipping amount to refund was specified (from invoice or another source).
6666
if ($creditmemo->hasBaseShippingAmount()) {
6767
// For the conditional logic, we will either use amounts that always include tax -OR- never include tax.
@@ -142,4 +142,15 @@ private function getTaxConfig()
142142
}
143143
return $this->taxConfig;
144144
}
145+
146+
/**
147+
* Get base allowed amount including Tax.
148+
*
149+
* @return float
150+
*
151+
*/
152+
private function getBaseAllowedAmountInclTax($baseAllowedAmountInclTaxDiff)
153+
{
154+
return ($baseAllowedAmountInclTaxDiff > 0) ? $baseAllowedAmountInclTaxDiff : 0;
155+
}
145156
}

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

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,4 +405,88 @@ public function testCollectUsingTaxInclShippingAmount()
405405

406406
$this->shippingCollector->collect($this->creditmemoMock);
407407
}
408+
/**
409+
* situation: The admin user did *not* specify any desired refund amount
410+
*
411+
* @throws LocalizedException
412+
*/
413+
public function testCollectRefundShippingAmountIncTax()
414+
{
415+
$orderShippingAmount = 7.2300;
416+
$orderShippingRefunded = 7.2300;
417+
$allowedShippingAmount = $orderShippingAmount - $orderShippingRefunded;
418+
$baseOrderShippingAmount = 7.9500;
419+
$baseOrderShippingRefunded = 7.2300;
420+
$baseAllowedShippingAmount = $baseOrderShippingAmount - $baseOrderShippingRefunded;
421+
$shippingTaxAmount = 0;
422+
$shippingTaxAmountRefunded = 7.9500;
423+
$baseShippingTaxAmount = 0;
424+
$baseShippingTaxAmountRefunded = 0.7300;
425+
426+
$expectedShippingAmountInclTax = $allowedShippingAmount + $shippingTaxAmount - $shippingTaxAmountRefunded;
427+
$expectedBaseShippingAmountInclTax =
428+
$baseAllowedShippingAmount + $baseShippingTaxAmount - $baseShippingTaxAmountRefunded;
429+
$grandTotalBefore = 14.35;
430+
$baseGrandTotalBefore = 14.35;
431+
$expectedGrandTotal = $grandTotalBefore + $allowedShippingAmount;
432+
$expectedBaseGrandTotal = $baseGrandTotalBefore + $baseAllowedShippingAmount;
433+
434+
$this->taxConfig->expects($this->any())->method('displaySalesShippingInclTax')->willReturn(false);
435+
436+
$order = new DataObject(
437+
[
438+
'shipping_amount' => $orderShippingAmount,
439+
'shipping_refunded' => $orderShippingRefunded,
440+
'base_shipping_amount' => $baseOrderShippingAmount,
441+
'base_shipping_refunded' => $baseOrderShippingRefunded,
442+
'shipping_incl_tax' => $orderShippingAmount + $shippingTaxAmount,
443+
'base_shipping_incl_tax' => $baseOrderShippingAmount + $baseShippingTaxAmount,
444+
'shipping_tax_amount' => $shippingTaxAmount,
445+
'shipping_tax_refunded' => $shippingTaxAmountRefunded,
446+
'base_shipping_tax_amount' => $baseShippingTaxAmount,
447+
'base_shipping_tax_refunded' => $baseShippingTaxAmountRefunded,
448+
]
449+
);
450+
451+
$this->creditmemoMock->expects($this->once())
452+
->method('getOrder')
453+
->willReturn($order);
454+
$this->creditmemoMock->expects($this->once())
455+
->method('hasBaseShippingAmount')
456+
->willReturn(false);
457+
$this->creditmemoMock->expects($this->once())
458+
->method('getGrandTotal')
459+
->willReturn($grandTotalBefore);
460+
$this->creditmemoMock->expects($this->once())
461+
->method('getBaseGrandTotal')
462+
->willReturn($baseGrandTotalBefore);
463+
464+
//verify
465+
$this->creditmemoMock->expects($this->once())
466+
->method('setShippingAmount')
467+
->with($allowedShippingAmount)
468+
->willReturnSelf();
469+
$this->creditmemoMock->expects($this->once())
470+
->method('setBaseShippingAmount')
471+
->with($baseAllowedShippingAmount)
472+
->willReturnSelf();
473+
$this->creditmemoMock->expects($this->once())
474+
->method('setShippingInclTax')
475+
->with($expectedShippingAmountInclTax)
476+
->willReturnSelf();
477+
$this->creditmemoMock->expects($this->once())
478+
->method('setBaseShippingInclTax')
479+
->with($this->shippingCollector->getBaseAllowedAmountInclTax($expectedBaseShippingAmountInclTax))
480+
->willReturnSelf();
481+
$this->creditmemoMock->expects($this->once())
482+
->method('setGrandTotal')
483+
->with($expectedGrandTotal)
484+
->willReturnSelf();
485+
$this->creditmemoMock->expects($this->once())
486+
->method('setBaseGrandTotal')
487+
->with($expectedBaseGrandTotal)
488+
->willReturnSelf();
489+
$this->assertEquals(0, $this->shippingCollector->getBaseAllowedAmountInclTax($expectedBaseShippingAmountInclTax));
490+
$this->shippingCollector->collect($this->creditmemoMock);
491+
}
408492
}

0 commit comments

Comments
 (0)