Skip to content

Instantly share code, notes, and snippets.

@Frank-Magmodules
Created February 15, 2024 09:45
Show Gist options
  • Save Frank-Magmodules/facae84204be5301963b25fb233db78f to your computer and use it in GitHub Desktop.
Save Frank-Magmodules/facae84204be5301963b25fb233db78f to your computer and use it in GitHub Desktop.
733.diff
diff --git a/Model/OrderLines.php b/Model/OrderLines.php
index 5e98a29f..f1eaf9ef 100644
--- a/Model/OrderLines.php
+++ b/Model/OrderLines.php
@@ -16,7 +16,6 @@
use Magento\Sales\Api\Data\CreditmemoItemInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\Data\ShipmentInterface;
-use Magento\Sales\Api\Data\ShipmentItemInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\ResourceModel\Order\Handler\State;
use Mollie\Payment\Helper\General as MollieHelper;
@@ -219,7 +218,10 @@ public function getShipmentOrderLines(ShipmentInterface $shipment): array
if ($orderHasDiscount) {
$orderItem = $item->getOrderItem();
- $rowTotal = $orderItem->getBaseRowTotalInclTax() - $orderItem->getBaseDiscountAmount();
+ $rowTotal = $orderItem->getBaseRowTotal()
+ - $orderItem->getBaseDiscountAmount()
+ + $orderItem->getBaseTaxAmount()
+ + $orderItem->getBaseDiscountTaxCompensationAmount();
$line['amount'] = $this->mollieHelper->getAmountArray(
$order->getBaseCurrencyCode(),
@@ -288,10 +290,12 @@ public function getCreditmemoOrderLines(CreditmemoInterface $creditmemo, bool $a
];
if ($item->getBaseDiscountAmount()) {
- $line['amount'] = $this->mollieHelper->getAmountArray(
- $creditmemo->getBaseCurrencyCode(),
- $item->getBaseRowTotalInclTax() - $item->getBaseDiscountAmount()
- );
+ $rowTotal = $item->getBaseRowTotal()
+ - $item->getBaseDiscountAmount()
+ + $item->getBaseTaxAmount()
+ + $item->getBaseDiscountTaxCompensationAmount();
+
+ $line['amount'] = $this->mollieHelper->getAmountArray($creditmemo->getBaseCurrencyCode(), $rowTotal);
}
$orderLines[] = $line;
diff --git a/Test/Integration/Model/OrderLinesTest.php b/Test/Integration/Model/OrderLinesTest.php
index 1cf85952..7410cd21 100644
--- a/Test/Integration/Model/OrderLinesTest.php
+++ b/Test/Integration/Model/OrderLinesTest.php
@@ -57,8 +57,10 @@ public function testCreditmemoUsesTheDiscount()
/** @var CreditmemoItemInterface $creditmemoItem */
$creditmemoItem = $this->objectManager->create(CreditmemoItemInterface::class);
- $creditmemoItem->setBaseRowTotalInclTax(45);
+ $creditmemoItem->setBaseRowTotal(45); // 45 - 21% tax
+ $creditmemoItem->setBaseRowTotalInclTax(45 * 1.21);
$creditmemoItem->setBaseDiscountAmount(9);
+ $creditmemoItem->setBaseTaxAmount(7.56); // 21% tax
$creditmemoItem->setQty(1);
$creditmemoItem->setOrderItemId(999);
@@ -75,7 +77,7 @@ public function testCreditmemoUsesTheDiscount()
$this->assertCount(1, $result['lines']);
$line = $result['lines'][0];
- $this->assertEquals(36, $line['amount']['value']);
+ $this->assertEquals(45 - 9 + 7.56, $line['amount']['value']);
$this->assertEquals(1, $line['quantity']);
}
@@ -143,7 +145,9 @@ public function testGetShipmentOrderLinesAddsAnAmountWhenTheOrderHasAnDiscount()
/** @var OrderItemInterface $orderItem */
$orderItem = $item->getOrderItem();
- $orderItem->setBaseRowTotalInclTax(100);
+ $orderItem->setBaseRowTotal(100);
+ $orderItem->setBaseTaxAmount(21);
+ $orderItem->setBaseRowTotalInclTax(121);
$orderItem->setBaseDiscountAmount(30);
$orderItem->setQtyOrdered(10);
}
@@ -158,12 +162,13 @@ public function testGetShipmentOrderLinesAddsAnAmountWhenTheOrderHasAnDiscount()
$this->assertEquals('EUR', $result['lines'][0]['amount']['currency']);
// 100 euro subtotal
+ // 21 euro tax
// 30 discount
// 70 grand total
// 10 items = 10 euro each
// 2 items ordered
- // ((100 - 30) / 10) * 2 = 14
- $this->assertEquals(14, $result['lines'][0]['amount']['value']);
+ // ((100 + 21 - 30) / 10) * 2 = 14
+ $this->assertEquals(18.2, $result['lines'][0]['amount']['value']);
}
public function tearDownWithoutVoid()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment