Question

I am trying to create a credit memo in my store but I keep getting this error

Cannot save the credit memo

I have checked the exception.log and can see the following:

Integrity constraint violation: 1062 Duplicate entry '100003910' for key 'UNQ_SALES_FLAT_CREDITMEMO_INCREMENT_ID

I wanted to ask if I should change the value in the database to the next increment or is there a better way to solve this problem?

I'd be greatful for any advice...

Was it helpful?

Solution

Review the following tables using the offending increment id: eav_entity_store sales_flat_creditmemo

After a bit of investigation you will find that there is a credit memo that conflicts for the last_increment_id stored in eav_entity_store for the store you are attempting to credit via or no last_increment_id record for credit memos in the eav_entity_store.

The correct fix is to adjust the eav_entity_store changing the last_increment_id for the store where the entity_type_id is 7 (7 is credit memo on my instance, if unsure review magento matching the increment id's).

OTHER TIPS

NOTE: Try this only in Test Order it may delete your order number from sales > order Grid

in app/code/core/Mage/Sales/Model/Resource/Order/Abstract.php this file

protected function _beforeSave(Mage_Core_Model_Abstract $object)
    {
        if ($this->_useIncrementId && !$object->getIncrementId()) {
            /* @var $entityType Mage_Eav_Model_Entity_Type */
            $entityType = Mage::getModel('eav/entity_type')->loadByCode($this->_entityTypeForIncrementId);
            $object->setIncrementId($entityType->fetchNewIncrementId($object->getStoreId()));
        }
        parent::_beforeSave($object);
        return $this;
    }

from above code. Put below two lines outside IF condition and then try to generate credit memo it will works.

     $entityType = Mage::getModel('eav/entity_type')->loadByCode($this->_entityTypeForIncrementId);
     $object->setIncrementId($entityType->fetchNewIncrementId($object->getStoreId()));

then reward changes.

Keep in Mind this is needed only for one record; Next onward it will start working

I guess it is okay to answer your own question once in a while...

Inside the sales_flat_creditmemo table look for increment_id column and change the number to one increment above the current number. For example, the increment_id was 100003910 so I changed it to 100003911 and I can now create credit memos.

UPDATE Another even better approach would be to use the Fooman Order Number Customiser. I've added to help with the duplication of Order No. Shipment No. Invoice No. and Credit Memo across mulitple stores...

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top