diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py index 09bd7d2cc8..743df3704d 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py +++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py @@ -70,7 +70,7 @@ class PaymentReconciliation(Document): non_reconciled_invoices = [] dr_or_cr = "debit" if self.party_type == "Customer" else "credit" cond = self.check_condition(dr_or_cr) - + invoice_list = frappe.db.sql(""" select voucher_no, voucher_type, posting_date, @@ -79,8 +79,12 @@ class PaymentReconciliation(Document): `tabGL Entry` where party_type = %(party_type)s and party = %(party)s - and voucher_type != "Journal Entry" and account = %(account)s and {dr_or_cr} > 0 {cond} + and (CASE + WHEN voucher_type = 'Journal Entry' + THEN ifnull(against_voucher, '') = '' + ELSE 1=1 + END) group by voucher_type, voucher_no """.format(**{ "cond": cond, diff --git a/erpnext/accounts/doctype/payment_tool/payment_tool.py b/erpnext/accounts/doctype/payment_tool/payment_tool.py index eedf69fe5d..b02214c847 100644 --- a/erpnext/accounts/doctype/payment_tool/payment_tool.py +++ b/erpnext/accounts/doctype/payment_tool/payment_tool.py @@ -71,7 +71,7 @@ def get_outstanding_vouchers(args): # Get all outstanding sales /purchase invoices outstanding_invoices = get_outstanding_invoices(amount_query, args.get("party_account"), - args.get("party_type"), args.get("party"), with_journal_entry=False) + args.get("party_type"), args.get("party")) # Get all SO / PO which are not fully billed or aginst which full advance not paid orders_to_be_billed = get_orders_to_be_billed(args.get("party_type"), args.get("party"), diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 04084ed0e8..645c91c8f7 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -397,7 +397,7 @@ def get_stock_rbnb_difference(posting_date, company): # Amount should be credited return flt(stock_rbnb) + flt(sys_bal) -def get_outstanding_invoices(amount_query, account, party_type, party, with_journal_entry=True): +def get_outstanding_invoices(amount_query, account, party_type, party): all_outstanding_vouchers = [] outstanding_voucher_list = frappe.db.sql(""" select @@ -407,6 +407,11 @@ def get_outstanding_invoices(amount_query, account, party_type, party, with_jour `tabGL Entry` where account = %s and party_type=%s and party=%s and {amount_query} > 0 + and (CASE + WHEN voucher_type = 'Journal Entry' + THEN ifnull(against_voucher, '') = '' + ELSE 1=1 + END) group by voucher_type, voucher_no """.format(amount_query = amount_query), (account, party_type, party), as_dict = True) @@ -425,9 +430,6 @@ def get_outstanding_invoices(amount_query, account, party_type, party, with_jour payment_amount = -1*payment_amount[0][0] if payment_amount else 0 precision = frappe.get_precision("Sales Invoice", "outstanding_amount") - if not with_journal_entry and d.voucher_type=="Journal Entry": - continue - if d.invoice_amount > payment_amount: all_outstanding_vouchers.append({