I need to fetch the outstanding amount from the previous invoice and apply it to the current invoice. Is this possible
ERPNext is designed to manage outstanding balances per customer through Payment Entries, and adjustments are generally handled in the payment process rather than per invoice.
However you can use a customisation / custom script to achieve what you wish.
If you want to get the total outstanding of select customer then you can use the below script and set it in your custom field. It’s a sample example, you can set it the scenario your according.
total_outstanding = frappe.db.sql("""
SELECT SUM(outstanding_amount)
FROM `tabSales Invoice`
WHERE customer = %s
AND docstatus = 1
""", (doc.customer))[0][0] or 0
doc.custom_outstanding_amount = total_outstanding
The idea is to track invoice-wise payment status and each invoice is settled via payment entry. So, if you make a lump sum payment entry of multiple invoices together, all the outstanding invoices of that customer will be fetched and you could allocate the amount and then settle. What is the rationale of bringing the previous outstanding into the current invoice, when you can see both invoice and their current status separately?
Accounting is done to capture information in a True and Fair view. To achieve this if you can separately track invoices via payment settlement, that is a better system.
Acualy, I wanted to include the outstanding amount on the invoice so that the customer is informed of the exact amount they need to settle. This would help streamline communication and ensure customers are always aware of their current balance.
You could share a statement of account with customers to let them know all the outstanding invoices and the total outstanding amount. This is standard practice across the industry to keep track of invoice-wise collection accounting and share statements of accounts with each other to be on the same page.
https://docs.erpnext.com/docs/user/manual/en/process-statement-of-accounts