Skip to content

Commit 533ec2e

Browse files
author
Serhii Balko
committed
Merge remote-tracking branch 'origin/MC-41438' into 2.4-develop-pr57
2 parents 87ea7b0 + 6cd8e47 commit 533ec2e

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

app/code/Magento/Sales/Model/Order/Invoice/Total/Discount.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ public function collect(Invoice $invoice)
7171
$invoice->setDiscountAmount(-$totalDiscountAmount);
7272
$invoice->setBaseDiscountAmount(-$baseTotalDiscountAmount);
7373

74-
$grandTotal = $invoice->getGrandTotal() - $totalDiscountAmount < 0.0001
74+
$grandTotal = abs($invoice->getGrandTotal() - $totalDiscountAmount) < 0.0001
7575
? 0 : $invoice->getGrandTotal() - $totalDiscountAmount;
76-
$baseGrandTotal = $invoice->getBaseGrandTotal() - $baseTotalDiscountAmount < 0.0001
76+
$baseGrandTotal = abs($invoice->getBaseGrandTotal() - $baseTotalDiscountAmount) < 0.0001
7777
? 0 : $invoice->getBaseGrandTotal() - $baseTotalDiscountAmount;
7878
$invoice->setGrandTotal($grandTotal);
7979
$invoice->setBaseGrandTotal($baseGrandTotal);

app/code/Magento/Sales/Test/Unit/Model/Order/Invoice/Total/DiscountTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,43 @@ public function testCollectInvoiceWithZeroGrandTotal(array $invoiceData): void
9898
$this->model->collect($this->invoice);
9999
}
100100

101+
/**
102+
* Test for collect invoice with negative grand total
103+
*
104+
* @return void
105+
*/
106+
public function testCollectInvoiceWithNegativeGrandTotal(): void
107+
{
108+
$invoiceData = [
109+
'order_item' => [
110+
'qty_ordered' => 1,
111+
'discount_amount' => 25.34,
112+
'base_discount_amount' => 25.34,
113+
],
114+
'is_last' => true,
115+
'qty' => 1,
116+
];
117+
$invoiceItem[] = $this->getInvoiceItem($invoiceData);
118+
$this->invoice->method('getOrder')
119+
->willReturn($this->order);
120+
$this->order->method('getInvoiceCollection')
121+
->willReturn([]);
122+
$this->invoice->method('getAllItems')
123+
->willReturn($invoiceItem);
124+
$this->invoice->method('getGrandTotal')
125+
->willReturn(15.6801);
126+
$this->invoice->method('getBaseGrandTotal')
127+
->willReturn(15.6801);
128+
129+
$this->invoice->expects($this->exactly(1))
130+
->method('setGrandTotal')
131+
->with(-9.6599);
132+
$this->invoice->expects($this->exactly(1))
133+
->method('setBaseGrandTotal')
134+
->with(-9.6599);
135+
$this->model->collect($this->invoice);
136+
}
137+
101138
/**
102139
* @return array
103140
*/

0 commit comments

Comments
 (0)