Skip to content

Commit de3df20

Browse files
committed
MAGETWO-82400: Credit Memo - Wrong tax calculation! #10982
1 parent 0d99623 commit de3df20

File tree

8 files changed

+164
-10
lines changed

8 files changed

+164
-10
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,11 @@ public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
7575
}
7676

7777
$isPartialShippingRefunded = false;
78+
$baseOrderShippingAmount = (float)$order->getBaseShippingAmount();
7879
if ($invoice = $creditmemo->getInvoice()) {
7980
//recalculate tax amounts in case if refund shipping value was changed
80-
if ($order->getBaseShippingAmount() && $creditmemo->getBaseShippingAmount()) {
81-
$taxFactor = $creditmemo->getBaseShippingAmount() / $order->getBaseShippingAmount();
81+
if ($baseOrderShippingAmount && $creditmemo->getBaseShippingAmount() !== null) {
82+
$taxFactor = $creditmemo->getBaseShippingAmount() / $baseOrderShippingAmount;
8283
$shippingTaxAmount = $invoice->getShippingTaxAmount() * $taxFactor;
8384
$baseShippingTaxAmount = $invoice->getBaseShippingTaxAmount() * $taxFactor;
8485
$totalDiscountTaxCompensation += $invoice->getShippingDiscountTaxCompensationAmount() * $taxFactor;
@@ -96,7 +97,6 @@ public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
9697
}
9798
} else {
9899
$orderShippingAmount = $order->getShippingAmount();
99-
$baseOrderShippingAmount = $order->getBaseShippingAmount();
100100

101101
$baseOrderShippingRefundedAmount = $order->getBaseShippingRefunded();
102102

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd">
11+
<page name="AdminOrderInvoiceViewPage" url="/sales/order_invoice/view/invoice_id/{{invoiceId}}" parameterized="true" area="admin" module="Magento_Sales">
12+
<section name="AdminOrderInvoiceViewMainActionsSection"/>
13+
</page>
14+
</pages>

app/code/Magento/Sales/Test/Mftf/Section/AdminCreditMemoTotalSection.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
-->
88

99
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10-
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
1111
<section name="AdminCreditMemoTotalSection">
1212
<element name="total" type="text" selector="//table[contains(@class,'order-subtotal-table')]/tbody/tr/td[contains(text(), '{{total}}')]/following-sibling::td/span/span[contains(@class, 'price')]" parameterized="true"/>
13-
<element name="submitRefundOffline" type="button" selector=".order-totals-actions button[data-ui-id='order-items-submit-button']" timeout="30"/>
13+
<element name="refundShipping" type="input" selector=".order-subtotal-table tbody input[name='creditmemo[shipping_amount]']"/>
14+
<element name="updateTotals" type="button" selector=".update-totals-button"/>
15+
<element name="submitRefundOffline" type="button" selector=".order-totals-actions button[title='Refund Offline']" timeout="30"/>
1416
</section>
1517
</sections>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
11+
<section name="AdminOrderInvoiceViewMainActionsSection">
12+
<element name="creditMemo" type="button" selector=".credit-memo" timeout="30"/>
13+
</section>
14+
</sections>
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminCheckingCreditMemoTotalsTest">
12+
<annotations>
13+
<features value="CreditMemo"/>
14+
<stories value="MAGETWO-82400: Credit Memo - Wrong tax calculation! #10982"/>
15+
<title value="Checking Credit Memo Totals"/>
16+
<description value="Checking Credit Memo Totals"/>
17+
<severity value="MAJOR"/>
18+
<testCaseId value="MAGETWO-97140"/>
19+
<group value="sales"/>
20+
<group value="tax"/>
21+
</annotations>
22+
<before>
23+
<!--Create category-->
24+
<createData entity="_defaultCategory" stepKey="createCategory"/>
25+
<!--Create simple product-->
26+
<createData entity="_defaultProduct" stepKey="createSimpleProduct">
27+
<requiredEntity createDataKey="createCategory"/>
28+
<field key="price">100</field>
29+
</createData>
30+
<!--Create Tax Rule-->
31+
<createData entity="SimpleTaxRule" stepKey="createTaxRule"/>
32+
<!--Create customer-->
33+
<createData entity="Simple_US_CA_Customer" stepKey="createCustomer"/>
34+
<!--Configure Tax Class for shipping-->
35+
<createData entity="TaxClassForShippingConfig" stepKey="configureTaxClassForShipping"/>
36+
<!--Configure Braintree-->
37+
<createData entity="SandboxBraintreeConfig" stepKey="configureBraintree"/>
38+
<!--Login to admin page-->
39+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
40+
</before>
41+
<after>
42+
<!--Delete category-->
43+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
44+
<!--Delete simple product-->
45+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
46+
<!--Delete Tax Rule-->
47+
<deleteData createDataKey="createTaxRule" stepKey="deleteTaxRule"/>
48+
<!--Delete customer-->
49+
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
50+
<!--Restore default configuration for Tax Class for shipping-->
51+
<createData entity="DefaultTaxClassForShippingConfig" stepKey="restoreTaxClassForShippingConfig"/>
52+
<!--Restore default configuration for Braintree-->
53+
<createData entity="DefaultBraintreeConfig" stepKey="restoreBraintreeConfig"/>
54+
<!--Logout from admin page-->
55+
<actionGroup ref="logout" stepKey="logout"/>
56+
</after>
57+
58+
<!--Create new order with existing customer-->
59+
<actionGroup ref="navigateToNewOrderPageExistingCustomer" stepKey="navigateToNewOrderPage">
60+
<argument name="customer" value="$$createCustomer$$"/>
61+
</actionGroup>
62+
<!--Add simple product to order-->
63+
<actionGroup ref="addSimpleProductToOrder" stepKey="addSimpleProductToOrder">
64+
<argument name="product" value="$$createSimpleProduct$$"/>
65+
</actionGroup>
66+
<!--Select Flat Rate shipping method-->
67+
<actionGroup ref="orderSelectFlatRateShipping" stepKey="selectFlatRateShipping"/>
68+
<!--Fill Braintree credit card for payment method-->
69+
<actionGroup ref="AdminOrderFillBraintreeCreditCardActionGroup" stepKey="fillBraintreeCreditCard"/>
70+
<!--Submit order-->
71+
<click selector="{{AdminOrderFormActionSection.submitOrder}}" stepKey="submitOrder"/>
72+
<see selector="{{AdminMessagesSection.success}}" userInput="You created the order."
73+
stepKey="seeSuccessMessage"/>
74+
75+
<!--Create invoice-->
76+
<actionGroup ref="StartCreateInvoiceFromOrderPage" stepKey="startCreateInvoice"/>
77+
<!--Submit invoice-->
78+
<actionGroup ref="SubmitInvoice" stepKey="submitInvoice"/>
79+
80+
<!--Go to invoice page-->
81+
<click selector="{{AdminOrderViewTabsSection.invoices}}" stepKey="clickInvoicesTab"/>
82+
<waitForPageLoad stepKey="waitForInvoiceGridToLoad"/>
83+
<see selector="{{AdminOrderInvoicesTabSection.gridRow('1')}}" userInput="$113.66" stepKey="seeInvoiceInGrid"/>
84+
<click selector="{{AdminDataGridTableSection.rowViewAction('1')}}" stepKey="clickViewInvoice"/>
85+
86+
<!--Create Credit Memo-->
87+
<click selector="{{AdminOrderInvoiceViewMainActionsSection.creditMemo}}" stepKey="clickCreditMemo"/>
88+
<see selector="{{AdminHeaderSection.pageTitle}}" userInput="New Memo" stepKey="seeNewMemoPageTitle"/>
89+
<fillField selector="{{AdminCreditMemoTotalSection.refundShipping}}" userInput="0" stepKey="setRefundShipping"/>
90+
<click selector="{{AdminCreditMemoTotalSection.updateTotals}}" stepKey="clickUpdateTotals"/>
91+
<waitForPageLoad stepKey="waitForUpdateTotals"/>
92+
<click selector="{{AdminCreditMemoTotalSection.submitRefundOffline}}" stepKey="clickRefundOffline"/>
93+
<see selector="{{AdminMessagesSection.success}}" userInput="You created the credit memo."
94+
stepKey="seeCreatedCreditMemoSuccessMessage"/>
95+
96+
<!--Go to Credit Memo tab-->
97+
<click selector="{{AdminOrderViewTabsSection.creditMemos}}" stepKey="clickCreditMemosTab"/>
98+
<waitForPageLoad stepKey="waitForCreditMemosGridToLoad"/>
99+
100+
<!--Check refunded total -->
101+
<see selector="{{AdminOrderCreditMemosTabSection.gridRow('1')}}" userInput="$108.25"
102+
stepKey="seeCreditMemoInGrid"/>
103+
</test>
104+
</tests>

app/code/Magento/Sales/Test/Unit/Model/Order/Creditmemo/Total/TaxTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,10 @@ public function collectDataProvider()
440440
],
441441
],
442442
'creditmemo_data' => [
443-
'grand_total' => 64.95,
444-
'base_grand_total' => 64.95,
445-
'tax_amount' => 4.95,
446-
'base_tax_amount' => 4.95,
443+
'grand_total' => 64.94,
444+
'base_grand_total' => 64.94,
445+
'tax_amount' => 4.94,
446+
'base_tax_amount' => 4.94,
447447
],
448448
],
449449
];

app/code/Magento/Tax/Test/Mftf/Data/TaxConfigData.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,17 @@
142142
<entity name="EmptyField" type="taxPostCodeEmpty">
143143
<data key="value"/>
144144
</entity>
145+
<!--Tax Class for Shipping-->
146+
<entity name="TaxClassForShippingConfig" type="tax_config_state">
147+
<requiredEntity type="shipping_tax_class">ShippingTaxClassTaxableGoods</requiredEntity>
148+
</entity>
149+
<entity name="DefaultTaxClassForShippingConfig" type="tax_config_state">
150+
<requiredEntity type="shipping_tax_class">ShippingTaxClassNone</requiredEntity>
151+
</entity>
152+
<entity name="ShippingTaxClassNone" type="shipping_tax_class">
153+
<data key="value">0</data>
154+
</entity>
155+
<entity name="ShippingTaxClassTaxableGoods" type="shipping_tax_class">
156+
<data key="value">2</data>
157+
</entity>
145158
</entities>

app/code/Magento/Tax/Test/Mftf/Metadata/tax_config-meta.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@
77
-->
88
<operations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataOperation.xsd">
10-
<operation name="CreateTaxConfigDefaultsTaxDestination" dataType="tax_config_state" type="create" auth="adminFormKey" url="/admin/system_config/save/section/tax/" method="POST">
10+
<operation name="CreateTaxConfigDefaultsTaxDestination" dataType="tax_config_state" type="create" auth="adminFormKey" url="/admin/system_config/save/section/tax/" method="POST" successRegex="/messages-message-success/">
1111
<object key="groups" dataType="tax_config_state">
12+
<object key="classes" dataType="tax_config_state">
13+
<object key="fields" dataType="tax_config_state">
14+
<object key="shipping_tax_class" dataType="shipping_tax_class">
15+
<field key="value">integer</field>
16+
</object>
17+
</object>
18+
</object>
1219
<object key="calculation" dataType="tax_config_state">
1320
<object key="fields" dataType="tax_config_state">
1421
<object key="algorithm" dataType="algorithm">

0 commit comments

Comments
 (0)