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)
71
71
$ invoice ->setDiscountAmount (-$ totalDiscountAmount );
72
72
$ invoice ->setBaseDiscountAmount (-$ baseTotalDiscountAmount );
73
73
74
- $ grandTotal = $ invoice ->getGrandTotal () - $ totalDiscountAmount < 0.0001
74
+ $ grandTotal = abs ( $ invoice ->getGrandTotal () - $ totalDiscountAmount) < 0.0001
75
75
? 0 : $ invoice ->getGrandTotal () - $ totalDiscountAmount ;
76
- $ baseGrandTotal = $ invoice ->getBaseGrandTotal () - $ baseTotalDiscountAmount < 0.0001
76
+ $ baseGrandTotal = abs ( $ invoice ->getBaseGrandTotal () - $ baseTotalDiscountAmount) < 0.0001
77
77
? 0 : $ invoice ->getBaseGrandTotal () - $ baseTotalDiscountAmount ;
78
78
$ invoice ->setGrandTotal ($ grandTotal );
79
79
$ invoice ->setBaseGrandTotal ($ baseGrandTotal );
Original file line number Diff line number Diff line change @@ -98,6 +98,43 @@ public function testCollectInvoiceWithZeroGrandTotal(array $invoiceData): void
98
98
$ this ->model ->collect ($ this ->invoice );
99
99
}
100
100
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
+
101
138
/**
102
139
* @return array
103
140
*/
You can’t perform that action at this time.
0 commit comments