Skip to content

Commit

Permalink
fix: posting_date of linked vouchers should not affect outstanding
Browse files Browse the repository at this point in the history
posting_date filter should not be applied for linked vouchers.

(cherry picked from commit 5f1562c)
  • Loading branch information
ruthra-kumar authored and mergify[bot] committed Aug 8, 2022
1 parent 8737c10 commit 0faa7b0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
4 changes: 3 additions & 1 deletion erpnext/accounts/doctype/payment_entry/payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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")))
Expand All @@ -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"),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion erpnext/accounts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
)

Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 0faa7b0

Please sign in to comment.