2

I wanted to delete a wrong credit memo so I deleted the wrong credit memo entry from sales_creditmemo and sales_creditmemo_grid. The listing of grid and credit memo is gone but when I view my order I could see refunded amount and comments about refund and the status of some product can also be seen as refunded .

enter image description here

So can someone explain what else I have to delete to completely get rid of credit memo information and also what is magento way of deleting a credit memo, does even magento provide a way to delete credit memo?

1
  • 1
    The answer your looking for is in the sales_order table you need to make sure columns related to refund are set to null and 0 as for the comment you can remove this in sales_order_status_history Commented Aug 21, 2019 at 10:09

2 Answers 2

1

In case anyone was looking for the full process to remove a Credit Memo via SQL.

First remove the credit memo records:

delete from sales_creditmemo where increment_id = <CREDITMEMO_INCREMENT_ID>;
delete from sales_creditmemo_grid where increment_id = <CREDITMEMO_INCREMENT_ID>;

Update the order values:

UPDATE sales_order
SET    state = 'complete',
       status = 'complete',
       base_discount_refunded = NULL,
       discount_refunded = NULL,
       discount_tax_compensation_refunded = NULL,
       base_discount_tax_compensation_refunded = NULL,
       base_shipping_tax_refunded = NULL,
       shipping_tax_refunded = NULL,
       shipping_refunded = NULL,
       base_tax_refunded = NULL,
       tax_refunded = NULL,
       base_subtotal_refunded = NULL,
       subtotal_refunded = NULL,
       base_total_offline_refunded = NULL,
       base_total_refunded = NULL,
       total_offline_refunded = NULL,
       total_refunded = NULL,
       base_shipping_refunded = NULL,
       base_total_online_refunded = NULL,
       total_online_refunded = NULL
WHERE  increment_id = <ORDER_INCREMENT_ID>;

Update the order line values:

UPDATE sales_order_item
SET    qty_refunded = 0.0000,
       amount_refunded = 0.0000,
       base_amount_refunded = 0.0000,
       discount_tax_compensation_refunded = NULL,
       base_discount_tax_compensation_refunded = NULL,
       tax_refunded = NULL,
       base_tax_refunded = NULL,
       discount_refunded = NULL,
       base_discount_refunded = NULL
WHERE  order_id = <ORDER_ID> --note this is the value seen in the URL when viewing the order

Remove Order Comment:

--find the comments for the order
select * from sales_order_status_history where parent_id = <ORDER_ID>

--remove the one referencing the credit
delete from sales_order_status_history where parent_id = <ORDER_ID> and entity_id = <COMMENT_ID>

Running the above queries with the correct order references left the order look like it did before the Credit Memo was created.

1
  • 1
    Note this doesn’t work if you have multiple credit memos associated with the order and want to cancel a single one.
    – bfontaine
    Commented May 27 at 14:08
0

Create Custom Script Like This :-

\Magento\Sales\Model\OrderFactory $orderFactory

 $orderId = '1234546';

$order = $this->orderFactory->create()->load($orderId);

$_creditmemos = $this->Order()->getCreditmemosCollection();

      if($_creditmemos){
          foreach($_creditmemos as $_creditmemo){
              $_creditmemo->delete();
          }
      }

You Can Download Module For Delete Credit Memo :-

delete credit memo

1
  • @rathod thanks for the script , i deleted it through mysql by i guess this will be a much better way , will it also revert the status of refunded from the products whose status changes by creating credit memo ? Commented Aug 13, 2019 at 4:55

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.