After cancelling a Stock Entry, I need to programmatically retrieve either the original GL Entries or the reversal entries created during cancellation.
However, when I query the GL Entry table for the voucher, I see:
Given that all entries are marked as cancelled, I’m not sure how to reliably distinguish between the original entries and their reversal counterparts.
Is there a recommended or reliable way to separate or identify the original vs reversal GL Entries in this case?
Thanks in advance!
Hi @guimorin
What about looking at the creation/modified date/time?
Yeah ERPNext does this in a kinda messy way lol, once you cancel, it flags everything as cancelled so that field is useless for separation. The trick is to look at the values, not the flag, the reversal entries are just the exact opposite of the originals, debit and credit flipped for the same accounts and amounts. You can pair them by voucher_no + account and match rows where debit in one equals credit in another. Also check creation or modified timestamp, reversal entries are created right at cancel time, so they come later. That combo usually lets you split them clean without guessing.
Yeah too bad tabGL Entry does not have “amended_from” like normal “Is Submittable” DocTypes