diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py index 6ce79ee3ea6..2b98baf2210 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py +++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py @@ -111,8 +111,6 @@ class PaymentReconciliation(Document): def get_payment_entries(self): order_doctype = "Sales Order" if self.party_type == "Customer" else "Purchase Order" condition = self.get_conditions(get_payments=True) - if self.payment_name: - condition += "name like '%%{0}%%'".format(self.payment_name) payment_entries = get_advance_payment_entries_for_regional( self.party_type, @@ -122,6 +120,7 @@ class PaymentReconciliation(Document): against_all_orders=True, limit=self.payment_limit, condition=condition, + payment_name=self.payment_name, ) return payment_entries diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 393ad171d52..abe5d688c3b 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -2504,6 +2504,7 @@ def get_advance_payment_entries( against_all_orders=False, limit=None, condition=None, + payment_name=None, ): party_account_field = "paid_from" if party_type == "Customer" else "paid_to" currency_field = ( @@ -2526,6 +2527,10 @@ def get_advance_payment_entries( reference_condition = "" order_list = [] + payment_name_filter = "" + if payment_name: + payment_name_filter = " and t1.name like '%%{0}%%'".format(payment_name) + if not condition: condition = "" @@ -2540,7 +2545,7 @@ def get_advance_payment_entries( where t1.name = t2.parent and t1.{1} = %s and t1.payment_type = %s and t1.party_type = %s and t1.party = %s and t1.docstatus = 1 - and t2.reference_doctype = %s {2} {3} + and t2.reference_doctype = %s {2} {3} {6} order by t1.posting_date {4} """.format( currency_field, @@ -2549,12 +2554,17 @@ def get_advance_payment_entries( condition, limit_cond, exchange_rate_field, + payment_name_filter, ), [party_account, payment_type, party_type, party, order_doctype] + order_list, as_dict=1, ) if include_unallocated: + payment_name_filter = "" + if payment_name: + payment_name_filter = " and name like '%%{0}%%'".format(payment_name) + unallocated_payment_entries = frappe.db.sql( """ select 'Payment Entry' as reference_type, name as reference_name, posting_date, @@ -2562,10 +2572,15 @@ def get_advance_payment_entries( from `tabPayment Entry` where {0} = %s and party_type = %s and party = %s and payment_type = %s - and docstatus = 1 and unallocated_amount > 0 {condition} + and docstatus = 1 and unallocated_amount > 0 {condition} {4} order by posting_date {1} """.format( - party_account_field, limit_cond, exchange_rate_field, currency_field, condition=condition or "" + party_account_field, + limit_cond, + exchange_rate_field, + currency_field, + payment_name_filter, + condition=condition or "", ), (party_account, party_type, party, payment_type), as_dict=1,