diff --git a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.js b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.js index 06c014cb785..022f900b053 100644 --- a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.js +++ b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.js @@ -44,7 +44,8 @@ cur_frm.fields_dict.voucher_no.get_query = function(doc) { and (ifnull(gle.against_voucher, '') = '' \ or ifnull(gle.against_voucher, '') = gle.voucher_no ) \ and ifnull(gle.%(account_type)s, 0) > 0 \ - and (select ifnull(abs(sum(debit) - sum(credit)), 0) from `tabGL Entry` \ + and (select ifnull(abs(sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))), 0) \ + from `tabGL Entry` \ where against_voucher_type = '%(dt)s' \ and against_voucher = gle.voucher_no \ and voucher_no != gle.voucher_no \ diff --git a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py index d585ceaefa4..b75142b66e2 100644 --- a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py +++ b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py @@ -39,16 +39,14 @@ class DocType: (self.doc.voucher_type, self.doc.voucher_no, self.doc.account)) total_amount = total_amount and flt(total_amount[0][0]) or 0 - reconciled_payment = webnotes.conn.sql(""" - select sum(%s) - sum(%s) from `tabGL Entry` where + select sum(ifnull(%s, 0)) - sum(ifnull(%s, 0)) from `tabGL Entry` where against_voucher = %s and voucher_no != %s and account = %s and ifnull(is_cancelled, 'No') = 'No'""" % ((self.doc.account_type == 'debit' and 'credit' or 'debit'), self.doc.account_type, '%s', '%s', '%s'), (self.doc.voucher_no, self.doc.voucher_no, self.doc.account)) reconciled_payment = reconciled_payment and flt(reconciled_payment[0][0]) or 0 - ret = { 'total_amount': total_amount, 'pending_amt_to_reconcile': total_amount - reconciled_payment