mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-21 14:09:19 +00:00
fix: query voucher outstanding only when all the conditions are true.
This commit is contained in:
@@ -1869,40 +1869,42 @@ def create_payment_ledger_entry(
|
|||||||
|
|
||||||
|
|
||||||
def update_voucher_outstanding(voucher_type, voucher_no, account, party_type, party):
|
def update_voucher_outstanding(voucher_type, voucher_no, account, party_type, party):
|
||||||
|
if not (voucher_type in OUTSTANDING_DOCTYPES and party_type and party):
|
||||||
|
return
|
||||||
|
|
||||||
ple = frappe.qb.DocType("Payment Ledger Entry")
|
ple = frappe.qb.DocType("Payment Ledger Entry")
|
||||||
vouchers = [frappe._dict({"voucher_type": voucher_type, "voucher_no": voucher_no})]
|
vouchers = [frappe._dict({"voucher_type": voucher_type, "voucher_no": voucher_no})]
|
||||||
common_filter = []
|
common_filter = []
|
||||||
|
common_filter.append(ple.party_type == party_type)
|
||||||
|
common_filter.append(ple.party == party)
|
||||||
|
|
||||||
if account:
|
if account:
|
||||||
common_filter.append(ple.account == account)
|
common_filter.append(ple.account == account)
|
||||||
|
|
||||||
if party_type:
|
|
||||||
common_filter.append(ple.party_type == party_type)
|
|
||||||
|
|
||||||
if party:
|
|
||||||
common_filter.append(ple.party == party)
|
|
||||||
|
|
||||||
ple_query = QueryPaymentLedger()
|
ple_query = QueryPaymentLedger()
|
||||||
|
|
||||||
# on cancellation outstanding can be an empty list
|
# on cancellation outstanding can be an empty list
|
||||||
voucher_outstanding = ple_query.get_voucher_outstandings(vouchers, common_filter=common_filter)
|
voucher_outstanding = ple_query.get_voucher_outstandings(vouchers, common_filter=common_filter)
|
||||||
if voucher_type in OUTSTANDING_DOCTYPES and party_type and party and voucher_outstanding:
|
if not voucher_outstanding:
|
||||||
outstanding = voucher_outstanding[0]
|
return
|
||||||
ref_doc = frappe.get_lazy_doc(voucher_type, voucher_no)
|
|
||||||
outstanding_amount = flt(
|
|
||||||
outstanding["outstanding_in_account_currency"], ref_doc.precision("outstanding_amount")
|
|
||||||
)
|
|
||||||
|
|
||||||
# Didn't use db_set for optimisation purpose
|
outstanding = voucher_outstanding[0]
|
||||||
ref_doc.outstanding_amount = outstanding_amount
|
ref_doc = frappe.get_lazy_doc(voucher_type, voucher_no)
|
||||||
frappe.db.set_value(
|
outstanding_amount = flt(
|
||||||
voucher_type,
|
outstanding["outstanding_in_account_currency"], ref_doc.precision("outstanding_amount")
|
||||||
voucher_no,
|
)
|
||||||
"outstanding_amount",
|
|
||||||
outstanding_amount,
|
|
||||||
)
|
|
||||||
|
|
||||||
ref_doc.set_status(update=True)
|
# Didn't use db_set for optimisation purpose
|
||||||
ref_doc.notify_update()
|
ref_doc.outstanding_amount = outstanding_amount
|
||||||
|
frappe.db.set_value(
|
||||||
|
voucher_type,
|
||||||
|
voucher_no,
|
||||||
|
"outstanding_amount",
|
||||||
|
outstanding_amount,
|
||||||
|
)
|
||||||
|
|
||||||
|
ref_doc.set_status(update=True)
|
||||||
|
ref_doc.notify_update()
|
||||||
|
|
||||||
|
|
||||||
def delink_original_entry(pl_entry, partial_cancel=False):
|
def delink_original_entry(pl_entry, partial_cancel=False):
|
||||||
|
|||||||
Reference in New Issue
Block a user