perf: pull latest details only for referenced vouchers

This commit is contained in:
ruthra kumar 2023-08-15 05:17:01 +05:30
parent e023e33a15
commit deb0d71294
2 changed files with 79 additions and 72 deletions

View File

@ -230,6 +230,9 @@ class PaymentEntry(AccountsController):
return False
def validate_allocated_amount_with_latest_data(self):
if self.references:
uniq_vouchers = set([(x.reference_doctype, x.reference_name) for x in self.references])
vouchers = [frappe._dict({"voucher_type": x[0], "voucher_no": x[1]}) for x in uniq_vouchers]
latest_references = get_outstanding_reference_documents(
{
"posting_date": self.posting_date,
@ -240,6 +243,7 @@ class PaymentEntry(AccountsController):
"party_account": self.paid_from if self.payment_type == "Receive" else self.paid_to,
"get_outstanding_invoices": True,
"get_orders_to_be_billed": True,
"vouchers": vouchers,
},
validate=True,
)
@ -1587,6 +1591,7 @@ def get_outstanding_reference_documents(args, validate=False):
min_outstanding=args.get("outstanding_amt_greater_than"),
max_outstanding=args.get("outstanding_amt_less_than"),
accounting_dimensions=accounting_dimensions_filter,
vouchers=args.get("vouchers") or None,
)
outstanding_invoices = split_invoices_based_on_payment_terms(

View File

@ -908,6 +908,7 @@ def get_outstanding_invoices(
min_outstanding=None,
max_outstanding=None,
accounting_dimensions=None,
vouchers=None,
):
ple = qb.DocType("Payment Ledger Entry")
@ -933,6 +934,7 @@ def get_outstanding_invoices(
ple_query = QueryPaymentLedger()
invoice_list = ple_query.get_voucher_outstandings(
vouchers=vouchers,
common_filter=common_filter,
posting_date=posting_date,
min_outstanding=min_outstanding,