Skip to content

Commit

Permalink
MAGETWO-87289: Refunding / Credit Memo Total Value is not updated #1185
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksii Korshenko authored Feb 5, 2018
2 parents 62c8ca6 + 5ee8150 commit e2c7bf1
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,20 @@ public function getShippingLabel()
}
return $label;
}

/**
* Get update totals url
*
* @return string
*/
public function getUpdateTotalsUrl()
{
return $this->getUrl(
'sales/*/updateQty',
[
'order_id' => $this->getSource()->getOrderId(),
'invoice_id' => $this->getRequest()->getParam('invoice_id', null)
]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ protected function _prepareLayout()
$this->addChild(
'update_button',
\Magento\Backend\Block\Widget\Button::class,
['label' => __('Update Qty\'s'), 'class' => 'update-button', 'onclick' => $onclick]
['label' => __('Update Qty\'s'), 'class' => 'update-button secondary', 'onclick' => $onclick]
);

$this->addChild(
'update_totals_button',
\Magento\Backend\Block\Widget\Button::class,
['label' => __('Update Totals'), 'class' => 'update-totals-button secondary', 'onclick' => $onclick]
);

if ($this->getCreditmemo()->canRefund()) {
if ($this->getCreditmemo()->getInvoice() && $this->getCreditmemo()->getInvoice()->getTransactionId()) {
$this->addChild(
Expand Down Expand Up @@ -176,6 +181,16 @@ public function getUpdateButtonHtml()
return $this->getChildHtml('update_button');
}

/**
* Get update totals button html
*
* @return string
*/
public function getUpdateTotalsButtonHtml()
{
return $this->getChildHtml('update_totals_button');
}

/**
* Get update url
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* See COPYING.txt for license details.
*/

/**
* @var Magento\Sales\Block\Adminhtml\Order\Creditmemo\Create\Items $block
*/
// @codingStandardsIgnoreFile

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

//<![CDATA[
var submitButtons = $$('.submit-button');
var updateButtons = $$('.update-button');
var fields = $$('.qty-input');
var updateButtons = $$('.update-button,.update-totals-button');
var fields = $$('.qty-input,.order-subtotal-table input[type="text"]');

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile
/**
* @var \Magento\Sales\Block\Adminhtml\Order\Creditmemo\Create\Adjustments $block
* @codingStandardsIgnoreFile
*/

?>
<?php $_source = $block->getSource() ?>
Expand All @@ -24,7 +27,7 @@
<td>
<input type="text"
name="creditmemo[adjustment_positive]"
value="<?= /* @escapeNotVerified */ $_source->getBaseAdjustmentFeePositive()*1 ?>"
value="<?= /* @escapeNotVerified */ $_source->getBaseAdjustmentPositive()*1 ?>"
class="input-text admin__control-text not-negative-amount"
id="adjustment_positive" />
</td>
Expand All @@ -34,7 +37,7 @@
<td>
<input type="text"
name="creditmemo[adjustment_negative]"
value="<?= /* @escapeNotVerified */ $_source->getBaseAdjustmentFeeNegative()*1 ?>"
value="<?= /* @escapeNotVerified */ $_source->getBaseAdjustmentNegative()*1 ?>"
class="input-text admin__control-text not-negative-amount"
id="adjustment_negative"/>
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
}
}

.totals-actions {
text-align: right;
}

.order-totals-actions {
margin-top: @indent__s;
.actions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,34 @@ class Totals extends \Magento\Sales\Test\Block\Adminhtml\Order\Totals
*/
protected $capture = '[name="invoice[capture_case]"]';

/**
* Refund Shipping css selector.
*
* @var string
*/
private $refundShippingSelector = '//input[@id=\'shipping_amount\']';
/**
* Adjustment Refund css selector.
*
* @var string
*/
private $adjustmentRefundSelector = '//input[@id=\'adjustment_positive\']';

/**
* Adjustment Fee css selector.
*
* @var string
*/
private $adjustmentFeeSelector = '//input[@id=\'adjustment_negative\']';
/**
* 'Update Totals button css selector.
*
* @var string
*/
private $updateTotalsSelector = '.update-totals-button';

/**
* Submit invoice.
*
Expand Down Expand Up @@ -57,4 +85,44 @@ public function setCaptureOption($option)
{
$this->_rootElement->find($this->capture, Locator::SELECTOR_CSS, 'select')->setValue($option);
}

/**
* Get Refund Shipping input element.
*
* @return \Magento\Mtf\Client\ElementInterface
*/
public function getRefundShippingElement()
{
return $this->_rootElement->find($this->refundShippingSelector, Locator::SELECTOR_XPATH);
}

/**
* Get Adjustment Refund input element.
*
* @return \Magento\Mtf\Client\ElementInterface
*/
public function getAdjustmentRefundElement()
{
return $this->_rootElement->find($this->adjustmentRefundSelector, Locator::SELECTOR_XPATH);
}

/**
* Get Adjustment Fee input element.
*
* @return \Magento\Mtf\Client\ElementInterface
*/
public function getAdjustmentFeeElement()
{
return $this->_rootElement->find($this->adjustmentFeeSelector, Locator::SELECTOR_XPATH);
}

/**
* Click update totals button.
*
* @return void
*/
public function clickUpdateTotals()
{
$this->_rootElement->find($this->updateTotalsSelector)->click();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ public function run()
$this->orderCreditMemoNew->getFormBlock()->updateQty();
}

$hasChangeTotals = $this->compareRefundTotalsData($refundData);
$this->orderCreditMemoNew->getFormBlock()->fillFormData($refundData);
if ($hasChangeTotals) {
$this->orderCreditMemoNew->getTotalsBlock()->clickUpdateTotals();
}

$this->orderCreditMemoNew->getFormBlock()->submit();
}

Expand All @@ -116,4 +121,31 @@ protected function getCreditMemoIds()
$this->salesOrderView->getOrderForm()->openTab('creditmemos');
return $this->salesOrderView->getOrderForm()->getTab('creditmemos')->getGridBlock()->getIds();
}

/**
* Compare refund total items.
*
* @param array $data
* @return int
*/
private function compareRefundTotalsData($data)
{
$compareData = [
'shipping_amount' =>
$this->orderCreditMemoNew->getTotalsBlock()->getRefundShippingElement()->getValue(),
'adjustment_positive' =>
$this->orderCreditMemoNew->getTotalsBlock()->getAdjustmentRefundElement()->getValue(),
'adjustment_negative' =>
$this->orderCreditMemoNew->getTotalsBlock()->getAdjustmentFeeElement()->getValue(),
];

$count = 0;
foreach ($compareData as $key => $val) {
if (isset($data['form_data'][$key])) {
$count += ($val != $data['form_data'][$key] ? 1 : 0);
}
}

return $count;
}
}

0 comments on commit e2c7bf1

Please sign in to comment.