From bfa78aaf7455aadf08de7718cddbe1a48f2ed2f9 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Tue, 12 Mar 2024 21:29:44 +0530 Subject: [PATCH] fix: advance journal fetching logic in Advances section (cherry picked from commit e786a93c2ece97d9b680127003d058b9a9e21d26) --- erpnext/controllers/accounts_controller.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index cb8f5250e0a..246c0c02d61 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -2669,14 +2669,20 @@ def get_advance_journal_entries( else: q = q.where(journal_acc.debit_in_account_currency > 0) + reference_or_condition = [] + if include_unallocated: - q = q.where((journal_acc.reference_name.isnull()) | (journal_acc.reference_name == "")) + reference_or_condition.append(journal_acc.reference_name.isnull()) + reference_or_condition.append(journal_acc.reference_name == "") if order_list: - q = q.where( + reference_or_condition.append( (journal_acc.reference_type == order_doctype) & ((journal_acc.reference_name).isin(order_list)) ) + if reference_or_condition: + q = q.where(Criterion.any(reference_or_condition)) + q = q.orderby(journal_entry.posting_date) journal_entries = q.run(as_dict=True)