fix: posting_date of linked vouchers should not affect outstanding
posting_date filter should not be applied for linked vouchers.
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index af5a5e2..48edda9 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -1184,6 +1184,7 @@
ple = qb.DocType("Payment Ledger Entry")
common_filter = []
+ posting_and_due_date = []
# confirm that Supplier is not blocked
if args.get("party_type") == "Supplier":
@@ -1224,7 +1225,7 @@
condition += " and {0} between '{1}' and '{2}'".format(
fieldname, args.get(date_fields[0]), args.get(date_fields[1])
)
- common_filter.append(ple[fieldname][args.get(date_fields[0]) : args.get(date_fields[1])])
+ posting_and_due_date.append(ple[fieldname][args.get(date_fields[0]) : args.get(date_fields[1])])
if args.get("company"):
condition += " and company = {0}".format(frappe.db.escape(args.get("company")))
@@ -1235,6 +1236,7 @@
args.get("party"),
args.get("party_account"),
common_filter=common_filter,
+ posting_date=posting_and_due_date,
min_outstanding=args.get("outstanding_amt_greater_than"),
max_outstanding=args.get("outstanding_amt_less_than"),
)
diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
index 5ed34d3..601fc87 100644
--- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
+++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
@@ -22,6 +22,7 @@
def __init__(self, *args, **kwargs):
super(PaymentReconciliation, self).__init__(*args, **kwargs)
self.common_filter_conditions = []
+ self.ple_posting_date_filter = []
@frappe.whitelist()
def get_unreconciled_entries(self):
@@ -150,6 +151,7 @@
return_outstanding = ple_query.get_voucher_outstandings(
vouchers=return_invoices,
common_filter=self.common_filter_conditions,
+ posting_date=self.ple_posting_date_filter,
min_outstanding=-(self.minimum_payment_amount) if self.minimum_payment_amount else None,
max_outstanding=-(self.maximum_payment_amount) if self.maximum_payment_amount else None,
get_payments=True,
@@ -187,6 +189,7 @@
self.party,
self.receivable_payable_account,
common_filter=self.common_filter_conditions,
+ posting_date=self.ple_posting_date_filter,
min_outstanding=self.minimum_invoice_amount if self.minimum_invoice_amount else None,
max_outstanding=self.maximum_invoice_amount if self.maximum_invoice_amount else None,
)
@@ -350,6 +353,7 @@
def build_qb_filter_conditions(self, get_invoices=False, get_return_invoices=False):
self.common_filter_conditions.clear()
+ self.ple_posting_date_filter.clear()
ple = qb.DocType("Payment Ledger Entry")
self.common_filter_conditions.append(ple.company == self.company)
@@ -359,15 +363,15 @@
if get_invoices:
if self.from_invoice_date:
- self.common_filter_conditions.append(ple.posting_date.gte(self.from_invoice_date))
+ self.ple_posting_date_filter.append(ple.posting_date.gte(self.from_invoice_date))
if self.to_invoice_date:
- self.common_filter_conditions.append(ple.posting_date.lte(self.to_invoice_date))
+ self.ple_posting_date_filter.append(ple.posting_date.lte(self.to_invoice_date))
elif get_return_invoices:
if self.from_payment_date:
- self.common_filter_conditions.append(ple.posting_date.gte(self.from_payment_date))
+ self.ple_posting_date_filter.append(ple.posting_date.gte(self.from_payment_date))
if self.to_payment_date:
- self.common_filter_conditions.append(ple.posting_date.lte(self.to_payment_date))
+ self.ple_posting_date_filter.append(ple.posting_date.lte(self.to_payment_date))
def get_conditions(self, get_payments=False):
condition = " and company = '{0}' ".format(self.company)
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 9dafef7..018e8f9 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -823,7 +823,13 @@
def get_outstanding_invoices(
- party_type, party, account, common_filter=None, min_outstanding=None, max_outstanding=None
+ party_type,
+ party,
+ account,
+ common_filter=None,
+ posting_date=None,
+ min_outstanding=None,
+ max_outstanding=None,
):
ple = qb.DocType("Payment Ledger Entry")
@@ -850,6 +856,7 @@
ple_query = QueryPaymentLedger()
invoice_list = ple_query.get_voucher_outstandings(
common_filter=common_filter,
+ posting_date=posting_date,
min_outstanding=min_outstanding,
max_outstanding=max_outstanding,
get_invoices=True,
@@ -1501,6 +1508,7 @@
# query filters
self.vouchers = []
self.common_filter = []
+ self.voucher_posting_date = []
self.min_outstanding = None
self.max_outstanding = None
@@ -1571,6 +1579,7 @@
.where(ple.delinked == 0)
.where(Criterion.all(filter_on_voucher_no))
.where(Criterion.all(self.common_filter))
+ .where(Criterion.all(self.voucher_posting_date))
.groupby(ple.voucher_type, ple.voucher_no, ple.party_type, ple.party)
)
@@ -1652,6 +1661,7 @@
self,
vouchers=None,
common_filter=None,
+ posting_date=None,
min_outstanding=None,
max_outstanding=None,
get_payments=False,
@@ -1671,6 +1681,7 @@
self.reset()
self.vouchers = vouchers
self.common_filter = common_filter or []
+ self.voucher_posting_date = posting_date or []
self.min_outstanding = min_outstanding
self.max_outstanding = max_outstanding
self.get_payments = get_payments