1

Preconditions

  1. M2.4.3
  2. Order with online or offline payment, and invoice

Steps to reproduce

  1. Navigate to invoice, create the credit note
  2. Refund Shipping, Adjustment refund, Adjustment fee all 0

Expected result Credit memo gets created successfully

Actual result

Unable to submit credit note, each of the above fields gets a validation error "Please enter positive number in this field."

3 Answers 3

1

I have faced the same issue and solved using the below code.

app/code/Vendor/Module/view/adminhtml/layout/sales_order_creditmemo_new.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name='adjustments'>
            <action method='setTemplate'>
                <argument name='template' xsi:type='string'>Vendor_Module::order/creditmemo/create/totals/adjustments.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

app/code/Vendor/Module/view/adminhtml/templates/order/creditmemo/create/totals/adjustments.phtml

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
?>
<?php $_source  = $block->getSource() ?>
<?php if ($_source): ?>
    <tr>
        <td class="label">
            <?= $block->escapeHtml($block->getShippingLabel()) ?>
            <div id="shipping_amount_adv"></div>
        </td>
        <td>
            <input type="text"
                   name="creditmemo[shipping_amount]"
                   value="<?= $block->escapeHtmlAttr($block->getShippingAmount()) ?>"
                   class="input-text admin__control-text not-negative-amount"
                   id="shipping_amount" />
        </td>
    </tr>
    <tr>
        <td class="label">
            <?= $block->escapeHtml(__('Adjustment Refund')) ?>
            <div id="adjustment_positive_adv"></div>
        </td>
        <td>
            <input type="text"
                   name="creditmemo[adjustment_positive]"
                   value="<?= $block->escapeHtmlAttr($_source->getBaseAdjustmentPositive()) ?>"
                   class="input-text admin__control-text not-negative-amount"
                   id="adjustment_positive" />
        </td>
    </tr>
    <tr>
        <td class="label">
            <?= $block->escapeHtml(__('Adjustment Fee')) ?>
            <div id="adjustment_negative_adv"></div>
        </td>
        <td>
            <input type="text"
                   name="creditmemo[adjustment_negative]"
                   value="<?= $block->escapeHtmlAttr($_source->getBaseAdjustmentNegative()) ?>"
                   class="input-text admin__control-text not-negative-amount"
                   id="adjustment_negative"/>
            <?php $scriptString = <<<script
                require(['prototype'], function(){

                //<![CDATA[
                Validation.addAllThese([
                    [
                        'not-negative-amount',
                        '{$block->escapeJs(__('Please enter a positive number in this field.'))}',
                        function (v) {
                            if (v.length)
                                return /^\s*\d+([,.]\d+)*\s*%?\s*$/.test(v);
                            else
                                return true;
                        }
                    ]
                ]);

                if ($('shipping_amount')) {
                    $('shipping_amount').advaiceContainer = $('shipping_amount_adv');
                    unblockSubmit('shipping_amount');
                }
                if ($('adjustment_positive')) {
                    $('adjustment_positive').advaiceContainer = $('adjustment_positive_adv');
                    unblockSubmit('adjustment_positive');
                }
                if ($('adjustment_negative')) {
                    $('adjustment_negative').advaiceContainer = $('adjustment_negative_adv');
                    unblockSubmit('adjustment_negative');
                }

                function unblockSubmit(id) {
                    $(id).observe('focus', function(event) {
                        if ($$('button[class="scalable update-button disabled"]').size() > 0) {
                            enableElements('submit-button');
                        }
                    });
                    $(id).observe('change', function (event) {
                        enableElements('submit-button');
                    });
                }
                //]]>

                });
script;
            ?>
            <?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>
        </td>
    </tr>

<?php endif; ?>
0

Apply below Patch

index 65b47d7535c..f9943daba24 100644
--- a/vendor/magento/module-directory/Model/Currency.php
+++ b/vendor/magento/module-directory/Model/Currency.php
@@ -365,10 +365,6 @@ class Currency extends \Magento\Framework\Model\AbstractModel
          */
         $price = sprintf("%F", $price);
 
-        if ($this->canUseNumberFormatter($options)) {
-            return $this->formatCurrency($price, $options);
-        }
-
         return $this->_localeCurrency->getCurrency($this->getCode())->toCurrency($price, $options);
     }
 
0

We are facing the same issue, but for us, it seems to be related to the Mageplaza "Currency Formatter" extension. When we disable it, the currency sign disappears and we can create the credit memo. Please note that we are using the 1.0.0 version and so maybe the issue has been solved in the new releases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.