diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 216c9f45d3..1849e8b3b5 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1352,12 +1352,12 @@ class AccountsController(TransactionBase): party = self.customer if self.doctype == "Sales Order" else self.supplier advance = ( frappe.qb.from_(ple) - .select(ple.account_currency, Abs(Sum(ple.amount)).as_("amount")) + .select(ple.account_currency, Abs(Sum(ple.amount_in_account_currency)).as_("amount")) .where( (ple.against_voucher_type == self.doctype) & (ple.against_voucher_no == self.name) & (ple.party == party) - & (ple.delinked == 0) + & (ple.docstatus == 1) & (ple.company == self.company) ) .run(as_dict=True)