Skip to content

Commit ae7e020

Browse files
committed
Merge branch 'ACP2E-2651' of https://github.com/magento-l3/magento2ce into Tier4-PR-01-02-2024
2 parents bfea788 + bbd1d12 commit ae7e020

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

app/code/Magento/Weee/Model/Total/Invoice/Weee.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class Weee extends \Magento\Sales\Model\Order\Invoice\Total\AbstractTotal
1313
{
1414
/**
15-
* Weee data
15+
* Weee data object
1616
*
1717
* @var WeeeHelper
1818
*/
@@ -174,6 +174,18 @@ public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
174174
$baseTotalWeeeAmountInclTax += $baseWeeeAmountInclTax;
175175
}
176176

177+
// If FPT is configured to be included in the subtotal,
178+
// we need to subtract it from the subtotal and the grand total,
179+
// as Collect function from Catalog module knows nothing about FPT and that it is already included in Subtotal
180+
if ($invoice->isLast() && $this->_weeeData->includeInSubtotal($store)) {
181+
$invoice->setSubtotal($invoice->getSubtotal() - $totalWeeeAmount);
182+
$invoice->setBaseSubtotal($invoice->getBaseSubtotal() - $baseTotalWeeeAmount);
183+
$invoice->setGrandTotal($invoice->getGrandTotal() - $totalWeeeAmountInclTax);
184+
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $baseTotalWeeeAmountInclTax);
185+
$invoice->setTaxAmount($invoice->getTaxAmount() - $totalWeeeTaxAmount);
186+
$invoice->setBaseTaxAmount($invoice->getBaseTaxAmount() - $baseTotalWeeeTaxAmount);
187+
}
188+
177189
$allowedTax = $order->getTaxAmount() - $order->getTaxInvoiced() - $invoice->getTaxAmount();
178190
$allowedBaseTax = $order->getBaseTaxAmount() - $order->getBaseTaxInvoiced() - $invoice->getBaseTaxAmount();
179191
$totalWeeeTaxAmount = min($totalWeeeTaxAmount, $allowedTax);
@@ -196,15 +208,9 @@ public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
196208
$invoice->setBaseSubtotal($invoice->getBaseSubtotal() + $baseTotalWeeeAmount);
197209
}
198210

199-
if (!$invoice->isLast()) {
200211
// need to add the Weee amounts including all their taxes
201212
$invoice->setSubtotalInclTax($invoice->getSubtotalInclTax() + $totalWeeeAmountInclTax);
202213
$invoice->setBaseSubtotalInclTax($invoice->getBaseSubtotalInclTax() + $baseTotalWeeeAmountInclTax);
203-
} else {
204-
// since the Subtotal Incl Tax line will already have the taxes on Weee, just add the non-taxable amounts
205-
$invoice->setSubtotalInclTax($invoice->getSubtotalInclTax() + $totalWeeeAmount);
206-
$invoice->setBaseSubtotalInclTax($invoice->getBaseSubtotalInclTax() + $baseTotalWeeeAmount);
207-
}
208214

209215
$invoice->setGrandTotal($invoice->getGrandTotal() + $totalWeeeAmount + $totalWeeeTaxAmount);
210216
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseTotalWeeeAmount + $baseTotalWeeeTaxAmount);

app/code/Magento/Weee/Test/Unit/Model/Total/Invoice/WeeeTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function testCollect($orderData, $invoiceData, $expectedResults)
115115
$this->setupOrder($orderData);
116116

117117
//Set up weeeData mock
118-
$this->weeeData->expects($this->once())
118+
$this->weeeData->expects($this->atLeastOnce())
119119
->method('includeInSubtotal')
120120
->willReturn($invoiceData['include_in_subtotal']);
121121

@@ -284,8 +284,8 @@ public function collectDataProvider()
284284
'base_tax_amount' => 16.09,
285285
'subtotal' => 300,
286286
'base_subtotal' => 300,
287-
'subtotal_incl_tax' => 344.85,
288-
'base_subtotal_incl_tax' => 344.85,
287+
'subtotal_incl_tax' => 347.32,
288+
'base_subtotal_incl_tax' => 347.32,
289289
],
290290
],
291291
];
@@ -590,8 +590,8 @@ public function collectDataProvider()
590590
'base_tax_amount' => 4.95,
591591
'subtotal' => 100,
592592
'base_subtotal' => 100,
593-
'subtotal_incl_tax' => 114.95,
594-
'base_subtotal_incl_tax' => 114.95,
593+
'subtotal_incl_tax' => 115.77,
594+
'base_subtotal_incl_tax' => 115.77,
595595
],
596596
],
597597
];

0 commit comments

Comments
 (0)