Skip to content

Commit

Permalink
Merge pull request #3503 from magento-mpi/port-94472
Browse files Browse the repository at this point in the history
[MPI]-port-94472
  • Loading branch information
viktym authored Dec 4, 2018
2 parents 0aa3191 + 9f66bed commit ab30035
Show file tree
Hide file tree
Showing 19 changed files with 353 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/actionGroupSchema.xsd">

<actionGroup name="AdminOrderBraintreeFillActionGroup">
<!--Select Braintree Payment method on Admin Order Create Page-->
<click stepKey="chooseBraintree" selector="{{NewOrderSection.creditCardBraintree}}"/>
<waitForPageLoad stepKey="waitForBraintreeConfigs" time="5"/>
<click stepKey="openCardTypes" selector="{{NewOrderSection.openCardTypes}}"/>
<waitForPageLoad stepKey="waitForCardTypes" time="3"/>
<click stepKey="chooseCardType" selector="{{NewOrderSection.masterCard}}"/>
<waitForPageLoad stepKey="waitForCardSelected" time="3"/>

<!--Choose Master Card from drop-down list-->
<switchToIFrame stepKey="switchToCardNumber" selector="{{NewOrderSection.cardFrame}}"/>
<fillField stepKey="fillCardNumber" selector="{{NewOrderSection.creditCardNumber}}" userInput="{{PaymentAndShippingInfo.cardNumber}}"/>
<waitForPageLoad stepKey="waitForFillCardNumber" time="1"/>
<switchToIFrame stepKey="switchBackFromCard"/>

<!--Fill expire date-->
<switchToIFrame stepKey="switchToExpirationMonth" selector="{{NewOrderSection.monthFrame}}"/>
<fillField stepKey="fillMonth" selector="{{NewOrderSection.expirationMonth}}" userInput="{{PaymentAndShippingInfo.month}}"/>
<waitForPageLoad stepKey="waitForFillMonth" time="1"/>
<switchToIFrame stepKey="switchBackFromMonth"/>
<switchToIFrame stepKey="switchToExpirationYear" selector="{{NewOrderSection.yearFrame}}"/>
<fillField stepKey="fillYear" selector="{{NewOrderSection.expirationYear}}" userInput="{{PaymentAndShippingInfo.year}}"/>
<waitForPageLoad stepKey="waitForFillYear" time="1"/>
<switchToIFrame stepKey="switchBackFromYear"/>

<!--Fill CVW code-->
<switchToIFrame stepKey="switchToCVV" selector="{{NewOrderSection.cvvFrame}}"/>
<fillField stepKey="fillCVV" selector="{{NewOrderSection.cvv}}" userInput="{{PaymentAndShippingInfo.cvv}}"/>
<wait stepKey="waitForFillCVV" time="1"/>
<switchToIFrame stepKey="switchBackFromCVV"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<requiredEntity type="merchant_id">MerchantId</requiredEntity>
<requiredEntity type="public_key">PublicKey</requiredEntity>
<requiredEntity type="private_key">PrivateKey</requiredEntity>
<requiredEntity type="active">Status</requiredEntity>
</entity>
<entity name="BraintreeTitle" type="title">
<data key="value">Credit Card (Braintree)</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<element name="sales" type="button" selector="//li[@id='menu-magento-sales-sales']"/>
<element name="catalog" type="button" selector="//li[@id='menu-magento-catalog-catalog']"/>
<element name="customers" type="button" selector="//li[@id='menu-magento-customer-customer']"/>
<element name="marketing" type="button" selector="//li[@id='//li[@id='menu-magento-backend-marketing']']"/>
<element name="marketing" type="button" selector="//li[@id='menu-magento-backend-marketing']"/>
<element name="content" type="button" selector="//li[@id='menu-magento-backend-content']"/>
<element name="reports" type="button" selector="//li[@id='menu-magento-reports-report']"/>
<element name="stores" type="button" selector="//li[@id='menu-magento-backend-stores']"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?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="CreateAdminOrderPayedWithOnlinePaymentIncludingTaxAndDiscount">
<annotations>
<features value="Braintree"/>
<stories value="Get access to a New Credit Memo Page from Invocie for Order payed with online payment via Admin"/>
<title value="Admin should be able to open a New Credit Memo Page from Invoice Page for Order with tax and discount and payed using online payment method"/>
<description value="Admin should be able to open a New Credit Memo Page from Invoice Page for Order with tax and discount and payed using online payment method"/>
<severity value="CRITICAL"/>
<testCaseId value="MAGETWO-94472"/>
<group value="braintree"/>
</annotations>

<before>
<!--Create Default Category-->
<createData entity="SimpleSubCategory" stepKey="createCategory"/>

<!--Create Simple product-->
<createData entity="_defaultProduct" stepKey="simpleProduct">
<requiredEntity createDataKey="createCategory"/>
</createData>

<!--Create Tax Rule is based on default tax rates (Stores>Tax Rule) US-CA-*-Rate 1 = 8.2500 US-NY-*-Rate 1 = 8.3750 -->
<createData entity="SimpleTaxRule" stepKey="createTaxRule"/>

<!--Configure Braintree Payment method-->
<createData entity="BraintreeConfig" stepKey="BraintreeConfigurationData"/>
<createData entity="CustomBraintreeConfigurationData" stepKey="enableBraintree"/>

<!--Create Retailer Customer with US_CA address-->
<createData entity="Simple_US_Customer_CA" stepKey="simpleCustomer">
<field key="group_id">3</field>
</createData>

<!--Login as Admin User-->
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
</before>

<after>
<!--Delete Cart Price Rule-->
<actionGroup ref="AdminDeleteCartPriceRuleForRetailerActionGroup" stepKey="deleteSalesRule"/>

<!--Set to default configuration Tax Shipping Class-->
<actionGroup ref="setDefaultShippingTaxClass" stepKey="setdefaultClass"/>

<!--Delete Simple Sub Category-->
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>

<!--Delete Simple Product-->
<deleteData createDataKey="simpleProduct" stepKey="deleteSimpleProduct"/>

<!-- Delete Tax Rule -->
<deleteData createDataKey="createTaxRule" stepKey="deleteTaxRule"/>

<!-- Rollback Braintree to Default -->
<createData entity="RollBackCustomBraintreeConfigurationData" stepKey="rollbackBraintreeConfig"/>

<!--Delete Customer-->
<deleteData createDataKey="simpleCustomer" stepKey="deleteSimpleCustomer"/>

<!--Log Out-->
<actionGroup ref="logout" stepKey="logout"/>
</after>

<!-- Create a cart price rule with 10% discount for whole cart -->
<click selector="{{AdminMenuSection.marketing}}" stepKey="clickOnMarketing" />
<waitForPageLoad stepKey="waitForMarketing" time="3"/>
<click selector="{{CartPriceRulesSubmenuSection.cartPriceRules}}" stepKey="clickOnCartPriceRules"/>
<waitForPageLoad stepKey="waitForCartPriceRules" time="3"/>
<click selector="{{AdminCartPriceRulesSection.addNewRuleButton}}" stepKey="clickAddNewRule"/>
<fillField selector="{{AdminCartPriceRulesFormSection.ruleName}}" userInput="{{SimpleSalesRule.name}}" stepKey="fillRuleName"/>
<selectOption selector="{{AdminCartPriceRulesFormSection.websites}}" userInput="Main Website" stepKey="selectWebsites"/>
<actionGroup ref="selectRetailerCustomerGroup" stepKey="selectRetailerCustomerGroup"/>
<click selector="{{AdminCartPriceRulesFormSection.actionsHeader}}" stepKey="clickToExpandActions"/>
<selectOption selector="{{AdminCartPriceRulesFormSection.apply}}" userInput="Percent of product price discount" stepKey="selectActionType"/>
<fillField selector="{{AdminCartPriceRulesFormSection.discountAmount}}" userInput="10" stepKey="fillDiscountAmount"/>
<click selector="{{AdminCartPriceRulesFormSection.save}}" stepKey="clickSaveButton"/>
<waitForPageLoad stepKey="waitForCartRuleLoad" time="3"/>
<see selector="{{AdminCartPriceRulesSection.messages}}" userInput="You saved the rule." stepKey="seeSuccessMessage"/>

<!--Set Taxable Goods for Shipping Tax Class-->
<actionGroup ref="changeShippingTaxClass" stepKey="changeShippingTaxClass"/>

<!--Adding Special price to product-->
<amOnPage url="{{AdminProductEditPage.url($$simpleProduct.id$$)}}" stepKey="openAdminProductEditPage"/>
<actionGroup ref="AddSpecialPriceToProductActionGroup" stepKey="addSpecialPrice"/>
<actionGroup ref="saveProductForm" stepKey="saveProductForm"/>

<!--Create New Order-->
<actionGroup ref="navigateToNewOrderPageExistingCustomer" stepKey="navigateToNewOrderWithExistingCustomer">
<argument name="customer" value="$$simpleCustomer$$"/>
</actionGroup>

<!--Add a product to order-->
<actionGroup ref="addSimpleProductToOrder" stepKey="addProductToOrder">
<argument name="product" value="$$simpleProduct$$"/>
</actionGroup>

<!--Select FlatRate shipping method-->
<actionGroup ref="orderSelectFlatRateShipping" stepKey="orderSelectFlatRateShippingMethod"/>

<!--Select Braintree online Payment method -->
<actionGroup ref="AdminOrderBraintreeFillActionGroup" stepKey="selectCreditCardPayment"/>

<!--Submit Order-->
<click stepKey="submitOrder" selector="{{NewOrderSection.submitOrder}}"/>
<waitForPageLoad stepKey="waitForSubmitOrder" time="5"/>
<see selector="{{AdminOrderDetailsMessagesSection.successMessage}}" userInput="You created the order." stepKey="seeOrderSuccessMessage" after="waitForSubmitOrder"/>

<!-- Create New invoice-->
<actionGroup ref="adminFastCreateInvoice" stepKey="createInvoice"/>

<!--Get access to Credit Memo page from Invoice page-->
<click selector="{{AdminInvoiceMainActionsSection.openNewCreditMemoFromInvoice}}" stepKey="clickCreateNewCreditMemo"/>
<waitForPageLoad stepKey="waitForLoadNewCreditMemoPage" time="5"/>
<see selector="{{AdminCreditMemoOrderInformationSection.orderStatus}}" userInput="Processing" stepKey="seeNewCreditMemo"/>
</test>
</tests>
11 changes: 5 additions & 6 deletions app/code/Magento/Sales/Model/Order/Creditmemo/Total/Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public function __construct(
}

/**
* Collects credit memo shipping totals.
*
* @param \Magento\Sales\Model\Order\Creditmemo $creditmemo
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
Expand All @@ -55,12 +57,10 @@ public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
$orderShippingInclTax = $order->getShippingInclTax();
$orderBaseShippingInclTax = $order->getBaseShippingInclTax();
$allowedTaxAmount = $order->getShippingTaxAmount() - $order->getShippingTaxRefunded();
$baseAllowedTaxAmount = $order->getBaseShippingTaxAmount() - $order->getBaseShippingTaxRefunded();
$allowedAmountInclTax = $allowedAmount + $allowedTaxAmount;
$baseAllowedAmountInclTax = $baseAllowedAmount + $baseAllowedTaxAmount;

// for the credit memo
$shippingAmount = $baseShippingAmount = $shippingInclTax = $baseShippingInclTax = 0;
$baseAllowedAmountInclTax = $orderBaseShippingInclTax
- $order->getBaseShippingRefunded()
- $order->getBaseShippingTaxRefunded();

// Check if the desired shipping amount to refund was specified (from invoice or another source).
if ($creditmemo->hasBaseShippingAmount()) {
Expand Down Expand Up @@ -128,7 +128,6 @@ private function isSuppliedShippingAmountInclTax($order)

/**
* Get the Tax Config.
* In a future release, will become a constructor parameter.
*
* @return \Magento\Tax\Model\Config
*
Expand Down
13 changes: 5 additions & 8 deletions app/code/Magento/Sales/Model/Order/Creditmemo/Total/Tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
*/
namespace Magento\Sales\Model\Order\Creditmemo\Total;

/**
* Collects credit memo taxes.
*/
class Tax extends AbstractTotal
{
/**
* Collects credit memo taxes.
*
* @param \Magento\Sales\Model\Order\Creditmemo $creditmemo
* @return $this
*
Expand Down Expand Up @@ -79,18 +84,10 @@ public function collect(\Magento\Sales\Model\Order\Creditmemo $creditmemo)
$totalDiscountTaxCompensation += $invoice->getShippingDiscountTaxCompensationAmount() * $taxFactor;
$baseTotalDiscountTaxCompensation +=
$invoice->getBaseShippingDiscountTaxCompensationAmnt() * $taxFactor;
$shippingDiscountTaxCompensationAmount =
$invoice->getShippingDiscountTaxCompensationAmount() * $taxFactor;
$baseShippingDiscountTaxCompensationAmount =
$invoice->getBaseShippingDiscountTaxCompensationAmnt() * $taxFactor;
$shippingTaxAmount = $creditmemo->roundPrice($shippingTaxAmount);
$baseShippingTaxAmount = $creditmemo->roundPrice($baseShippingTaxAmount, 'base');
$totalDiscountTaxCompensation = $creditmemo->roundPrice($totalDiscountTaxCompensation);
$baseTotalDiscountTaxCompensation = $creditmemo->roundPrice($baseTotalDiscountTaxCompensation, 'base');
$shippingDiscountTaxCompensationAmount =
$creditmemo->roundPrice($shippingDiscountTaxCompensationAmount);
$baseShippingDiscountTaxCompensationAmount =
$creditmemo->roundPrice($baseShippingDiscountTaxCompensationAmount, 'base');
if ($taxFactor < 1 && $invoice->getShippingTaxAmount() > 0) {
$isPartialShippingRefunded = true;
}
Expand Down
28 changes: 18 additions & 10 deletions app/code/Magento/Sales/Model/Order/Invoice/Total/Tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*/
namespace Magento\Sales\Model\Order\Invoice\Total;

/**
* Collects invoice taxes.
*/
class Tax extends AbstractTotal
{
/**
Expand Down Expand Up @@ -69,26 +72,31 @@ public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
}
}

$taxDiscountCompensationAmt = $totalDiscountTaxCompensation;
$baseTaxDiscountCompensationAmt = $baseTotalDiscountTaxCompensation;
$allowedDiscountTaxCompensation = $order->getDiscountTaxCompensationAmount() -
$order->getDiscountTaxCompensationInvoiced();
$allowedBaseDiscountTaxCompensation = $order->getBaseDiscountTaxCompensationAmount() -
$order->getBaseDiscountTaxCompensationInvoiced();

if ($this->_canIncludeShipping($invoice)) {
$totalTax += $order->getShippingTaxAmount();
$baseTotalTax += $order->getBaseShippingTaxAmount();
$totalDiscountTaxCompensation += $order->getShippingDiscountTaxCompensationAmount();
$baseTotalDiscountTaxCompensation += $order->getBaseShippingDiscountTaxCompensationAmnt();

$allowedDiscountTaxCompensation += $order->getShippingDiscountTaxCompensationAmount() -
$order->getShippingDiscountTaxCompensationInvoiced();
$allowedBaseDiscountTaxCompensation += $order->getBaseShippingDiscountTaxCompensationAmnt() -
$order->getBaseShippingDiscountTaxCompensationInvoiced();

$invoice->setShippingTaxAmount($order->getShippingTaxAmount());
$invoice->setBaseShippingTaxAmount($order->getBaseShippingTaxAmount());
$invoice->setShippingDiscountTaxCompensationAmount($order->getShippingDiscountTaxCompensationAmount());
$invoice->setBaseShippingDiscountTaxCompensationAmnt($order->getBaseShippingDiscountTaxCompensationAmnt());
}
$allowedTax = $order->getTaxAmount() - $order->getTaxInvoiced();
$allowedBaseTax = $order->getBaseTaxAmount() - $order->getBaseTaxInvoiced();
$allowedDiscountTaxCompensation = $order->getDiscountTaxCompensationAmount() +
$order->getShippingDiscountTaxCompensationAmount() -
$order->getDiscountTaxCompensationInvoiced() -
$order->getShippingDiscountTaxCompensationInvoiced();
$allowedBaseDiscountTaxCompensation = $order->getBaseDiscountTaxCompensationAmount() +
$order->getBaseShippingDiscountTaxCompensationAmnt() -
$order->getBaseDiscountTaxCompensationInvoiced() -
$order->getBaseShippingDiscountTaxCompensationInvoiced();

if ($invoice->isLast()) {
$totalTax = $allowedTax;
Expand All @@ -107,8 +115,8 @@ public function collect(\Magento\Sales\Model\Order\Invoice $invoice)

$invoice->setTaxAmount($totalTax);
$invoice->setBaseTaxAmount($baseTotalTax);
$invoice->setDiscountTaxCompensationAmount($totalDiscountTaxCompensation);
$invoice->setBaseDiscountTaxCompensationAmount($baseTotalDiscountTaxCompensation);
$invoice->setDiscountTaxCompensationAmount($taxDiscountCompensationAmt);
$invoice->setBaseDiscountTaxCompensationAmount($baseTaxDiscountCompensationAmt);

$invoice->setGrandTotal($invoice->getGrandTotal() + $totalTax + $totalDiscountTaxCompensation);
$invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseTotalTax + $baseTotalDiscountTaxCompensation);
Expand Down
10 changes: 5 additions & 5 deletions app/code/Magento/Sales/Model/Service/CreditmemoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,15 @@ protected function validateForRefund(\Magento\Sales\Api\Data\CreditmemoInterface
throw new \Magento\Framework\Exception\LocalizedException(
__(
'The most money available to refund is %1.',
$creditmemo->getOrder()->formatBasePrice($baseAvailableRefund)
$creditmemo->getOrder()->formatPriceTxt($baseAvailableRefund)
)
);
}
return true;
}

/**
* Gets the instance of RefundAdapterInterface
* Initializes RefundAdapterInterface dependency.
*
* @return \Magento\Sales\Model\Order\RefundAdapterInterface
* @deprecated 100.1.3
Expand All @@ -225,7 +225,7 @@ private function getRefundAdapter()
}

/**
* Gets instance of ResourceConnection.
* Initializes ResourceConnection dependency.
*
* @return \Magento\Framework\App\ResourceConnection|mixed
* @deprecated 100.1.3
Expand All @@ -240,7 +240,7 @@ private function getResource()
}

/**
* Gets instance of OrderRepositoryInterface.
* Initializes OrderRepositoryInterface dependency.
*
* @return \Magento\Sales\Api\OrderRepositoryInterface
* @deprecated 100.1.3
Expand All @@ -255,7 +255,7 @@ private function getOrderRepository()
}

/**
* Gets instance of InvoiceRepositoryInterface
* Initializes InvoiceRepositoryInterface dependency.
*
* @return \Magento\Sales\Api\InvoiceRepositoryInterface
* @deprecated 100.1.3
Expand Down
Loading

0 comments on commit ab30035

Please sign in to comment.