diff --git a/vendor/magento/module-sales/Model/Order/Creditmemo/Total/Tax.php b/vendor/magento/module-sales/Model/Order/Creditmemo/Total/Tax.php index e08ed2e2814a3..3193732f91adf 100644 --- a/vendor/magento/module-sales/Model/Order/Creditmemo/Total/Tax.php +++ b/vendor/magento/module-sales/Model/Order/Creditmemo/Total/Tax.php @@ -232,8 +232,10 @@ private function calculateAllowedTax(Creditmemo $creditMemo): float $invoice = $creditMemo->getInvoice(); $order = $creditMemo->getOrder(); if ($invoice!== null) { - $amount = $invoice->getTaxAmount() + $invoiceTaxAvailable = $invoice->getTaxAmount() - $this->calculateInvoiceRefundedAmount($invoice, CreditmemoInterface::TAX_AMOUNT); + $orderTaxAvailable = $order->getTaxInvoiced() - $order->getTaxRefunded(); + $amount = min($invoiceTaxAvailable, $orderTaxAvailable); } else { $amount = $order->getTaxInvoiced() - $order->getTaxRefunded(); } @@ -253,8 +255,10 @@ private function calculateAllowedBaseTax(Creditmemo $creditMemo): float $order = $creditMemo->getOrder(); if ($invoice!== null) { - $amount = $invoice->getBaseTaxAmount() + $invoiceTaxAvailable = $invoice->getBaseTaxAmount() - $this->calculateInvoiceRefundedAmount($invoice, CreditmemoInterface::BASE_TAX_AMOUNT); + $orderTaxAvailable = $order->getBaseTaxInvoiced() - $order->getBaseTaxRefunded(); + $amount = min($invoiceTaxAvailable, $orderTaxAvailable); } else { $amount = $order->getBaseTaxInvoiced() - $order->getBaseTaxRefunded(); } @@ -274,7 +278,7 @@ private function calculateAllowedDiscountTaxCompensation(Creditmemo $creditMemo) $order = $creditMemo->getOrder(); if ($invoice) { - $amount = $invoice->getDiscountTaxCompensationAmount() + $invoiceAmount = $invoice->getDiscountTaxCompensationAmount() + $invoice->getShippingDiscountTaxCompensationAmount() - $this->calculateInvoiceRefundedAmount( $invoice, @@ -283,6 +287,11 @@ private function calculateAllowedDiscountTaxCompensation(Creditmemo $creditMemo) $invoice, CreditmemoInterface::SHIPPING_DISCOUNT_TAX_COMPENSATION_AMOUNT ); + $orderAmount = $order->getDiscountTaxCompensationInvoiced() + + $order->getShippingDiscountTaxCompensationAmount() + - $order->getDiscountTaxCompensationRefunded() + - $order->getShippingDiscountTaxCompensationRefunded(); + $amount = min($invoiceAmount, $orderAmount); } else { $amount = $order->getDiscountTaxCompensationInvoiced() + $order->getShippingDiscountTaxCompensationAmount() @@ -307,7 +316,7 @@ private function calculateAllowedBaseDiscountTaxCompensation(Creditmemo $creditM $order = $creditMemo->getOrder(); if ($invoice) { - $amount = $invoice->getBaseDiscountTaxCompensationAmount() + $invoiceAmount = $invoice->getBaseDiscountTaxCompensationAmount() + $invoice->getBaseShippingDiscountTaxCompensationAmnt() - $this->calculateInvoiceRefundedAmount( $invoice, @@ -316,6 +325,11 @@ private function calculateAllowedBaseDiscountTaxCompensation(Creditmemo $creditM $invoice, CreditmemoInterface::BASE_SHIPPING_DISCOUNT_TAX_COMPENSATION_AMNT ); + $orderAmount = $order->getBaseDiscountTaxCompensationInvoiced() + + $order->getBaseShippingDiscountTaxCompensationAmnt() + - $order->getBaseDiscountTaxCompensationRefunded() + - $order->getBaseShippingDiscountTaxCompensationRefunded(); + $amount = min($invoiceAmount, $orderAmount); } else { $amount = $order->getBaseDiscountTaxCompensationInvoiced() + $order->getBaseShippingDiscountTaxCompensationAmnt()