Skip to content

Commit 4ebdd17

Browse files
committed
MC-17003: Update Totals button is missing from Credit Memo page
1 parent cc599e5 commit 4ebdd17

File tree

8 files changed

+191
-9
lines changed

8 files changed

+191
-9
lines changed

app/code/Magento/Sales/Test/Mftf/Test/AdminCheckingCreditMemoUpdateTotalsTest.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
<testCaseId value="MC-18159"/>
1919
<useCaseId value="MC-17003"/>
2020
<group value="sales"/>
21-
<skip>
22-
<issueId value="MC-17003"/>
23-
</skip>
2421
</annotations>
2522
<before>
2623
<!--Create product-->
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Sales\ViewModel\CreditMemo\Create;
10+
11+
use Magento\Backend\Block\Widget\Button;
12+
use Magento\Framework\View\Element\BlockInterface;
13+
use Magento\Framework\View\LayoutInterface;
14+
use Magento\Sales\Block\Adminhtml\Order\Creditmemo\Create\Items;
15+
16+
/**
17+
* View model to add Update Totals button for new Credit Memo
18+
*/
19+
class UpdateTotalsButton implements \Magento\Framework\View\Element\Block\ArgumentInterface
20+
{
21+
/**
22+
* @var LayoutInterface
23+
*/
24+
private $layout;
25+
26+
/**
27+
* @var Items
28+
*/
29+
private $items;
30+
31+
/**
32+
* @param LayoutInterface $layout
33+
* @param Items $items
34+
*/
35+
public function __construct(
36+
LayoutInterface $layout,
37+
Items $items
38+
) {
39+
$this->layout = $layout;
40+
$this->items = $items;
41+
}
42+
43+
/**
44+
* Get Update Totals block html.
45+
*
46+
* @return string
47+
*/
48+
public function getUpdateTotalsButton(): string
49+
{
50+
$block = $this->createUpdateTotalsBlock();
51+
52+
return $block->toHtml();
53+
}
54+
55+
/**
56+
* Create Update Totals block.
57+
*
58+
* @return BlockInterface
59+
*/
60+
private function createUpdateTotalsBlock(): BlockInterface
61+
{
62+
$onclick = "submitAndReloadArea($('creditmemo_item_container'),'" . $this->items->getUpdateUrl() . "')";
63+
$block = $this->layout->addBlock(Button::class, 'update_totals_button', 'order_items');
64+
$block->setData(
65+
[
66+
'label' => __('Update Totals'),
67+
'class' => 'update-totals-button secondary',
68+
'onclick' => $onclick,
69+
]
70+
);
71+
72+
return $block;
73+
}
74+
}

app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_new.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
<container name="extra_customer_info"/>
1818
</block>
1919
<block class="Magento\Sales\Block\Adminhtml\Order\Payment" name="order_payment"/>
20-
<block class="Magento\Sales\Block\Adminhtml\Order\Creditmemo\Create\Items" name="order_items" template="Magento_Sales::order/creditmemo/create/items.phtml">
20+
<block class="Magento\Sales\Block\Adminhtml\Order\Creditmemo\Create\Items" name="order_items" template="Magento_Sales::order/creditmemo/create/items.phtml" cacheable="false">
21+
<arguments>
22+
<argument name="viewModel" xsi:type="object">Magento\Sales\ViewModel\CreditMemo\Create\UpdateTotalsButton</argument>
23+
</arguments>
2124
<block class="Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer" name="order_items.default" as="default" template="Magento_Sales::order/creditmemo/create/items/renderer/default.phtml"/>
2225
<block class="Magento\Sales\Block\Adminhtml\Items\Column\Qty" name="column_qty" template="Magento_Sales::items/column/qty.phtml" group="column"/>
2326
<block class="Magento\Sales\Block\Adminhtml\Items\Column\Name" name="column_name" template="Magento_Sales::items/column/name.phtml" group="column"/>

app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_updateqty.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
<update handle="sales_order_item_price"/>
1010
<body>
1111
<block class="Magento\Sales\Block\Adminhtml\Order\Creditmemo\Create\Items" name="order_items" template="Magento_Sales::order/creditmemo/create/items.phtml">
12+
<arguments>
13+
<argument name="viewModel" xsi:type="object">Magento\Sales\ViewModel\CreditMemo\Create\UpdateTotalsButton</argument>
14+
</arguments>
1215
<block class="Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer" name="order_items.default" as="default" template="Magento_Sales::order/creditmemo/create/items/renderer/default.phtml"/>
1316
<block class="Magento\Sales\Block\Adminhtml\Items\Column\Qty" name="column_qty" template="Magento_Sales::items/column/qty.phtml" group="column"/>
1417
<block class="Magento\Sales\Block\Adminhtml\Items\Column\Name" name="column_name" template="Magento_Sales::items/column/name.phtml" group="column"/>

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
/* @var \Magento\Sales\Block\Adminhtml\Order\Creditmemo\Create\Items $block */
88
?>
9-
<?php $_items = $block->getCreditmemo()->getAllItems() ?>
9+
<?php
10+
/** @var Magento\Sales\ViewModel\CreditMemo\Create\UpdateTotalsButton $viewModel */
11+
$viewModel = $block->getData('viewModel');
12+
$_items = $block->getCreditmemo()->getAllItems();
13+
?>
1014

1115
<section class="admin__page-section">
1216
<div class="admin__page-section-title">
@@ -100,6 +104,7 @@
100104
<span class="title"><?= $block->escapeHtml(__('Refund Totals')) ?></span>
101105
</div>
102106
<?= $block->getChildHtml('creditmemo_totals') ?>
107+
<div class="totals-actions"><?= $viewModel->getUpdateTotalsButton() ?></div>
103108
<div class="order-totals-actions">
104109
<div class="field choice admin__field admin__field-option field-append-comments">
105110
<input id="notify_customer"
@@ -139,8 +144,8 @@ require(['jquery'], function(jQuery){
139144

140145
//<![CDATA[
141146
var submitButtons = jQuery('.submit-button');
142-
var updateButtons = jQuery('.update-button');
143-
var fields = jQuery('.qty-input');
147+
var updateButtons = jQuery('.update-button, .update-totals-button');
148+
var fields = jQuery('.qty-input, .order-subtotal-table input[type="text"]');
144149
function enableButtons(buttons) {
145150
buttons.removeClass('disabled').prop('disabled', false);
146151
}

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: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,11 @@ 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-
$this->orderCreditMemoNew->getFormBlock()->submit();
100+
if ($hasChangeTotals) {
101+
$this->orderCreditMemoNew->getTotalsBlock()->clickUpdateTotals();
102+
}
101103
}
102104

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

0 commit comments

Comments
 (0)