Skip to content

Commit 5ee8150

Browse files
author
Oleksii Korshenko
committed
MAGETWO-87289: Refunding / Credit Memo Total Value is not updated #1185
- Merge Pull Request magento-engcom/magento2ce#1185 from serhii-balko/magento2:github-11798 - Merged commits: 1. 451f7b9
2 parents 3572ee9 + 451f7b9 commit 5ee8150

File tree

7 files changed

+149
-7
lines changed

7 files changed

+149
-7
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
@@ -109,4 +109,20 @@ public function getShippingLabel()
109109
}
110110
return $label;
111111
}
112+
113+
/**
114+
* Get update totals url
115+
*
116+
* @return string
117+
*/
118+
public function getUpdateTotalsUrl()
119+
{
120+
return $this->getUrl(
121+
'sales/*/updateQty',
122+
[
123+
'order_id' => $this->getSource()->getOrderId(),
124+
'invoice_id' => $this->getRequest()->getParam('invoice_id', null)
125+
]
126+
);
127+
}
112128
}

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,14 @@ 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]
6060
);
61-
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+
);
66+
6267
if ($this->getCreditmemo()->canRefund()) {
6368
if ($this->getCreditmemo()->getInvoice() && $this->getCreditmemo()->getInvoice()->getTransactionId()) {
6469
$this->addChild(
@@ -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()
190+
{
191+
return $this->getChildHtml('update_totals_button');
192+
}
193+
179194
/**
180195
* Get update url
181196
*

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
/**
8+
* @var Magento\Sales\Block\Adminhtml\Order\Creditmemo\Create\Items $block
9+
*/
710
// @codingStandardsIgnoreFile
811

912
?>
@@ -101,6 +104,7 @@
101104
<span class="title"><?= /* @escapeNotVerified */ __('Refund Totals') ?></span>
102105
</div>
103106
<?= $block->getChildHtml('creditmemo_totals') ?>
107+
<div class="totals-actions"><?= $block->getUpdateTotalsButtonHtml() ?></div>
104108
<div class="order-totals-actions">
105109
<div class="field choice admin__field admin__field-option field-append-comments">
106110
<input id="notify_customer"
@@ -140,8 +144,8 @@ require(['jquery', 'prototype'], function(jQuery){
140144

141145
//<![CDATA[
142146
var submitButtons = $$('.submit-button');
143-
var updateButtons = $$('.update-button');
144-
var fields = $$('.qty-input');
147+
var updateButtons = $$('.update-button,.update-totals-button');
148+
var fields = $$('.qty-input,.order-subtotal-table input[type="text"]');
145149

146150
updateButtons.each(function (elem) {elem.disabled=true;elem.addClassName('disabled');});
147151

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
7+
/**
8+
* @var \Magento\Sales\Block\Adminhtml\Order\Creditmemo\Create\Adjustments $block
9+
* @codingStandardsIgnoreFile
10+
*/
811

912
?>
1013
<?php $_source = $block->getSource() ?>
@@ -24,7 +27,7 @@
2427
<td>
2528
<input type="text"
2629
name="creditmemo[adjustment_positive]"
27-
value="<?= /* @escapeNotVerified */ $_source->getBaseAdjustmentFeePositive()*1 ?>"
30+
value="<?= /* @escapeNotVerified */ $_source->getBaseAdjustmentPositive()*1 ?>"
2831
class="input-text admin__control-text not-negative-amount"
2932
id="adjustment_positive" />
3033
</td>
@@ -34,7 +37,7 @@
3437
<td>
3538
<input type="text"
3639
name="creditmemo[adjustment_negative]"
37-
value="<?= /* @escapeNotVerified */ $_source->getBaseAdjustmentFeeNegative()*1 ?>"
40+
value="<?= /* @escapeNotVerified */ $_source->getBaseAdjustmentNegative()*1 ?>"
3841
class="input-text admin__control-text not-negative-amount"
3942
id="adjustment_negative"/>
4043
<script>

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ public function run()
9696
$this->orderCreditMemoNew->getFormBlock()->updateQty();
9797
}
9898

99+
$hasChangeTotals = $this->compareRefundTotalsData($refundData);
99100
$this->orderCreditMemoNew->getFormBlock()->fillFormData($refundData);
101+
if ($hasChangeTotals) {
102+
$this->orderCreditMemoNew->getTotalsBlock()->clickUpdateTotals();
103+
}
104+
100105
$this->orderCreditMemoNew->getFormBlock()->submit();
101106
}
102107

@@ -116,4 +121,31 @@ protected function getCreditMemoIds()
116121
$this->salesOrderView->getOrderForm()->openTab('creditmemos');
117122
return $this->salesOrderView->getOrderForm()->getTab('creditmemos')->getGridBlock()->getIds();
118123
}
124+
125+
/**
126+
* Compare refund total items.
127+
*
128+
* @param array $data
129+
* @return int
130+
*/
131+
private function compareRefundTotalsData($data)
132+
{
133+
$compareData = [
134+
'shipping_amount' =>
135+
$this->orderCreditMemoNew->getTotalsBlock()->getRefundShippingElement()->getValue(),
136+
'adjustment_positive' =>
137+
$this->orderCreditMemoNew->getTotalsBlock()->getAdjustmentRefundElement()->getValue(),
138+
'adjustment_negative' =>
139+
$this->orderCreditMemoNew->getTotalsBlock()->getAdjustmentFeeElement()->getValue(),
140+
];
141+
142+
$count = 0;
143+
foreach ($compareData as $key => $val) {
144+
if (isset($data['form_data'][$key])) {
145+
$count += ($val != $data['form_data'][$key] ? 1 : 0);
146+
}
147+
}
148+
149+
return $count;
150+
}
119151
}

0 commit comments

Comments
 (0)