Show total unpaid amount for a customer in custom field on customer selection

I want to display the customers current outstanding amount or total unpaid amount when i make a sales invoice for that customer .

i.e when i select a customer , his outstanding amount should be shown inside a custom field or ideally a pop up.

I checked a few places , but could not find a function from which i can get that amount , there is only in reports and gl entry , which you have to calculate by which seems a bit complex for me.

Is there a simple custom script or function where i can fetch this ?

i thought there would be more people interested in fetching outstanding amount of customer in some form other than reports or dynamically , but didn’t find any such discussions.

can you guide me please .

Thanks in advance for your help.


me too

from erpnext.selling.doctype.customer.customer import get_customer_outstanding

def get_customer_outstanding_amount(doc, method=None):
	doc.outstanding_cash = get_customer_outstanding(doc.customer,, ignore_outstanding_sales_order=True)