File tree Expand file tree Collapse file tree 2 files changed +39
-2
lines changed
Model/Order/Invoice/Total
Test/Unit/Model/Order/Invoice/Total Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Original file line number Diff line number Diff 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 );
Original file line number Diff line number Diff 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 */
You can’t perform that action at this time.
0 commit comments