Skip to content

Commit

Permalink
MAGETWO-69378: #4272: v2.0.4 Credit memos with adjustment fees cannot…
Browse files Browse the repository at this point in the history
… be fully refunded with a second credit memo #9715
  • Loading branch information
ishakhsuvarov authored May 26, 2017
2 parents 14b9b98 + ffea7c4 commit ef4b4b5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/code/Magento/Sales/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,12 @@ public function canCreditmemo()
* for this we have additional diapason for 0
* TotalPaid - contains amount, that were not rounded.
*/
if (abs($this->priceCurrency->round($this->getTotalPaid()) - $this->getTotalRefunded()) < .0001) {
$totalRefunded = $this->priceCurrency->round($this->getTotalPaid()) - $this->getTotalRefunded();
if (abs($totalRefunded) < .0001) {
return false;
}
// Case when Adjustment Fee (adjustment_negative) has been used for first creditmemo
if (abs($totalRefunded - $this->getAdjustmentNegative()) < .0001) {
return false;
}

Expand Down
28 changes: 28 additions & 0 deletions app/code/Magento/Sales/Test/Unit/Model/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,34 @@ public function testCanNotCreditMemoWithTotalNull()
$this->assertFalse($this->order->canCreditmemo());
}

public function testCanNotCreditMemoWithAdjustmentNegative()
{
$totalPaid = 100;
$adjustmentNegative = 10;
$totalRefunded = 90;

$this->order->setTotalPaid($totalPaid);
$this->order->setTotalRefunded($totalRefunded);
$this->order->setAdjustmentNegative($adjustmentNegative);
$this->priceCurrency->expects($this->once())->method('round')->with($totalPaid)->willReturnArgument(0);

$this->assertFalse($this->order->canCreditmemo());
}

public function testCanCreditMemoWithAdjustmentNegativeLowerThanTotalPaid()
{
$totalPaid = 100;
$adjustmentNegative = 9;
$totalRefunded = 90;

$this->order->setTotalPaid($totalPaid);
$this->order->setTotalRefunded($totalRefunded);
$this->order->setAdjustmentNegative($adjustmentNegative);
$this->priceCurrency->expects($this->once())->method('round')->with($totalPaid)->willReturnArgument(0);

$this->assertTrue($this->order->canCreditmemo());
}

/**
* @param string $state
*
Expand Down

0 comments on commit ef4b4b5

Please sign in to comment.