Skip to content

Commit ef4b4b5

Browse files
MAGETWO-69378: #4272: v2.0.4 Credit memos with adjustment fees cannot be fully refunded with a second credit memo #9715
2 parents 14b9b98 + ffea7c4 commit ef4b4b5

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

app/code/Magento/Sales/Model/Order.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,12 @@ public function canCreditmemo()
618618
* for this we have additional diapason for 0
619619
* TotalPaid - contains amount, that were not rounded.
620620
*/
621-
if (abs($this->priceCurrency->round($this->getTotalPaid()) - $this->getTotalRefunded()) < .0001) {
621+
$totalRefunded = $this->priceCurrency->round($this->getTotalPaid()) - $this->getTotalRefunded();
622+
if (abs($totalRefunded) < .0001) {
623+
return false;
624+
}
625+
// Case when Adjustment Fee (adjustment_negative) has been used for first creditmemo
626+
if (abs($totalRefunded - $this->getAdjustmentNegative()) < .0001) {
622627
return false;
623628
}
624629

app/code/Magento/Sales/Test/Unit/Model/OrderTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,34 @@ public function testCanNotCreditMemoWithTotalNull()
357357
$this->assertFalse($this->order->canCreditmemo());
358358
}
359359

360+
public function testCanNotCreditMemoWithAdjustmentNegative()
361+
{
362+
$totalPaid = 100;
363+
$adjustmentNegative = 10;
364+
$totalRefunded = 90;
365+
366+
$this->order->setTotalPaid($totalPaid);
367+
$this->order->setTotalRefunded($totalRefunded);
368+
$this->order->setAdjustmentNegative($adjustmentNegative);
369+
$this->priceCurrency->expects($this->once())->method('round')->with($totalPaid)->willReturnArgument(0);
370+
371+
$this->assertFalse($this->order->canCreditmemo());
372+
}
373+
374+
public function testCanCreditMemoWithAdjustmentNegativeLowerThanTotalPaid()
375+
{
376+
$totalPaid = 100;
377+
$adjustmentNegative = 9;
378+
$totalRefunded = 90;
379+
380+
$this->order->setTotalPaid($totalPaid);
381+
$this->order->setTotalRefunded($totalRefunded);
382+
$this->order->setAdjustmentNegative($adjustmentNegative);
383+
$this->priceCurrency->expects($this->once())->method('round')->with($totalPaid)->willReturnArgument(0);
384+
385+
$this->assertTrue($this->order->canCreditmemo());
386+
}
387+
360388
/**
361389
* @param string $state
362390
*

0 commit comments

Comments
 (0)