Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 6b7a9b3

Browse files
authored
Merge pull request #2759 from magento-borg/MAGETWO-91710
[borg] MAGETWO-91710: Creditmemo Grand Total is incorrect if discount is applied on shipping
2 parents 53241b9 + 32ba268 commit 6b7a9b3

File tree

8 files changed

+285
-2
lines changed

8 files changed

+285
-2
lines changed

app/code/Magento/Catalog/Test/Mftf/Test/SaveProductWithCustomOptionsSecondWebsiteTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
<!--Create Store view -->
3636
<amOnPage url="{{AdminSystemStorePage.url}}" stepKey="amOnAdminSystemStorePage"/>
37+
<waitForElementVisible selector="{{AdminStoresMainActionsSection.createStoreViewButton}}" stepKey="waitForStoreViewBtn"/>
3738
<click selector="{{AdminStoresMainActionsSection.createStoreViewButton}}" stepKey="createStoreViewButton"/>
3839
<waitForPageLoad stepKey="waitForProductPageLoad"/>
3940
<selectOption userInput="Second Store" selector="{{AdminNewStoreSection.storeGrpDropdown}}" stepKey="selectStoreGroup"/>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="SetTaxClassForShipping">
12+
<amOnPage url="{{AdminSalesTaxClassPage.url}}" stepKey="navigateToSalesTaxPage"/>
13+
<waitForPageLoad stepKey="waitForPageLoad"/>
14+
<conditionalClick selector="{{SalesConfigSection.TaxClassesTab}}" dependentSelector="{{SalesConfigSection.CheckIfTaxClassesTabExpand}}" visible="true" stepKey="expandTaxClassesTab"/>
15+
<waitForElementVisible selector="{{SalesConfigSection.ShippingTaxClass}}" stepKey="seeShippingTaxClass"/>
16+
<uncheckOption selector="{{SalesConfigSection.EnableTaxClassForShipping}}" stepKey="uncheckUseSystemValue"/>
17+
<selectOption selector="{{SalesConfigSection.ShippingTaxClass}}" userInput="Taxable Goods" stepKey="setShippingTaxClass"/>
18+
<click selector="{{SalesConfigSection.TaxClassesTab}}" stepKey="collapseTaxClassesTab"/>
19+
<click selector="{{ContentManagementSection.Save}}" stepKey="saveConfig" />
20+
</actionGroup>
21+
<actionGroup name="ResetTaxClassForShipping">
22+
<amOnPage url="{{AdminSalesTaxClassPage.url}}" stepKey="navigateToSalesTaxConfigPagetoReset"/>
23+
<waitForPageLoad stepKey="waitForPageLoad2"/>
24+
<conditionalClick selector="{{SalesConfigSection.TaxClassesTab}}" dependentSelector="{{SalesConfigSection.CheckIfTaxClassesTabExpand}}" visible="true" stepKey="openTaxClassTab"/>
25+
<waitForElementVisible selector="{{SalesConfigSection.ShippingTaxClass}}" stepKey="seeShippingTaxClass2"/>
26+
<selectOption selector="{{SalesConfigSection.ShippingTaxClass}}" userInput="None" stepKey="resetShippingTaxClass"/>
27+
<checkOption selector="{{SalesConfigSection.EnableTaxClassForShipping}}" stepKey="useSystemValue"/>
28+
<click selector="{{SalesConfigSection.TaxClassesTab}}" stepKey="collapseTaxClassesTab"/>
29+
<click selector="{{ContentManagementSection.Save}}" stepKey="saveConfiguration"/>
30+
</actionGroup>
31+
</actionGroups>

app/code/Magento/Config/Test/Mftf/Page/AdminConfigPage.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@
1212
<page name="AdminContentManagementPage" url="admin/system_config/edit/section/cms/" area="admin" module="Magento_Config">
1313
<section name="ContentManagementSection"/>
1414
</page>
15+
<page name="AdminSalesTaxClassPage" url="admin/system_config/edit/section/tax/" area="admin" module="Magento_Config">
16+
<section name="SalesTaxClassSection"/>
17+
</page>
1518
</pages>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
11+
<section name="SalesConfigSection">
12+
<element name="TaxClassesTab" type="button" selector="#tax_classes-head"/>
13+
<element name="CheckIfTaxClassesTabExpand" type="button" selector="#tax_classes-head:not(.open)"/>
14+
<element name="ShippingTaxClass" type="select" selector="#tax_classes_shipping_tax_class"/>
15+
<element name="EnableTaxClassForShipping" type="checkbox" selector="#tax_classes_shipping_tax_class_inherit"/>
16+
</section>
17+
</sections>

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
2525
* Calculate how much shipping discount should be applied
2626
* basing on how much shipping should be refunded.
2727
*/
28-
$baseShippingAmount = (float)$creditmemo->getBaseShippingAmount();
28+
$baseShippingAmount = $this->getBaseShippingAmount($creditmemo);
2929
if ($baseShippingAmount) {
3030
$baseShippingDiscount = $baseShippingAmount *
3131
$order->getBaseShippingDiscountAmount() /
@@ -75,4 +75,21 @@ public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
7575
$creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() - $baseTotalDiscountAmount);
7676
return $this;
7777
}
78+
79+
/**
80+
* Get base shipping amount
81+
*
82+
* @param \Magento\Sales\Model\Order\Creditmemo $creditmemo
83+
* @return float
84+
*/
85+
private function getBaseShippingAmount(\Magento\Sales\Model\Order\Creditmemo $creditmemo): float
86+
{
87+
$baseShippingAmount = (float)$creditmemo->getBaseShippingAmount();
88+
if (!$baseShippingAmount) {
89+
$baseShippingInclTax = (float)$creditmemo->getBaseShippingInclTax();
90+
$baseShippingTaxAmount = (float)$creditmemo->getBaseShippingTaxAmount();
91+
$baseShippingAmount = $baseShippingInclTax - $baseShippingTaxAmount;
92+
}
93+
return $baseShippingAmount;
94+
}
7895
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
11+
<test name="CreditMemoTotalAfterShippingDiscountTest">
12+
<annotations>
13+
<features value="Credit memo"/>
14+
<title value="Verify credit memo grand total after shipping discount is applied via Cart Price Rule"/>
15+
<description value="Verify credit memo grand total after shipping discount is applied via Cart Price Rule"/>
16+
<severity value="MAJOR"/>
17+
<testCaseId value="MAGETWO-92924"/>
18+
<group value="sales"/>
19+
</annotations>
20+
<before>
21+
<createData entity="_defaultCategory" stepKey="createCategory"/>
22+
<createData entity="_defaultProduct" stepKey="createProduct">
23+
<requiredEntity createDataKey="createCategory"/>
24+
</createData>
25+
<actionGroup ref="LoginActionGroup" stepKey="loginAsAdmin"/>
26+
<actionGroup ref="SetTaxClassForShipping" stepKey="setShippingTaxClass"/>
27+
</before>
28+
<after>
29+
<actionGroup ref="ResetTaxClassForShipping" stepKey="resetTaxClassForShipping"/>
30+
<actionGroup ref="DeleteCartPriceRuleByName" stepKey="deleteSalesRule">
31+
<argument name="ruleName" value="{{ApiSalesRule.name}}"/>
32+
</actionGroup>
33+
<amOnPage url="admin/admin/auth/logout/" stepKey="amOnLogoutPage"/>
34+
<deleteData createDataKey="createCategory" stepKey="deleteProduct1"/>
35+
<deleteData createDataKey="createProduct" stepKey="deleteCategory1"/>
36+
</after>
37+
38+
<!-- Create a cart price rule for $10 Fixed amount discount -->
39+
<amOnPage url="{{AdminCartPriceRulesPage.url}}" stepKey="amOnCartPriceList"/>
40+
<waitForPageLoad stepKey="waitForRulesPage"/>
41+
<click selector="{{AdminCartPriceRulesSection.addNewRuleButton}}" stepKey="clickAddNewRule"/>
42+
<fillField selector="{{AdminCartPriceRulesFormSection.ruleName}}" userInput="{{ApiSalesRule.name}}" stepKey="fillRuleName"/>
43+
<selectOption selector="{{AdminCartPriceRulesFormSection.websites}}" userInput="Main Website" stepKey="selectWebsite"/>
44+
<actionGroup ref="selectNotLoggedInCustomerGroup" stepKey="chooseNotLoggedInCustomerGroup"/>
45+
<!--<selectOption selector="{{AdminCartPriceRulesFormSection.customerGroups}}" userInput="NOT LOGGED IN" stepKey="selectCustomerGroup"/>-->
46+
47+
<!-- Open the Actions Tab in the Rules Edit page -->
48+
<click selector="{{AdminCartPriceRulesFormSection.actionsHeader}}" stepKey="clickToExpandActions"/>
49+
<waitForElementVisible selector="{{AdminCartPriceRulesFormSection.applyDiscountToShippingLabel}}" stepKey="waitForElementToBeVisible"/>
50+
<click selector="{{AdminCartPriceRulesFormSection.applyDiscountToShippingLabel}}" stepKey="enableApplyDiscountToShiping"/>
51+
<seeCheckboxIsChecked selector="{{AdminCartPriceRulesFormSection.applyDiscountToShipping}}" stepKey="DiscountIsAppliedToShiping"/>
52+
<selectOption selector="{{AdminCartPriceRulesFormSection.apply}}" userInput="Fixed amount discount" stepKey="selectActionType"/>
53+
<fillField selector="{{AdminCartPriceRulesFormSection.discountAmount}}" userInput="10" stepKey="fillDiscountAmount"/>
54+
55+
<!--<scrollTo selector="{{AdminCartPriceRulesFormSection.applyDiscountToShippingLabel}}" stepKey="scrollToShippingLabel"/>-->
56+
<!--<click selector="{{AdminCartPriceRulesFormSection.applyDiscountToShippingLabel}}" stepKey="enableApplyDiscountToShiping"/>-->
57+
<!--<seeCheckboxIsChecked selector="{{AdminCartPriceRulesFormSection.applyDiscountToShipping}}" stepKey="DiscountIsAppliedToShiping"/>-->
58+
<click selector="{{AdminCartPriceRulesFormSection.save}}" stepKey="clickSaveButton"/>
59+
<see selector="{{AdminCartPriceRulesSection.messages}}" userInput="You saved the rule." stepKey="seeSuccessMessage"/>
60+
<amOnPage url="admin/admin/auth/logout/" stepKey="amOnLogoutPage"/>
61+
62+
<!-- Place an order from Storefront as a Guest -->
63+
<amOnPage url="{{StorefrontCategoryPage.url($$createCategory.name$$)}}" stepKey="onCategoryPage"/>
64+
<waitForPageLoad stepKey="waitForPageLoad1"/>
65+
<moveMouseOver selector="{{StorefrontCategoryMainSection.ProductItemInfo}}" stepKey="hoverOverProduct"/>
66+
<click selector="{{StorefrontCategoryMainSection.AddToCartBtn}}" stepKey="addToCart"/>
67+
<waitForElementVisible selector="{{StorefrontCategoryMainSection.SuccessMsg}}" time="30" stepKey="waitForProductToAdd"/>
68+
<click selector="{{StorefrontMinicartSection.showCart}}" stepKey="clickCart"/>
69+
<click selector="{{StorefrontMinicartSection.goToCheckout}}" stepKey="goToCheckout"/>
70+
<waitForPageLoad stepKey="waitForPageLoad2"/>
71+
<!-- fill out customer information -->
72+
<fillField selector="{{CheckoutShippingGuestInfoSection.email}}" userInput="{{CustomerEntityOne.email}}" stepKey="enterEmail"/>
73+
<fillField selector="{{CheckoutShippingGuestInfoSection.firstName}}" userInput="{{CustomerEntityOne.firstname}}" stepKey="enterFirstName"/>
74+
<fillField selector="{{CheckoutShippingGuestInfoSection.lastName}}" userInput="{{CustomerEntityOne.lastname}}" stepKey="enterLastName"/>
75+
<fillField selector="{{CheckoutShippingGuestInfoSection.street}}" userInput="{{CustomerAddressSimple.street[0]}}" stepKey="enterStreet"/>
76+
<fillField selector="{{CheckoutShippingGuestInfoSection.city}}" userInput="{{CustomerAddressSimple.city}}" stepKey="enterCity"/>
77+
<selectOption selector="{{CheckoutShippingGuestInfoSection.region}}" userInput="{{CustomerAddressSimple.state}}" stepKey="selectRegion"/>
78+
<fillField selector="{{CheckoutShippingGuestInfoSection.postcode}}" userInput="{{CustomerAddressSimple.postcode}}" stepKey="enterPostcode"/>
79+
<fillField selector="{{CheckoutShippingGuestInfoSection.telephone}}" userInput="{{CustomerAddressSimple.telephone}}" stepKey="enterTelephone"/>
80+
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMask"/>
81+
82+
<!-- Choose Shippping - Flat Rate Shipping -->
83+
<click selector="{{CheckoutShippingMethodsSection.firstShippingMethod}}" stepKey="selectFirstShippingMethod"/>
84+
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMask2"/>
85+
<waitForElement selector="{{CheckoutShippingMethodsSection.next}}" time="30" stepKey="waitForNextButton"/>
86+
<click selector="{{CheckoutShippingMethodsSection.next}}" stepKey="clickNext"/>
87+
<waitForElement selector="{{CheckoutPaymentSection.placeOrder}}" time="30" stepKey="waitForPlaceOrderButton"/>
88+
<click selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="clickPlaceOrder"/>
89+
<grabTextFrom selector="{{CheckoutSuccessMainSection.orderNumber}}" stepKey="grabOrderNumber"/>
90+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin1"/>
91+
92+
<!-- Search for Order in the order grid -->
93+
<amOnPage url="{{AdminOrdersPage.url}}" stepKey="onOrdersPage"/>
94+
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMask3"/>
95+
<fillField selector="{{AdminOrdersGridSection.search}}" userInput="{$grabOrderNumber}" stepKey="searchOrderNum"/>
96+
<click selector="{{AdminOrdersGridSection.submitSearch}}" stepKey="submitSearch"/>
97+
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMask4"/>
98+
99+
<!-- Create invoice -->
100+
<click selector="{{AdminOrdersGridSection.firstRow}}" stepKey="clickOrderRow"/>
101+
<click selector="{{AdminOrderDetailsMainActionsSection.invoice}}" stepKey="clickInvoiceButton"/>
102+
<see selector="{{AdminHeaderSection.pageTitle}}" userInput="New Invoice" stepKey="seeNewInvoiceInPageTitle" after="clickInvoiceButton"/>
103+
104+
<!-- Verify Invoice Totals including subTotal Shipping Discount and GrandTotal -->
105+
<see selector="{{AdminInvoiceTotalSection.total('Subtotal')}}" userInput="${{AdminOrderSimpleProduct.subtotal}}" stepKey="seeInvoiceSubTotal"/>
106+
<comment userInput="Shipping and Handling" stepKey="commentViewShippingAndHandling" after="seeInvoiceSubTotal"/>
107+
<see selector="{{AdminInvoiceTotalSection.total('Shipping')}}" userInput="${{AdminOrderSimpleProduct.shipping}}" stepKey="seeShippingAndHandling"/>
108+
<scrollTo selector="{{AdminInvoiceTotalSection.total('Shipping')}}" stepKey="scrollToInvoiceTotals"/>
109+
<grabTextFrom selector="{{AdminInvoiceTotalSection.total('Shipping')}}" stepKey="grabShippingCost"/>
110+
<assertEquals expected='$5.00' expectedType="string" actual="($grabShippingCost)" message="ExpectedShipping" stepKey="assertShippingAndHandling"/>
111+
112+
<see selector="{{AdminInvoiceTotalSection.total('Discount')}}" userInput="-$15.00" stepKey="seeShippingAndHandling2"/>
113+
<grabTextFrom selector="{{AdminInvoiceTotalSection.total('Discount')}}" stepKey="grabInvoiceDiscount"/>
114+
<assertEquals expected='-$15.00' expectedType="string" actual="($grabInvoiceDiscount)" message="ExpectedDiscount" stepKey="assertDiscountValue"/>
115+
116+
<see selector="{{AdminInvoiceTotalSection.grandTotal}}" userInput="$113.00" stepKey="seeCorrectGrandTotal"/>
117+
<grabTextFrom selector="{{AdminInvoiceTotalSection.grandTotal}}" stepKey="grabInvoiceGrandTotal" after="seeCorrectGrandTotal"/>
118+
119+
<click selector="{{AdminInvoiceMainActionsSection.submitInvoice}}" stepKey="clickSubmitInvoice"/>
120+
<see selector="{{AdminOrderDetailsMessagesSection.successMessage}}" userInput="The invoice has been created." stepKey="seeSuccessMessage1"/>
121+
122+
<!--Create Credit Memo-->
123+
<comment userInput="Admin creates credit memo" stepKey="createCreditMemoComment"/>
124+
<click selector="{{AdminOrderDetailsMainActionsSection.creditMemo}}" stepKey="clickCreateCreditMemo" after="createCreditMemoComment"/>
125+
<seeInCurrentUrl url="{{AdminCreditMemoNewPage.url}}" stepKey="seeNewCreditMemoPage" after="clickCreateCreditMemo"/>
126+
<see selector="{{AdminHeaderSection.pageTitle}}" userInput="New Memo" stepKey="seeNewMemoInPageTitle" after="seeNewCreditMemoPage"/>
127+
128+
<!-- Verify Refund Totals -->
129+
<see selector="{{AdminCreditMemoTotalSection.total('Subtotal')}}" userInput="${{AdminOrderSimpleProduct.subtotal}}" stepKey="seeRefundSubTotal"/>
130+
<grabTextFrom selector="{{AdminCreditMemoTotalSection.total('Discount')}}" stepKey="grabRefundDiscountValue"/>
131+
<assertEquals expected='-$15.00' expectedType="string" actual="($grabRefundDiscountValue)" message="notExpectedDiscountOnRefundPage" stepKey="assertDiscountValue1"/>
132+
<grabTextFrom selector="{{AdminInvoiceTotalSection.grandTotal}}" stepKey="grabRefundGrandTotal"/>
133+
<assertEquals expected="($grabInvoiceGrandTotal)" actual="($grabRefundGrandTotal)" message="RefundGrandTotalMatchesWithInvoiceGrandTotal" stepKey="compareRefundGrandTotalAndInvoiceGrandTotal"/>
134+
</test>
135+
</tests>
136+

0 commit comments

Comments
 (0)