Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Product qty is incremented when comment is added on a Credit Memo from SOAP API v2 #1517

Closed
medgoprot opened this issue Apr 2, 2021 · 11 comments · Fixed by #1575
Closed
Labels

Comments

@medgoprot
Copy link

medgoprot commented Apr 2, 2021

Preconditions (*)

  1. Should be reproducible on Open Mage.

Steps to reproduce (*)

  1. Create a Credit Memo for any order either through the SOAP API v2 or the Admin panel
  2. Add a comment on a Credit Memo via the SOAP API v2 and note the qty of the products in the inventory before and after

Expected result (*)

  1. Adding a comment on the Credit Memo should not cause the refunded products' inventory qty to increment again

Actual result (*)

  1. Adding a comment via the SOAP API causes the refunded products' inventory qty to be incremented again

After a long debugging session, it was found that the problem is arising from Mage_CatalogInventory_Model_Observer#refundOrderInventory which is observing the sales_order_creditmemo_save_after event that is dispatched after any save() of the Credit Memo, this is because in the event observer method (refundOrderInventory), there is no check to see whether the creditmemo object is new or not therefore it keeps adding the qty for all order items on every save.
Thanks

@medgoprot medgoprot added the bug label Apr 2, 2021
@medgoprot medgoprot changed the title Product qty is incremented in double when Credit Memo is created from SOAP API v2 Product qty is incremented when comment is added on a Credit Memo from SOAP API v2 Apr 12, 2021
@fballiano
Copy link
Contributor

I tested it but couldn't reproduce the error.

Schermata 2021-04-28 alle 17 22 46

The qty is always 1, also if the last comment was added via SOAP.

@fballiano
Copy link
Contributor

is salesOrderCreditmemoAddComment is method you call?

@medgoprot
Copy link
Author

medgoprot commented Apr 28, 2021

@fballiano Yes that's method being called. I think you misunderstood, I meant the inventory qty of the product and not the Creditmemo items' qty. I updated the description to make it more clear.

@fballiano
Copy link
Contributor

the last comment on my screenshot was added via soap but the qty was kept at 1.

@fballiano
Copy link
Contributor

fballiano commented Apr 28, 2021

another order, with ordered_qty = 10, refunded_qty = 1, created some comments via soap:

Schermata 2021-04-28 alle 17 54 25

i'm on OM 20.0.10 tho

the soap call:
Schermata 2021-04-28 alle 17 55 33

@medgoprot
Copy link
Author

medgoprot commented Apr 28, 2021

@fballiano Yes but I'm not talking about the refunded qty in the creditmemo, can you note the qty of the product in the inventory before vs. after adding the comment and see if it changes?

@medgoprot
Copy link
Author

medgoprot commented Apr 28, 2021

I'm talking about this qty, it gets incremented each time after adding a comment from the SOAP API

Screen Shot 2021-04-28 at 17 02 19

@fballiano
Copy link
Contributor

so it's not the refunded_qty but the qty that goes back to stock?

@fballiano
Copy link
Contributor

do you have this?

Schermata 2021-04-28 alle 18 17 51

@fballiano
Copy link
Contributor

oki, understood and reproduced

@fballiano
Copy link
Contributor

fballiano commented Apr 28, 2021

I just submitted PR #1575 which solves the problem on my local installation.

Flyingmana pushed a commit that referenced this issue Apr 30, 2021
Adding a comment to a creditmemo keeps "restocking" the products to the inventory, as explained in issue #1517

$creditmemo->getCommentsCollection()->save() is used in Mage_Adminhtml_Sales_Order_CreditmemoController::addCommentAction() and works correctly because it doesn't trigger a "save" on the creditmemo, but only on the comments.
randallelliott714 added a commit to randallelliott714/magento that referenced this issue Oct 18, 2022
Adding a comment to a creditmemo keeps "restocking" the products to the inventory, as explained in issue OpenMage/magento-lts#1517

$creditmemo->getCommentsCollection()->save() is used in Mage_Adminhtml_Sales_Order_CreditmemoController::addCommentAction() and works correctly because it doesn't trigger a "save" on the creditmemo, but only on the comments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants