Skip to content

Commit 683a87d

Browse files
committed
MC-17003: Update Totals button is missing from Credit Memo page
1 parent c63b388 commit 683a87d

File tree

9 files changed

+230
-4
lines changed

9 files changed

+230
-4
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ protected function _prepareLayout()
5858
\Magento\Backend\Block\Widget\Button::class,
5959
['label' => __('Update Qty\'s'), 'class' => 'update-button', 'onclick' => $onclick]
6060
);
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]
65+
);
6166

6267
if ($this->getCreditmemo()->canRefund()) {
6368
if ($this->getCreditmemo()->getInvoice() && $this->getCreditmemo()->getInvoice()->getTransactionId()) {
@@ -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+
<see selector="{{AdminHeaderSection.pageTitle}}" userInput="New Memo" stepKey="seeNewMemoPageTitle"/>
47+
</actionGroup>
48+
<actionGroup name="SubmitCreditMemoActionGroup">
49+
<waitForElementVisible selector="{{AdminCreditMemoTotalSection.submitRefundOffline}}" stepKey="waitButtonEnabled"/>
50+
<click selector="{{AdminCreditMemoTotalSection.submitRefundOffline}}" stepKey="clickSubmitCreditMemo"/>
51+
<waitForElementVisible selector="{{AdminMessagesSection.successMessage}}" stepKey="waitForMessageAppears"/>
52+
<see selector="{{AdminMessagesSection.successMessage}}" userInput="You created the credit memo." stepKey="seeCreditMemoCreateSuccess"/>
53+
<grabFromCurrentUrl regex="~/order_id/(\d+)/~" stepKey="grabOrderId"/>
54+
<seeInCurrentUrl url="{{AdminOrderDetailsPage.url}}$grabOrderId" stepKey="seeViewOrderPageCreditMemo"/>
55+
</actionGroup>
56+
<actionGroup name="UpdateCreditMemoTotalsActionGroup">
57+
<waitForElementVisible selector="{{AdminCreditMemoTotalSection.updateTotals}}" stepKey="waitUpdateTotalsButtonEnabled"/>
58+
<click selector="{{AdminCreditMemoTotalSection.updateTotals}}" stepKey="clickUpdateTotals"/>
59+
<waitForLoadingMaskToDisappear stepKey="waitForUpdateTotals"/>
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: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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 category-->
24+
<createData entity="_defaultCategory" stepKey="createCategory"/>
25+
<!--Create simple product-->
26+
<createData entity="_defaultProduct" stepKey="createSimpleProduct">
27+
<requiredEntity createDataKey="createCategory"/>
28+
</createData>
29+
<!--Create customer-->
30+
<createData entity="Simple_US_CA_Customer" stepKey="createCustomer"/>
31+
<!--Login to admin page-->
32+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
33+
</before>
34+
<after>
35+
<!--Delete category-->
36+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
37+
<!--Delete simple product-->
38+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
39+
<!--Delete customer-->
40+
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
41+
<actionGroup ref="logout" stepKey="logout"/>
42+
</after>
43+
44+
<actionGroup ref="CreateOrderActionGroup" stepKey="createOrder">
45+
<argument name="product" value="$$createSimpleProduct$$"/>
46+
<argument name="customer" value="$$createCustomer$$"/>
47+
</actionGroup>
48+
<grabFromCurrentUrl regex="~/order_id/(\d+)/~" stepKey="grabOrderId"/>
49+
<!--Create invoice-->
50+
<actionGroup ref="StartCreateInvoiceFromOrderPage" stepKey="startCreateInvoice"/>
51+
<!--Submit invoice-->
52+
<actionGroup ref="SubmitInvoice" stepKey="submitInvoice"/>
53+
54+
<!--Create Credit Memo-->
55+
<actionGroup ref="StartToCreateCreditMemoActionGroup" stepKey="startToCreateCreditMemo">
56+
<argument name="orderId" value="{$grabOrderId}"/>
57+
</actionGroup>
58+
<fillField selector="{{AdminCreditMemoTotalSection.refundShipping}}" userInput="0" stepKey="setRefundShipping"/>
59+
<actionGroup ref="UpdateCreditMemoTotalsActionGroup" stepKey="updateCreditMemoTotals"/>
60+
<actionGroup ref="SubmitCreditMemoActionGroup" stepKey="submitCreditMemo"/>
61+
62+
<!--Go to Credit Memo tab-->
63+
<click selector="{{AdminOrderDetailsOrderViewSection.creditMemos}}" stepKey="clickCreditMemosTab"/>
64+
<waitForPageLoad stepKey="waitForCreditMemosGridToLoad"/>
65+
66+
<!--Check refunded total -->
67+
<see selector="{{AdminOrderCreditMemosTabSection.gridRow('1')}}" userInput="$123" stepKey="seeCreditMemoInGrid"/>
68+
</test>
69+
</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 = '//input[@id=\'shipping_amount\']';
36+
37+
/**
38+
* Adjustment Refund css selector.
39+
*
40+
* @var string
41+
*/
42+
private $adjustmentRefundSelector = '//input[@id=\'adjustment_positive\']';
43+
44+
/**
45+
* Adjustment Fee css selector.
46+
*
47+
* @var string
48+
*/
49+
private $adjustmentFeeSelector = '//input[@id=\'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_XPATH);
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_XPATH);
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_XPATH);
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: 32 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->compareRefundTotalsData($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,31 @@ protected function getCreditMemoIds()
116120
$this->salesOrderView->getOrderForm()->openTab('creditmemos');
117121
return $this->salesOrderView->getOrderForm()->getTab('creditmemos')->getGridBlock()->getIds();
118122
}
123+
124+
/**
125+
* Compare refund total items.
126+
*
127+
* @param array $data
128+
* @return int
129+
*/
130+
private function compareRefundTotalsData($data)
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+
$count = 0;
142+
foreach ($compareData as $key => $val) {
143+
if (isset($data['form_data'][$key])) {
144+
$count += ($val != $data['form_data'][$key] ? 1 : 0);
145+
}
146+
}
147+
148+
return $count;
149+
}
119150
}

0 commit comments

Comments
 (0)