How to use field outstanding_amount Sales Invoice Number Card

Maybe this needs to be a feature request, as I’m very surprised this is not a default option.

How can I use outstanding_amount in the sum/agregation field for Sales Invoice Number card?

Why isn’t it available by default?

With the help of Gemini, I used a custom number card based on an API Server Script.

Server script:

Script Type: “API”

Method: “get_overdue_outstanding_amount”

try:
    # Fetch sum of outstanding_amount for submitted, unpaid & overdue sales invoices
    result = frappe.db.sql("""
        SELECT SUM(outstanding_amount) 
        FROM `tabSales Invoice` 
        WHERE docstatus = 1 
          AND status NOT IN ('Return', 'Cancelled', 'Draft')
    """, as_list=True)

    # Extract total amount safely
    total = result[0][0] if (result and result[0][0]) else 0.0

    # Number Cards expect either a dictionary with "value" or a direct numeric/float response.
    # Setting frappe.response["message"] returns the dictionary expected by Number Card components.
    frappe.response["message"] = {
        "value": total,
        "fieldtype": "Currency"
    }

except Exception as e:
    frappe.log_error(title="Number Card Outstanding Amount Error", message=frappe.get_traceback())
    frappe.response["message"] = {
        "value": 0.0,
        "fieldtype": "Currency"
    }

Then for the number card:

Label: “Invoices Due”

Type: “Custom”

Method: “get_overdue_outstanding_amount”

Hi @volkswagner

Thanks for posting your answer for anyone who has a similar problem.

FOSS is amazing :heart: