In Magento 1.7, I want to do like after credit memo create product quantity should be deduct.

How to do that?

Any help would be appreciated.



You can use sales_order_invoice_save_after to deduct product quantity after generate credit memo :

Create config.xml for define event and module :


<?xml version="1.0"?>


Create Observer.php file for add code for deduct qty after credit memo generate :


class RH_StockDeduct_Model_Observer {
    public function decreaseqty(Varien_Event_Observer $observer) {
        try {
            $invoice = $observer->getEvent()->getInvoice();
            $invoiceItems = $invoice->getAllItems();
            foreach ($invoiceItems as $item) {
                $productId = $item->getProductId();
                $product = Mage::getModel('catalog/product')->load($productId);
                $stockItem = (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty();
                $sku = $product->getSku();
                $qty = $stockItem - $item->getQty();
                $product->getStockItem()->setData('qty', $qty)->save();
            return $this;
        } catch (\Exception $e) {
            return $e->getMessage();
  • Thanks !! It's working like charm !!
    – Niket
    Dec 3 '19 at 2:32

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.