Skip to content

Commit 525555e

Browse files
committed
ACP2E-1313: Refund shipping issue with discounted order (Apply Discount On Prices = Including tax)
1 parent bab1f54 commit 525555e

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

app/code/Magento/Sales/Model/Order/Creditmemo/Total/Shipping.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Framework\Pricing\PriceCurrencyInterface;
99
use Magento\Tax\Model\Calculation as TaxCalculation;
10+
use Magento\Sales\Model\Order;
1011

1112
/**
1213
* Order creditmemo shipping total calculation model
@@ -115,25 +116,26 @@ public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
115116
/**
116117
* Checks if shipping provided incl tax, tax applied after discount, and discount applied on shipping excl tax
117118
*
118-
* @param \Magento\Sales\Model\Order $order
119+
* @param Order $order
119120
* @return bool
120121
*/
121-
private function isShippingIncludeTaxWithTaxAfterDiscountOnExcl($order): bool
122+
private function isShippingIncludeTaxWithTaxAfterDiscount(Order $order): bool
122123
{
123-
return $this->getTaxConfig()->getCalculationSequence($order->getStoreId())
124-
=== TaxCalculation::CALC_TAX_AFTER_DISCOUNT_ON_EXCL &&
125-
$this->isSuppliedShippingAmountInclTax($order);
124+
$calculationSequence = $this->getTaxConfig()->getCalculationSequence($order->getStoreId());
125+
return ($calculationSequence === TaxCalculation::CALC_TAX_AFTER_DISCOUNT_ON_EXCL
126+
|| $calculationSequence === TaxCalculation::CALC_TAX_AFTER_DISCOUNT_ON_INCL)
127+
&& $this->isSuppliedShippingAmountInclTax($order);
126128
}
127129

128130
/**
129131
* Get allowed shipping amount to refund based on tax settings
130132
*
131-
* @param \Magento\Sales\Model\Order $order
133+
* @param Order $order
132134
* @return float
133135
*/
134-
private function getAllowedAmountInclTax(\Magento\Sales\Model\Order $order): float
136+
private function getAllowedAmountInclTax(Order $order): float
135137
{
136-
if ($this->isShippingIncludeTaxWithTaxAfterDiscountOnExcl($order)) {
138+
if ($this->isShippingIncludeTaxWithTaxAfterDiscount($order)) {
137139
$result = $order->getShippingInclTax();
138140
foreach ($order->getCreditmemosCollection() as $creditmemo) {
139141
$result -= $creditmemo->getShippingInclTax();
@@ -155,7 +157,7 @@ private function getAllowedAmountInclTax(\Magento\Sales\Model\Order $order): flo
155157
private function getBaseAllowedAmountInclTax(\Magento\Sales\Model\Order $order): float
156158
{
157159
$result = $order->getBaseShippingInclTax();
158-
if ($this->isShippingIncludeTaxWithTaxAfterDiscountOnExcl($order)) {
160+
if ($this->isShippingIncludeTaxWithTaxAfterDiscount($order)) {
159161
foreach ($order->getCreditmemosCollection() as $creditmemo) {
160162
$result -= $creditmemo->getBaseShippingInclTax();
161163
}

app/code/Magento/Sales/Model/Order/Creditmemo/Total/Tax.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
*/
66
namespace Magento\Sales\Model\Order\Creditmemo\Total;
77

8+
use Magento\Framework\App\ObjectManager;
89
use Magento\Sales\Api\Data\CreditmemoInterface;
910
use Magento\Sales\Model\Order\Creditmemo;
1011
use Magento\Sales\Model\Order\Invoice;
1112
use Magento\Sales\Model\ResourceModel\Order\Invoice as ResourceInvoice;
12-
use Magento\Tax\Model\Config as TaxConfig;
1313
use Magento\Tax\Model\Calculation as TaxCalculation;
14-
use Magento\Framework\App\ObjectManager;
14+
use Magento\Tax\Model\Config as TaxConfig;
1515

1616
/**
1717
* Collects credit memo taxes.
@@ -135,7 +135,7 @@ public function collect(Creditmemo $creditmemo)
135135
$shippingDelta = $baseOrderShippingAmount - $baseOrderShippingRefundedAmount;
136136

137137
if ($shippingDelta > $creditmemo->getBaseShippingAmount() ||
138-
$this->isShippingIncludeTaxWithTaxAfterDiscountOnExcl($order->getStoreId())) {
138+
$this->isShippingIncludeTaxWithTaxAfterDiscount($order->getStoreId())) {
139139
$part = $creditmemo->getShippingAmount() / $orderShippingAmount;
140140
$basePart = $creditmemo->getBaseShippingAmount() / $baseOrderShippingAmount;
141141
$shippingTaxAmount = $order->getShippingTaxAmount() * $part;
@@ -213,10 +213,12 @@ public function collect(Creditmemo $creditmemo)
213213
* @param int|null $storeId
214214
* @return bool
215215
*/
216-
private function isShippingIncludeTaxWithTaxAfterDiscountOnExcl(?int $storeId): bool
216+
private function isShippingIncludeTaxWithTaxAfterDiscount(?int $storeId): bool
217217
{
218-
return $this->taxConfig->getCalculationSequence($storeId) === TaxCalculation::CALC_TAX_AFTER_DISCOUNT_ON_EXCL &&
219-
$this->taxConfig->displaySalesShippingInclTax($storeId);
218+
$calculationSequence = $this->taxConfig->getCalculationSequence($storeId);
219+
return ($calculationSequence === TaxCalculation::CALC_TAX_AFTER_DISCOUNT_ON_EXCL
220+
|| $calculationSequence === TaxCalculation::CALC_TAX_AFTER_DISCOUNT_ON_INCL)
221+
&& $this->taxConfig->displaySalesShippingInclTax($storeId);
220222
}
221223

222224
/**

0 commit comments

Comments
 (0)