diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index fe931ee822..704381817e 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -219,6 +219,8 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends e add_filters_group: 0, date_field: "posting_date", columns: ["voucher_type", "voucher_no", "allocated_amount"], + primary_action_label: "Un-Reconcile", + title: "Un-Reconcile Payments", get_query() { return query_args; }, diff --git a/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.py b/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.py index ed978cbc37..dfd2d29e0f 100644 --- a/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.py +++ b/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.py @@ -4,6 +4,7 @@ import frappe from frappe import qb from frappe.model.document import Document +from frappe.query_builder import Criterion from frappe.query_builder.functions import Abs, Sum from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries, update_voucher_outstanding @@ -78,6 +79,11 @@ def get_linked_payments_for_doc(doctype, txt, searchfield, start, page_len, filt _dn = filters.get("docname") ple = qb.DocType("Payment Ledger Entry") if _dt in ["Sales Invoice", "Purchase Invoice"]: + criteria = [(ple.delinked == 0), (ple.against_voucher_no == _dn), (ple.amount < 0)] + + if txt: + criteria.append(ple.voucher_no.like(f"%{txt}%")) + res = ( qb.from_(ple) .select( @@ -85,7 +91,7 @@ def get_linked_payments_for_doc(doctype, txt, searchfield, start, page_len, filt ple.voucher_no, Abs(Sum(ple.amount_in_account_currency)).as_("allocated_amount"), ) - .where((ple.delinked == 0) & (ple.against_voucher_no == _dn) & (ple.amount < 0)) + .where(Criterion.all(criteria)) .groupby(ple.against_voucher_no) .run(as_dict=True) )