Skip to content

Commit 9487e74

Browse files
ENGCOM-5172: Show converted value for validateForRefund error message #22211
2 parents 6638187 + 8f075d7 commit 9487e74

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ protected function validateForRefund(\Magento\Sales\Api\Data\CreditmemoInterface
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()->getBaseCurrency()->formatTxt($baseAvailableRefund)
206206
)
207207
);
208208
}

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

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,14 @@ public function testRefundExpectsMoneyAvailableToReturn()
351351
$order->method('getBaseTotalPaid')
352352
->willReturn($baseTotalPaid);
353353
$baseAvailableRefund = $baseTotalPaid - $baseTotalRefunded;
354-
$order->method('formatPriceTxt')
354+
$baseCurrency = $this->createMock(\Magento\Directory\Model\Currency::class);
355+
$baseCurrency->expects($this->once())
356+
->method('formatTxt')
355357
->with($baseAvailableRefund)
356358
->willReturn($baseAvailableRefund);
359+
$order->expects($this->once())
360+
->method('getBaseCurrency')
361+
->willReturn($baseCurrency);
357362
$this->creditmemoService->refund($creditMemo, true);
358363
}
359364

@@ -369,4 +374,56 @@ public function testRefundDoNotExpectsId()
369374
$creditMemoMock->expects($this->once())->method('getId')->willReturn(444);
370375
$this->creditmemoService->refund($creditMemoMock, true);
371376
}
377+
378+
/**
379+
* @expectedExceptionMessage The most money available to refund is $1.00.
380+
* @expectedException \Magento\Framework\Exception\LocalizedException
381+
*/
382+
public function testMultiCurrencyRefundExpectsMoneyAvailableToReturn()
383+
{
384+
$baseGrandTotal = 10.00;
385+
$baseTotalRefunded = 9.00;
386+
$baseTotalPaid = 10;
387+
$grandTotal = 8.81;
388+
$totalRefunded = 7.929;
389+
$totalPaid = 8.81;
390+
391+
/** @var CreditmemoInterface|MockObject $creditMemo */
392+
$creditMemo = $this->getMockBuilder(CreditmemoInterface::class)
393+
->setMethods(['getId', 'getOrder'])
394+
->getMockForAbstractClass();
395+
$creditMemo->method('getId')
396+
->willReturn(null);
397+
/** @var Order|MockObject $order */
398+
$order = $this->getMockBuilder(Order::class)
399+
->disableOriginalConstructor()
400+
->getMock();
401+
$creditMemo->method('getOrder')
402+
->willReturn($order);
403+
$creditMemo->method('getBaseGrandTotal')
404+
->willReturn($baseGrandTotal);
405+
$creditMemo->method('getGrandTotal')
406+
->willReturn($grandTotal);
407+
$order->method('getBaseTotalRefunded')
408+
->willReturn($baseTotalRefunded);
409+
$order->method('getTotalRefunded')
410+
->willReturn($totalRefunded);
411+
$this->priceCurrency->method('round')
412+
->withConsecutive([$baseTotalRefunded + $baseGrandTotal], [$baseTotalPaid])
413+
->willReturnOnConsecutiveCalls($baseTotalRefunded + $baseGrandTotal, $baseTotalPaid);
414+
$order->method('getBaseTotalPaid')
415+
->willReturn($baseTotalPaid);
416+
$order->method('getTotalPaid')
417+
->willReturn($totalPaid);
418+
$baseAvailableRefund = $baseTotalPaid - $baseTotalRefunded;
419+
$baseCurrency = $this->createMock(\Magento\Directory\Model\Currency::class);
420+
$baseCurrency->expects($this->once())
421+
->method('formatTxt')
422+
->with($baseAvailableRefund)
423+
->willReturn(sprintf('$%.2f', $baseAvailableRefund));
424+
$order->expects($this->once())
425+
->method('getBaseCurrency')
426+
->willReturn($baseCurrency);
427+
$this->creditmemoService->refund($creditMemo, true);
428+
}
372429
}

0 commit comments

Comments
 (0)