Skip to content

Commit

Permalink
MAGETWO-82400: Credit Memo - Wrong tax calculation! #10982
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorpetryk committed Dec 14, 2018
1 parent 0d99623 commit de3df20
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 10 deletions.
6 changes: 3 additions & 3 deletions app/code/Magento/Sales/Model/Order/Creditmemo/Total/Tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
}

$isPartialShippingRefunded = false;
$baseOrderShippingAmount = (float)$order->getBaseShippingAmount();
if ($invoice = $creditmemo->getInvoice()) {
//recalculate tax amounts in case if refund shipping value was changed
if ($order->getBaseShippingAmount() && $creditmemo->getBaseShippingAmount()) {
$taxFactor = $creditmemo->getBaseShippingAmount() / $order->getBaseShippingAmount();
if ($baseOrderShippingAmount && $creditmemo->getBaseShippingAmount() !== null) {
$taxFactor = $creditmemo->getBaseShippingAmount() / $baseOrderShippingAmount;
$shippingTaxAmount = $invoice->getShippingTaxAmount() * $taxFactor;
$baseShippingTaxAmount = $invoice->getBaseShippingTaxAmount() * $taxFactor;
$totalDiscountTaxCompensation += $invoice->getShippingDiscountTaxCompensationAmount() * $taxFactor;
Expand All @@ -96,7 +97,6 @@ public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
}
} else {
$orderShippingAmount = $order->getShippingAmount();
$baseOrderShippingAmount = $order->getBaseShippingAmount();

$baseOrderShippingRefundedAmount = $order->getBaseShippingRefunded();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd">
<page name="AdminOrderInvoiceViewPage" url="/sales/order_invoice/view/invoice_id/{{invoiceId}}" parameterized="true" area="admin" module="Magento_Sales">
<section name="AdminOrderInvoiceViewMainActionsSection"/>
</page>
</pages>
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
-->

<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
<section name="AdminCreditMemoTotalSection">
<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"/>
<element name="submitRefundOffline" type="button" selector=".order-totals-actions button[data-ui-id='order-items-submit-button']" timeout="30"/>
<element name="refundShipping" type="input" selector=".order-subtotal-table tbody input[name='creditmemo[shipping_amount]']"/>
<element name="updateTotals" type="button" selector=".update-totals-button"/>
<element name="submitRefundOffline" type="button" selector=".order-totals-actions button[title='Refund Offline']" timeout="30"/>
</section>
</sections>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
<section name="AdminOrderInvoiceViewMainActionsSection">
<element name="creditMemo" type="button" selector=".credit-memo" timeout="30"/>
</section>
</sections>
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminCheckingCreditMemoTotalsTest">
<annotations>
<features value="CreditMemo"/>
<stories value="MAGETWO-82400: Credit Memo - Wrong tax calculation! #10982"/>
<title value="Checking Credit Memo Totals"/>
<description value="Checking Credit Memo Totals"/>
<severity value="MAJOR"/>
<testCaseId value="MAGETWO-97140"/>
<group value="sales"/>
<group value="tax"/>
</annotations>
<before>
<!--Create category-->
<createData entity="_defaultCategory" stepKey="createCategory"/>
<!--Create simple product-->
<createData entity="_defaultProduct" stepKey="createSimpleProduct">
<requiredEntity createDataKey="createCategory"/>
<field key="price">100</field>
</createData>
<!--Create Tax Rule-->
<createData entity="SimpleTaxRule" stepKey="createTaxRule"/>
<!--Create customer-->
<createData entity="Simple_US_CA_Customer" stepKey="createCustomer"/>
<!--Configure Tax Class for shipping-->
<createData entity="TaxClassForShippingConfig" stepKey="configureTaxClassForShipping"/>
<!--Configure Braintree-->
<createData entity="SandboxBraintreeConfig" stepKey="configureBraintree"/>
<!--Login to admin page-->
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
</before>
<after>
<!--Delete category-->
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
<!--Delete simple product-->
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
<!--Delete Tax Rule-->
<deleteData createDataKey="createTaxRule" stepKey="deleteTaxRule"/>
<!--Delete customer-->
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
<!--Restore default configuration for Tax Class for shipping-->
<createData entity="DefaultTaxClassForShippingConfig" stepKey="restoreTaxClassForShippingConfig"/>
<!--Restore default configuration for Braintree-->
<createData entity="DefaultBraintreeConfig" stepKey="restoreBraintreeConfig"/>
<!--Logout from admin page-->
<actionGroup ref="logout" stepKey="logout"/>
</after>

<!--Create new order with existing customer-->
<actionGroup ref="navigateToNewOrderPageExistingCustomer" stepKey="navigateToNewOrderPage">
<argument name="customer" value="$$createCustomer$$"/>
</actionGroup>
<!--Add simple product to order-->
<actionGroup ref="addSimpleProductToOrder" stepKey="addSimpleProductToOrder">
<argument name="product" value="$$createSimpleProduct$$"/>
</actionGroup>
<!--Select Flat Rate shipping method-->
<actionGroup ref="orderSelectFlatRateShipping" stepKey="selectFlatRateShipping"/>
<!--Fill Braintree credit card for payment method-->
<actionGroup ref="AdminOrderFillBraintreeCreditCardActionGroup" stepKey="fillBraintreeCreditCard"/>
<!--Submit order-->
<click selector="{{AdminOrderFormActionSection.submitOrder}}" stepKey="submitOrder"/>
<see selector="{{AdminMessagesSection.success}}" userInput="You created the order."
stepKey="seeSuccessMessage"/>

<!--Create invoice-->
<actionGroup ref="StartCreateInvoiceFromOrderPage" stepKey="startCreateInvoice"/>
<!--Submit invoice-->
<actionGroup ref="SubmitInvoice" stepKey="submitInvoice"/>

<!--Go to invoice page-->
<click selector="{{AdminOrderViewTabsSection.invoices}}" stepKey="clickInvoicesTab"/>
<waitForPageLoad stepKey="waitForInvoiceGridToLoad"/>
<see selector="{{AdminOrderInvoicesTabSection.gridRow('1')}}" userInput="$113.66" stepKey="seeInvoiceInGrid"/>
<click selector="{{AdminDataGridTableSection.rowViewAction('1')}}" stepKey="clickViewInvoice"/>

<!--Create Credit Memo-->
<click selector="{{AdminOrderInvoiceViewMainActionsSection.creditMemo}}" stepKey="clickCreditMemo"/>
<see selector="{{AdminHeaderSection.pageTitle}}" userInput="New Memo" stepKey="seeNewMemoPageTitle"/>
<fillField selector="{{AdminCreditMemoTotalSection.refundShipping}}" userInput="0" stepKey="setRefundShipping"/>
<click selector="{{AdminCreditMemoTotalSection.updateTotals}}" stepKey="clickUpdateTotals"/>
<waitForPageLoad stepKey="waitForUpdateTotals"/>
<click selector="{{AdminCreditMemoTotalSection.submitRefundOffline}}" stepKey="clickRefundOffline"/>
<see selector="{{AdminMessagesSection.success}}" userInput="You created the credit memo."
stepKey="seeCreatedCreditMemoSuccessMessage"/>

<!--Go to Credit Memo tab-->
<click selector="{{AdminOrderViewTabsSection.creditMemos}}" stepKey="clickCreditMemosTab"/>
<waitForPageLoad stepKey="waitForCreditMemosGridToLoad"/>

<!--Check refunded total -->
<see selector="{{AdminOrderCreditMemosTabSection.gridRow('1')}}" userInput="$108.25"
stepKey="seeCreditMemoInGrid"/>
</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,10 @@ public function collectDataProvider()
],
],
'creditmemo_data' => [
'grand_total' => 64.95,
'base_grand_total' => 64.95,
'tax_amount' => 4.95,
'base_tax_amount' => 4.95,
'grand_total' => 64.94,
'base_grand_total' => 64.94,
'tax_amount' => 4.94,
'base_tax_amount' => 4.94,
],
],
];
Expand Down
13 changes: 13 additions & 0 deletions app/code/Magento/Tax/Test/Mftf/Data/TaxConfigData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,17 @@
<entity name="EmptyField" type="taxPostCodeEmpty">
<data key="value"/>
</entity>
<!--Tax Class for Shipping-->
<entity name="TaxClassForShippingConfig" type="tax_config_state">
<requiredEntity type="shipping_tax_class">ShippingTaxClassTaxableGoods</requiredEntity>
</entity>
<entity name="DefaultTaxClassForShippingConfig" type="tax_config_state">
<requiredEntity type="shipping_tax_class">ShippingTaxClassNone</requiredEntity>
</entity>
<entity name="ShippingTaxClassNone" type="shipping_tax_class">
<data key="value">0</data>
</entity>
<entity name="ShippingTaxClassTaxableGoods" type="shipping_tax_class">
<data key="value">2</data>
</entity>
</entities>
9 changes: 8 additions & 1 deletion app/code/Magento/Tax/Test/Mftf/Metadata/tax_config-meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@
-->
<operations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataOperation.xsd">
<operation name="CreateTaxConfigDefaultsTaxDestination" dataType="tax_config_state" type="create" auth="adminFormKey" url="/admin/system_config/save/section/tax/" method="POST">
<operation name="CreateTaxConfigDefaultsTaxDestination" dataType="tax_config_state" type="create" auth="adminFormKey" url="/admin/system_config/save/section/tax/" method="POST" successRegex="/messages-message-success/">
<object key="groups" dataType="tax_config_state">
<object key="classes" dataType="tax_config_state">
<object key="fields" dataType="tax_config_state">
<object key="shipping_tax_class" dataType="shipping_tax_class">
<field key="value">integer</field>
</object>
</object>
</object>
<object key="calculation" dataType="tax_config_state">
<object key="fields" dataType="tax_config_state">
<object key="algorithm" dataType="algorithm">
Expand Down

0 comments on commit de3df20

Please sign in to comment.