Currently ERPNext reconciles advance payments to invoices by modifying the source document’s (Payment Entry or Journal Entry) GL Entries and changing their
against_voucher and in some cases even splitting the GL Entries into multiple rows.
With this current method, the information about that fact that a payment was made as an advance against a Sales Order or Purchase Order or an Unallocated Advance Payment is lost. I would assume that accountants and people who advocate for immutable ledgers would not approve this method.
So while working on improving Employee Advance I got the idea that there could be a Voucher Type (Document) that acts as the document that gets allocated with the advance payments. And instead of reposting/modifying the original GL Entries we can post GL Entries like this:
Advance Voucher Types: Sales Order, Purchase Order, Employee Advance, Advance Payment (new DocType)
Payment Entry/Journal Entry --> Advance Voucher Type
Advance Voucher Type <-- Invoice/Expense Claim
Payment Entry ($100)
Bank 100 Dr Customer 100 Cr (against Sales Order)
Balance of Sales Order: of 100 Cr
Balance of Payment Entry: 0 (of course)
Sales Invoice ($200)
Customer 100 Dr Customer 100 Dr (against Sales Order) Sales 200 Cr
Balance of Sales Order: 0
Balance of Sales Invoice: 100 Dr
This way a Payment Entry/Journal Entry/GL Entry will always show that it was paid for Sales Order and not Sales Invoice.
And yes I am working on this, however, currently only for Employee Advance and Expense Claim documents.
Let me know what are your thoughts on this.