Skip to content

Commit

Permalink
fix: error while filtering on name on reconciliation tool
Browse files Browse the repository at this point in the history
  • Loading branch information
ruthra-kumar committed Dec 14, 2023
1 parent 497049b commit 30b6321
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ def get_nonreconciled_payment_entries(self):
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,
Expand All @@ -70,6 +68,7 @@ def get_payment_entries(self):
against_all_orders=True,
limit=self.payment_limit,
condition=condition,
payment_name=self.payment_name,
)

return payment_entries
Expand Down
21 changes: 18 additions & 3 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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 = ""

Expand All @@ -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,
Expand All @@ -2549,23 +2554,33 @@ 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,
remarks, unallocated_amount as amount, {2} as exchange_rate, {3} as currency
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,
Expand Down

0 comments on commit 30b6321

Please sign in to comment.