1

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...

1
  • make sure table "sequence_creditmemo_0","sequence_creditmemo_1", so on...
    – Ansyori
    Commented Aug 12 at 7:13

3 Answers 3

1

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).

1
  • On mine there is no credit memo for it (it was order 600000001, made 600000001 and shipment 600000001 but no credit memo so no credit memo line).
    – Mike
    Commented Feb 2, 2017 at 20:44
1

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

1

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...

7
  • 1
    it mean i got error in 200000001 this number so, i should changes it with 200000002. right?
    – MageDev
    Commented Oct 9, 2014 at 6:11
  • @Michel06 Yea that should solve it Commented Oct 9, 2014 at 8:34
  • okey thanks and shipping also not working what to do for it? same step? same error in ship too.
    – MageDev
    Commented Oct 9, 2014 at 10:09
  • @Michel06 Yes, please try the same step for shopping. Let us know if it works... Commented Oct 9, 2014 at 11:13
  • Okey. but i am afraid to change creditmemo number frm database its live and old site. if it may harm with existing same number credit memo then? "(
    – MageDev
    Commented Oct 9, 2014 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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