Skip to content

Commit 7fd1f7e

Browse files
committed
Merge remote-tracking branch 'origin/MC-17003' into 2.3-develop-pr59
2 parents 029b530 + 55a2fb8 commit 7fd1f7e

File tree

9 files changed

+224
-5
lines changed

9 files changed

+224
-5
lines changed

app/code/Magento/Sales/Block/Adminhtml/Order/Creditmemo/Create/Adjustments.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,20 @@ public function getShippingLabel()
111111
}
112112
return $label;
113113
}
114+
115+
/**
116+
* Get update totals url.
117+
*
118+
* @return string
119+
*/
120+
public function getUpdateTotalsUrl(): string
121+
{
122+
return $this->getUrl(
123+
'sales/*/updateQty',
124+
[
125+
'order_id' => $this->getSource()->getOrderId(),
126+
'invoice_id' => $this->getRequest()->getParam('invoice_id', null),
127+
]
128+
);
129+
}
114130
}

app/code/Magento/Sales/Block/Adminhtml/Order/Creditmemo/Create/Items.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ protected function _prepareLayout()
5656
$this->addChild(
5757
'update_button',
5858
\Magento\Backend\Block\Widget\Button::class,
59-
['label' => __('Update Qty\'s'), 'class' => 'update-button', 'onclick' => $onclick]
59+
['label' => __('Update Qty\'s'), 'class' => 'update-button secondary', 'onclick' => $onclick]
60+
);
61+
$this->addChild(
62+
'update_totals_button',
63+
\Magento\Backend\Block\Widget\Button::class,
64+
['label' => __('Update Totals'), 'class' => 'update-totals-button secondary', 'onclick' => $onclick]
6065
);
6166

6267
if ($this->getCreditmemo()->canRefund()) {
@@ -176,6 +181,16 @@ public function getUpdateButtonHtml()
176181
return $this->getChildHtml('update_button');
177182
}
178183

184+
/**
185+
* Get update totals button html
186+
*
187+
* @return string
188+
*/
189+
public function getUpdateTotalsButtonHtml(): string
190+
{
191+
return $this->getChildHtml('update_totals_button');
192+
}
193+
179194
/**
180195
* Get update url
181196
*

app/code/Magento/Sales/Test/Mftf/ActionGroup/AdminCreditMemoActionGroup.xml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,25 @@
3737
</arguments>
3838
<see selector="{{AdminCreditMemoItemsSection.skuColumn}}" userInput="{{product.sku}}" stepKey="seeProductSkuInGrid"/>
3939
</actionGroup>
40-
</actionGroups>
40+
<actionGroup name="StartToCreateCreditMemoActionGroup">
41+
<arguments>
42+
<argument name="orderId" type="string"/>
43+
</arguments>
44+
<amOnPage url="{{AdminOrderPage.url(orderId)}}" stepKey="navigateToOrderPage"/>
45+
<click selector="{{AdminOrderDetailsMainActionsSection.creditMemo}}" stepKey="clickCreditMemo"/>
46+
<waitForElementVisible selector="{{AdminHeaderSection.pageTitle}}" stepKey="waitForPageTitle"/>
47+
<see selector="{{AdminHeaderSection.pageTitle}}" userInput="New Memo" stepKey="seeNewMemoPageTitle"/>
48+
</actionGroup>
49+
<actionGroup name="SubmitCreditMemoActionGroup">
50+
<grabFromCurrentUrl regex="~/order_id/(\d+)/~" stepKey="grabOrderId"/>
51+
<waitForElementVisible selector="{{AdminCreditMemoTotalSection.submitRefundOffline}}" stepKey="waitButtonEnabled"/>
52+
<click selector="{{AdminCreditMemoTotalSection.submitRefundOffline}}" stepKey="clickSubmitCreditMemo"/>
53+
<waitForElementVisible selector="{{AdminMessagesSection.successMessage}}" stepKey="waitForMessageAppears"/>
54+
<see selector="{{AdminMessagesSection.successMessage}}" userInput="You created the credit memo." stepKey="seeCreditMemoCreateSuccess"/>
55+
<seeInCurrentUrl url="{{AdminOrderDetailsPage.url}}$grabOrderId" stepKey="seeViewOrderPageCreditMemo"/>
56+
</actionGroup>
57+
<actionGroup name="UpdateCreditMemoTotalsActionGroup">
58+
<waitForElementVisible selector="{{AdminCreditMemoTotalSection.updateTotals}}" stepKey="waitUpdateTotalsButtonEnabled"/>
59+
<click selector="{{AdminCreditMemoTotalSection.updateTotals}}" stepKey="clickUpdateTotals"/>
60+
</actionGroup>
61+
</actionGroups>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222
<element name="creditMemoItem" type="text" selector="#sales_order_view_tabs_order_creditmemos"/>
2323
<element name="viewMemo" type="text" selector="div#sales_order_view_tabs_order_creditmemos_content a.action-menu-item"/>
2424
<element name="refundOffline" type="button" selector=".order-totals-actions button[data-ui-id='order-items-submit-offline']"/>
25+
<element name="updateTotals" type="button" selector=".update-totals-button" timeout="30"/>
2526
</section>
2627
</sections>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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="Create credit memo"/>
15+
<title value="Checking Credit Memo Update Totals button"/>
16+
<description value="Checking Credit Memo Update Totals button"/>
17+
<severity value="MAJOR"/>
18+
<testCaseId value="MC-18159"/>
19+
<useCaseId value="MC-17003"/>
20+
<group value="sales"/>
21+
</annotations>
22+
<before>
23+
<!--Create product-->
24+
<createData entity="SimpleProduct2" stepKey="createSimpleProduct"/>
25+
<!--Create customer-->
26+
<createData entity="Simple_US_CA_Customer" stepKey="createCustomer"/>
27+
<!--Login to admin page-->
28+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
29+
</before>
30+
<after>
31+
<!--Delete simple product-->
32+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
33+
<!--Delete customer-->
34+
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
35+
<actionGroup ref="logout" stepKey="logout"/>
36+
</after>
37+
38+
<actionGroup ref="CreateOrderActionGroup" stepKey="createOrder">
39+
<argument name="product" value="$$createSimpleProduct$$"/>
40+
<argument name="customer" value="$$createCustomer$$"/>
41+
</actionGroup>
42+
<grabFromCurrentUrl regex="~/order_id/(\d+)/~" stepKey="grabOrderId"/>
43+
<!--Create invoice-->
44+
<actionGroup ref="StartCreateInvoiceFromOrderPage" stepKey="startCreateInvoice"/>
45+
<!--Submit invoice-->
46+
<actionGroup ref="SubmitInvoice" stepKey="submitInvoice"/>
47+
48+
<!--Create Credit Memo-->
49+
<actionGroup ref="StartToCreateCreditMemoActionGroup" stepKey="startToCreateCreditMemo">
50+
<argument name="orderId" value="{$grabOrderId}"/>
51+
</actionGroup>
52+
<fillField selector="{{AdminCreditMemoTotalSection.refundShipping}}" userInput="0" stepKey="setRefundShipping"/>
53+
<actionGroup ref="UpdateCreditMemoTotalsActionGroup" stepKey="updateCreditMemoTotals"/>
54+
<actionGroup ref="SubmitCreditMemoActionGroup" stepKey="submitCreditMemo"/>
55+
56+
<!--Go to Credit Memo tab-->
57+
<click selector="{{AdminOrderDetailsOrderViewSection.creditMemos}}" stepKey="clickCreditMemosTab"/>
58+
<waitForPageLoad stepKey="waitForCreditMemosGridToLoad"/>
59+
60+
<!--Check refunded total -->
61+
<see selector="{{AdminOrderCreditMemosTabSection.gridRow('1')}}" userInput="$123" stepKey="seeCreditMemoInGrid"/>
62+
</test>
63+
</tests>

app/code/Magento/Sales/view/adminhtml/templates/order/creditmemo/create/items.phtml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
<span class="title"><?= $block->escapeHtml(__('Refund Totals')) ?></span>
101101
</div>
102102
<?= $block->getChildHtml('creditmemo_totals') ?>
103+
<div class="totals-actions"><?= $block->getUpdateTotalsButtonHtml() ?></div>
103104
<div class="order-totals-actions">
104105
<div class="field choice admin__field admin__field-option field-append-comments">
105106
<input id="notify_customer"
@@ -139,8 +140,8 @@ require(['jquery'], function(jQuery){
139140

140141
//<![CDATA[
141142
var submitButtons = jQuery('.submit-button');
142-
var updateButtons = jQuery('.update-button');
143-
var fields = jQuery('.qty-input');
143+
var updateButtons = jQuery('.update-button,.update-totals-button');
144+
var fields = jQuery('.qty-input,.order-subtotal-table input[type="text"]');
144145

145146
function enableButtons(buttons) {
146147
buttons.removeClass('disabled').prop('disabled', false);

app/design/adminhtml/Magento/backend/Magento_Sales/web/css/source/module/order/_total.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
}
2323
}
2424

25+
.totals-actions {
26+
text-align: right;
27+
}
28+
2529
.order-totals-actions {
2630
margin-top: @indent__s;
2731
.actions {

dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Creditmemo/Totals.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,34 @@ class Totals extends \Magento\Sales\Test\Block\Adminhtml\Order\Totals
2727
*/
2828
protected $capture = '[name="invoice[capture_case]"]';
2929

30+
/**
31+
* Refund Shipping css selector.
32+
*
33+
* @var string
34+
*/
35+
private $refundShippingSelector = '#shipping_amount';
36+
37+
/**
38+
* Adjustment Refund css selector.
39+
*
40+
* @var string
41+
*/
42+
private $adjustmentRefundSelector = '#adjustment_positive';
43+
44+
/**
45+
* Adjustment Fee css selector.
46+
*
47+
* @var string
48+
*/
49+
private $adjustmentFeeSelector = '#adjustment_negative';
50+
51+
/**
52+
* Update Totals button css selector.
53+
*
54+
* @var string
55+
*/
56+
private $updateTotalsSelector = '.update-totals-button';
57+
3058
/**
3159
* Submit invoice.
3260
*
@@ -57,4 +85,44 @@ public function setCaptureOption($option)
5785
{
5886
$this->_rootElement->find($this->capture, Locator::SELECTOR_CSS, 'select')->setValue($option);
5987
}
88+
89+
/**
90+
* Get Refund Shipping input element.
91+
*
92+
* @return \Magento\Mtf\Client\ElementInterface
93+
*/
94+
public function getRefundShippingElement()
95+
{
96+
return $this->_rootElement->find($this->refundShippingSelector, Locator::SELECTOR_CSS);
97+
}
98+
99+
/**
100+
* Get Adjustment Refund input element.
101+
*
102+
* @return \Magento\Mtf\Client\ElementInterface
103+
*/
104+
public function getAdjustmentRefundElement()
105+
{
106+
return $this->_rootElement->find($this->adjustmentRefundSelector, Locator::SELECTOR_CSS);
107+
}
108+
109+
/**
110+
* Get Adjustment Fee input element.
111+
*
112+
* @return \Magento\Mtf\Client\ElementInterface
113+
*/
114+
public function getAdjustmentFeeElement()
115+
{
116+
return $this->_rootElement->find($this->adjustmentFeeSelector, Locator::SELECTOR_CSS);
117+
}
118+
119+
/**
120+
* Click update totals button.
121+
*
122+
* @return void
123+
*/
124+
public function clickUpdateTotals()
125+
{
126+
$this->_rootElement->find($this->updateTotalsSelector)->click();
127+
}
60128
}

dev/tests/functional/tests/app/Magento/Sales/Test/TestStep/CreateCreditMemoStep.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,12 @@ public function run()
9595
if ($this->compare($items, $refundData)) {
9696
$this->orderCreditMemoNew->getFormBlock()->updateQty();
9797
}
98-
98+
$hasChangeTotals = $this->isTotalsDataChanged($refundData);
9999
$this->orderCreditMemoNew->getFormBlock()->fillFormData($refundData);
100+
if ($hasChangeTotals) {
101+
$this->orderCreditMemoNew->getTotalsBlock()->clickUpdateTotals();
102+
}
103+
100104
$this->orderCreditMemoNew->getFormBlock()->submit();
101105
}
102106

@@ -116,4 +120,30 @@ protected function getCreditMemoIds()
116120
$this->salesOrderView->getOrderForm()->openTab('creditmemos');
117121
return $this->salesOrderView->getOrderForm()->getTab('creditmemos')->getGridBlock()->getIds();
118122
}
123+
124+
/**
125+
* Is totals data changed.
126+
*
127+
* @param array $data
128+
* @return bool
129+
*/
130+
private function isTotalsDataChanged(array $data): bool
131+
{
132+
$compareData = [
133+
'shipping_amount' =>
134+
$this->orderCreditMemoNew->getTotalsBlock()->getRefundShippingElement()->getValue(),
135+
'adjustment_positive' =>
136+
$this->orderCreditMemoNew->getTotalsBlock()->getAdjustmentRefundElement()->getValue(),
137+
'adjustment_negative' =>
138+
$this->orderCreditMemoNew->getTotalsBlock()->getAdjustmentFeeElement()->getValue(),
139+
];
140+
141+
foreach ($compareData as $fieldName => $fieldValue) {
142+
if (isset($data['form_data'][$fieldName]) && $fieldValue != $data['form_data'][$fieldName]) {
143+
return true;
144+
}
145+
}
146+
147+
return false;
148+
}
119149
}

0 commit comments

Comments
 (0)