13

My typical use case for credit memo is price adjustments (adjust shipping, courtousy discount, etc.). It is rare that I'm using it for total return.

It is odd to me that the default behavior of Magento is that a CreditMemo is returning all products and refunding all shipping. Even when there are returns, it is rare the shipping is also refunded.

It would be better (and safer) if the CreditMemo defaults to $0 (no products refunded, and no shipping refunded) so admins are explicit about what is being refunded (nothing by default). Otherwise it is too easy to, for example, create a credit memo intended to refund shipping but refund the entire order!

Is there any configuration, or customization, that would support defaulting a CreditMemo to $0?

  • No answer re: configuration solution. Could this be accomplished via an extension? That is, set the initial settings on the Credit Memo? – MarkE Feb 27 '15 at 20:34
2

Not sure if you can achieve what you want without extending magento basic functionality. I had to do something similar and this is what I did: First I rewrote sales_order_creditmemo_totals for automatic creditmemos (maybe you dont need this, so you can go to the second part):

In my module config.xml:

    <blocks>
        <adminhtml>
            <rewrite>
                ...
                <sales_order_creditmemo_totals>Bla_Customercredit_Block_Adminhtml_Sales_Creditmemo</sales_order_creditmemo_totals>
            </rewrite>
        </adminhtml>

        <sales>
            <rewrite>
                ...
                <order_creditmemo_totals>Bla_Customercredit_Block_Sales_Creditmemo</order_creditmemo_totals>
            </rewrite>
        </sales>
    </blocks>

Then in Block/Adminhtml/Sales/Creditmemo.php

class Bla_Customercredit_Block_Adminhtml_Sales_Creditmemo extends Mage_Sales_Block_Order_Creditmemo_Totals 
{
    protected $_code = 'credit';

    protected function _initTotals() 
    {
        $helper = $this->getCreditsHelper();
        parent::_initTotals();
        $baseAmount = $this->getOrder()->getBaseCustomerCredit();

        $this->addTotal(
            new Varien_Object(
                array(
                    'code' => $this->_code,
                    'value' => -$creditAmount,
                    'base_value' => -$baseAmount,
                    'label' => $helper->__('Bla Credit'),
                )
            ), 
            'discount'
        );

        return $this;
    }
}

As you can see I did this to create creditmemos for orders with customer credit, so I also rewrote sales_order_totals and sales_order_invoice_totals but I think you dont need to do this.

Second: I also added a my own template to add some functionality during the manual creditmemo cretion, so the admin could decide how to generate it. For that I created an items.phtml under app/design/adminhtml/default/default/template/MODULE_NAME/order/creditmemo/create/items.phtml, in this phtml I added some input fields to change the efault values. I also added in my module in an admin controller under Company_CustomerCredit_Adminhtml_CustomerController

require_once 'Mage/Adminhtml/controllers/CustomerController.php';
class Bla_Customercredit_Adminhtml_CustomerController extends Mage_Adminhtml_CustomerController
{
    /**
     * Overload to save customer credits, then call 
     * parent::saveAction() 
     */
    public function saveAction()
    {
        $data = $this->getRequest()->getPost();
        if($data && $data['bla_credits'])
        {
            if(!empty($data['bla_credits']['id']))
            {
                $model = Mage::getModel('credits/credits')->load($data['bla_credits']['id']);
            }
            else
            {
                unset($data['bla_credits']['id']);
                $model = Mage::getModel('credits/credits');
            }

            try
            {
                $model->setData($data['bla_credits']);
                $model->save();
            }
            catch(Exception $e)
            {
            }
        }

        parent::saveAction();
    }
}
| improve this answer | |
  • Thanks, I appreciate your response and will see if I can apply your solution to my requirements. – MarkE Aug 20 '15 at 16:48

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.