Skip to content

Commit 5b834a5

Browse files
author
Rafael Kassner
committed
Show converted value for validateForRefund error message
1 parent 5791131 commit 5b834a5

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

app/code/Magento/Sales/Model/Service/CreditmemoService.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,13 @@ protected function validateForRefund(\Magento\Sales\Api\Data\CreditmemoInterface
196196
$creditmemo->getOrder()->getBaseTotalRefunded() + $creditmemo->getBaseGrandTotal()
197197
);
198198
if ($baseOrderRefund > $this->priceCurrency->round($creditmemo->getOrder()->getBaseTotalPaid())) {
199-
$baseAvailableRefund = $creditmemo->getOrder()->getBaseTotalPaid()
200-
- $creditmemo->getOrder()->getBaseTotalRefunded();
199+
$availableRefund = $creditmemo->getOrder()->getTotalPaid()
200+
- $creditmemo->getOrder()->getTotalRefunded();
201201

202202
throw new \Magento\Framework\Exception\LocalizedException(
203203
__(
204204
'The most money available to refund is %1.',
205-
$creditmemo->getOrder()->formatPriceTxt($baseAvailableRefund)
205+
$creditmemo->getOrder()->formatPriceTxt($availableRefund)
206206
)
207207
);
208208
}

app/code/Magento/Sales/Test/Unit/Model/Service/CreditmemoServiceTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,20 +343,74 @@ public function testRefundExpectsMoneyAvailableToReturn()
343343
->willReturn($order);
344344
$creditMemo->method('getBaseGrandTotal')
345345
->willReturn($baseGrandTotal);
346+
$creditMemo->method('getGrandTotal')
347+
->willReturn($baseGrandTotal);
346348
$order->method('getBaseTotalRefunded')
347349
->willReturn($baseTotalRefunded);
350+
$order->method('getTotalRefunded')
351+
->willReturn($baseTotalRefunded);
348352
$this->priceCurrency->method('round')
349353
->withConsecutive([$baseTotalRefunded + $baseGrandTotal], [$baseTotalPaid])
350354
->willReturnOnConsecutiveCalls($baseTotalRefunded + $baseGrandTotal, $baseTotalPaid);
351355
$order->method('getBaseTotalPaid')
352356
->willReturn($baseTotalPaid);
357+
$order->method('getTotalPaid')
358+
->willReturn($baseTotalPaid);
353359
$baseAvailableRefund = $baseTotalPaid - $baseTotalRefunded;
354360
$order->method('formatPriceTxt')
355361
->with($baseAvailableRefund)
356362
->willReturn($baseAvailableRefund);
357363
$this->creditmemoService->refund($creditMemo, true);
358364
}
359365

366+
/**
367+
* @expectedExceptionMessage The most money available to refund is €0.88.
368+
* @expectedException \Magento\Framework\Exception\LocalizedException
369+
*/
370+
public function testMultiCurrencyRefundExpectsMoneyAvailableToReturn()
371+
{
372+
$baseGrandTotal = 10.00;
373+
$baseTotalRefunded = 9.00;
374+
$baseTotalPaid = 10;
375+
376+
$grandTotal = 8.81;
377+
$totalRefunded = 7.929;
378+
$totalPaid = 8.81;
379+
380+
/** @var CreditmemoInterface|MockObject $creditMemo */
381+
$creditMemo = $this->getMockBuilder(CreditmemoInterface::class)
382+
->setMethods(['getId', 'getOrder'])
383+
->getMockForAbstractClass();
384+
$creditMemo->method('getId')
385+
->willReturn(null);
386+
/** @var Order|MockObject $order */
387+
$order = $this->getMockBuilder(Order::class)
388+
->disableOriginalConstructor()
389+
->getMock();
390+
$creditMemo->method('getOrder')
391+
->willReturn($order);
392+
$creditMemo->method('getBaseGrandTotal')
393+
->willReturn($baseGrandTotal);
394+
$creditMemo->method('getGrandTotal')
395+
->willReturn($grandTotal);
396+
$order->method('getBaseTotalRefunded')
397+
->willReturn($baseTotalRefunded);
398+
$order->method('getTotalRefunded')
399+
->willReturn($totalRefunded);
400+
$this->priceCurrency->method('round')
401+
->withConsecutive([$baseTotalRefunded + $baseGrandTotal], [$baseTotalPaid])
402+
->willReturnOnConsecutiveCalls($baseTotalRefunded + $baseGrandTotal, $baseTotalPaid);
403+
$order->method('getBaseTotalPaid')
404+
->willReturn($baseTotalPaid);
405+
$order->method('getTotalPaid')
406+
->willReturn($totalPaid);
407+
$availableRefund = $totalPaid - $totalRefunded;
408+
$order->method('formatPriceTxt')
409+
->with($availableRefund)
410+
->willReturn(sprintf('€%.2f', $availableRefund));
411+
$this->creditmemoService->refund($creditMemo, true);
412+
}
413+
360414
/**
361415
* @expectedExceptionMessage We cannot register an existing credit memo.
362416
* @expectedException \Magento\Framework\Exception\LocalizedException

0 commit comments

Comments
 (0)