Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

100% Discount cart rule results in Tax invoiced #30853 #31556

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/code/Magento/Sales/Model/Order/Invoice/Total/Tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,13 @@ public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
$invoice->setDiscountTaxCompensationAmount($taxDiscountCompensationAmt);
$invoice->setBaseDiscountTaxCompensationAmount($baseTaxDiscountCompensationAmt);

$invoice->setGrandTotal($invoice->getGrandTotal() + $totalTax + $totalDiscountTaxCompensation);
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseTotalTax + $baseTotalDiscountTaxCompensation);
$grandTotal = $invoice->getGrandTotal() + $invoice->getDiscountAmount() < 0.0001
? 0 : $invoice->getGrandTotal() + $totalTax + $totalDiscountTaxCompensation;
$baseGrandTotal = $invoice->getBaseGrandTotal() + $invoice->getBaseDiscountAmount() < 0.0001
? 0 : $invoice->getBaseGrandTotal() + $baseTotalTax + $baseTotalDiscountTaxCompensation;

$invoice->setGrandTotal($grandTotal);
$invoice->setBaseGrandTotal($baseGrandTotal);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such a solution would just work if the Tax totals is the last to run, but depending on sort order is not great, I recommend looking at \Magento\Sales\Model\Order\Invoice\Total\Shipping line 41 and 42, that is where the shipping cost is bein added to the grand total.


return $this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?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="CreateInvoiceWithZeroGrandTotalCheckoutTest">
<annotations>
<stories value="Create Invoice for Offline Payment Methods"/>
<title value="Create invoice with zero grandTotal checkout test"/>
<description value="Create invoice with with zero grandTotal checkout"/>
<severity value="CRITICAL"/>
<testCaseId value="MC-*"/>
<group value="sales"/>
<group value="mtf_migrated"/>
</annotations>
<before>
<createData entity="Simple_US_Customer_CA" stepKey="createCustomer"/>
<createData entity="SimpleProduct2" stepKey="createSimpleProduct">
<field key="price">10</field>
</createData>
<!-- Create sales rule discount 100% with coupon -->
<createData entity="SalesRuleSpecificCouponWithHundredPercentDiscount" stepKey="createCartPriceRule"/>
<createData entity="SimpleSalesRuleCoupon" stepKey="createCouponForCartPriceRule">
<requiredEntity createDataKey="createCartPriceRule"/>
</createData>
<createData entity="FreeShippinMethodConfig" stepKey="enableFreeShippingMethod"/>
<!-- Catalog Prices and Apply Discount On Prices switched to Including Tax -->
<magentoCLI command="config:set tax/calculation/price_includes_tax 1" stepKey="setCatalogPriceConfigToIncludingTax"/>
<magentoCLI command="config:set tax/calculation/discount_tax 1" stepKey="setApplyDiscountOnPricesConfigToIncludingTax"/>
<!--Create tax rate for US-CA-*-->
<createData entity="defaultTaxRate" stepKey="taxRate"/>
<!-- Login as admin -->
<actionGroup ref="AdminLoginActionGroup" stepKey="LoginAsAdmin"/>
<!--Create tax rule-->
<actionGroup ref="AdminCreateTaxRuleActionGroup" stepKey="createTaxRule">
<argument name="taxRate" value="$$taxRate$$"/>
<argument name="taxRule" value="SimpleTaxRule"/>
</actionGroup>
</before>
<after>
<actionGroup ref="AdminDeleteTaxRule" stepKey="deleteTaxRule">
<argument name="taxRuleCode" value="{{SimpleTaxRule.code}}" />
</actionGroup>
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
<deleteData createDataKey="taxRate" stepKey="deleteTaxRate"/>
<createData entity="FreeShippinMethodDefault" stepKey="disableFreeShippingMethod"/>
<deleteData createDataKey="createCartPriceRule" stepKey="deleteCartPriceRule"/>
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
<!-- Catalog Prices and Apply Discount On Prices switched to Excluding Tax -->
<magentoCLI command="config:set tax/calculation/price_includes_tax 0" stepKey="setCatalogPriceConfigToExcludingTax"/>
<magentoCLI command="config:set tax/calculation/discount_tax 0" stepKey="setApplyDiscountOnPricesConfigToExcludingTax"/>
</after>
<!-- Create order -->
<actionGroup ref="NavigateToNewOrderPageExistingCustomerActionGroup" stepKey="goToCreateOrderPage">
<argument name="customer" value="$$createCustomer$$"/>
</actionGroup>
<actionGroup ref="AddSimpleProductToOrderActionGroup" stepKey="addProductToOrder">
<argument name="product" value="$$createSimpleProduct$$"/>
</actionGroup>
<actionGroup ref="AdminApplyCouponToOrderActionGroup" stepKey="applyCoupon">
<argument name="couponCode" value="$$createCouponForCartPriceRule.code$$"/>
</actionGroup>
<actionGroup ref="OrderSelectFreeShippingActionGroup" stepKey="selectFreeShippingOption"/>
<actionGroup ref="AdminSubmitOrderActionGroup" stepKey="submitOrder"/>
<grabTextFrom selector="|Order # (\d+)|" stepKey="getOrderId"/>
<actionGroup ref="AdminOrdersPageOpenActionGroup" stepKey="goToOrdersPage"/>
<actionGroup ref="FilterOrderGridByIdActionGroup" stepKey="filterOrdersGridById">
<argument name="orderId" value="$getOrderId"/>
</actionGroup>
<click selector="{{AdminDataGridTableSection.firstRow}}" stepKey="openFilteredOrder"/>
<actionGroup ref="AdminClickInvoiceButtonOrderViewActionGroup" stepKey="clickInvoiceTab"/>
<!-- Check that invoice item row total and order grand total are equal zero -->
<see selector="{{AdminInvoiceTotalSection.itemTotalPrice}}" userInput="$0.00" stepKey="seeCorrectItemRowTotal"/>
<see selector="{{AdminInvoiceTotalSection.grandTotal}}" userInput="$0.00" stepKey="seeCorrectOrderGrandTotal"/>
</test>
</tests>
4 changes: 4 additions & 0 deletions app/code/Magento/SalesRule/Test/Mftf/Data/SalesRuleData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@
<data key="simple_free_shipping">1</data>
</entity>

<entity name="SalesRuleSpecificCouponWithHundredPercentDiscount" extends="SalesRuleSpecificCouponWithPercentDiscount">
<data key="discount_amount">100</data>
</entity>

<entity name="ActiveSalesRuleForNotLoggedIn" type="SalesRule">
<data key="name" unique="suffix">SimpleSalesRule</data>
<data key="description">Sales Rule Description</data>
Expand Down