Cancel then Delete a Stock Entry results in error

I’m trying to programmatically cancel a Stock Entry and then immediately delete it.

The cancellation itself works, but when I attempt to delete the document right afterward, I receive the following error:

Cannot cancel as processing of cancelled documents is pending. Please try again in an hour.

Do you have any recommendations on the correct approach to handle this?

Is there any way to force a synchronous Repost Item Valuation for that stock_entry right after the cancel ?

Hi @guimorin

Whenever any stock doctype is recorded or updated, Repost Item Valuation record update valuation of that item in particular store.

The reposting job is hourly schedule job which runs automatically. Please check if cancelling result a new record in there waiting to be triggered for next hour, meaning you have to push schedule job on the same event programmatically as well.