From 0faa7b04326db9f896d647d9dee5fa3b79f4051c Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 28 Jul 2022 11:57:27 +0530 Subject: [PATCH] fix: posting_date of linked vouchers should not affect outstanding posting_date filter should not be applied for linked vouchers. (cherry picked from commit 5f1562c5b21da32e7f963a8b052e0eb26b7e7684) --- .../accounts/doctype/payment_entry/payment_entry.py | 4 +++- .../payment_reconciliation.py | 12 ++++++++---- erpnext/accounts/utils.py | 13 ++++++++++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index af5a5e249d2b..48edda90324d 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1184,6 +1184,7 @@ def get_outstanding_reference_documents(args): 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 @@ def get_outstanding_reference_documents(args): 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 @@ def get_outstanding_reference_documents(args): 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 5ed34d34a32a..601fc87a227a 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py +++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py @@ -22,6 +22,7 @@ class PaymentReconciliation(Document): 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 @@ def get_dr_or_cr_notes(self): 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 @@ def get_invoice_entries(self): 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 validate_allocation(self): 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 @@ def build_qb_filter_conditions(self, get_invoices=False, get_return_invoices=Fal 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 9dafef74f4a4..018e8f9301a2 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -823,7 +823,13 @@ def get_held_invoices(party_type, party): 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 @@ def get_outstanding_invoices( 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 @@ def __init__(self): # query filters self.vouchers = [] self.common_filter = [] + self.voucher_posting_date = [] self.min_outstanding = None self.max_outstanding = None @@ -1571,6 +1579,7 @@ def query_for_outstanding(self): .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 @@ def get_voucher_outstandings( self, vouchers=None, common_filter=None, + posting_date=None, min_outstanding=None, max_outstanding=None, get_payments=False, @@ -1671,6 +1681,7 @@ def get_voucher_outstandings( 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