fix(Payment Entry): don't check empty references

Manual partial backport of https://github.com/frappe/erpnext/pull/36649
This commit is contained in:
barredterra
2023-12-14 13:39:35 +01:00
parent 1b78dd17c9
commit f0877ffa47

View File

@@ -175,52 +175,53 @@ class PaymentEntry(AccountsController):
frappe.throw(fail_message.format(d.idx)) frappe.throw(fail_message.format(d.idx))
def validate_allocated_amount_with_latest_data(self): def validate_allocated_amount_with_latest_data(self):
latest_references = get_outstanding_reference_documents( if self.references:
{ latest_references = get_outstanding_reference_documents(
"posting_date": self.posting_date, {
"company": self.company, "posting_date": self.posting_date,
"party_type": self.party_type, "company": self.company,
"payment_type": self.payment_type, "party_type": self.party_type,
"party": self.party, "payment_type": self.payment_type,
"party_account": self.paid_from if self.payment_type == "Receive" else self.paid_to, "party": self.party,
"get_outstanding_invoices": True, "party_account": self.paid_from if self.payment_type == "Receive" else self.paid_to,
"get_orders_to_be_billed": True, "get_outstanding_invoices": True,
} "get_orders_to_be_billed": True,
) }
)
# Group latest_references by (voucher_type, voucher_no) # Group latest_references by (voucher_type, voucher_no)
latest_lookup = {} latest_lookup = {}
for d in latest_references: for d in latest_references:
d = frappe._dict(d) d = frappe._dict(d)
latest_lookup.update({(d.voucher_type, d.voucher_no): d}) latest_lookup.update({(d.voucher_type, d.voucher_no): d})
for d in self.get("references"): for d in self.get("references"):
latest = latest_lookup.get((d.reference_doctype, d.reference_name)) latest = latest_lookup.get((d.reference_doctype, d.reference_name))
# The reference has already been fully paid # The reference has already been fully paid
if not latest: if not latest:
frappe.throw( frappe.throw(
_("{0} {1} has already been fully paid.").format(_(d.reference_doctype), d.reference_name) _("{0} {1} has already been fully paid.").format(_(d.reference_doctype), d.reference_name)
) )
# The reference has already been partly paid # The reference has already been partly paid
elif latest.outstanding_amount < latest.invoice_amount and flt( elif latest.outstanding_amount < latest.invoice_amount and flt(
d.outstanding_amount, d.precision("outstanding_amount") d.outstanding_amount, d.precision("outstanding_amount")
) != flt(latest.outstanding_amount, d.precision("outstanding_amount")): ) != flt(latest.outstanding_amount, d.precision("outstanding_amount")):
frappe.throw( frappe.throw(
_( _(
"{0} {1} has already been partly paid. Please use the 'Get Outstanding Invoice' or the 'Get Outstanding Orders' button to get the latest outstanding amounts." "{0} {1} has already been partly paid. Please use the 'Get Outstanding Invoice' or the 'Get Outstanding Orders' button to get the latest outstanding amounts."
).format(_(d.reference_doctype), d.reference_name) ).format(_(d.reference_doctype), d.reference_name)
) )
fail_message = _("Row #{0}: Allocated Amount cannot be greater than outstanding amount.") fail_message = _("Row #{0}: Allocated Amount cannot be greater than outstanding amount.")
if (flt(d.allocated_amount)) > 0 and flt(d.allocated_amount) > flt(latest.outstanding_amount): if (flt(d.allocated_amount)) > 0 and flt(d.allocated_amount) > flt(latest.outstanding_amount):
frappe.throw(fail_message.format(d.idx)) frappe.throw(fail_message.format(d.idx))
# Check for negative outstanding invoices as well # Check for negative outstanding invoices as well
if flt(d.allocated_amount) < 0 and flt(d.allocated_amount) < flt(latest.outstanding_amount): if flt(d.allocated_amount) < 0 and flt(d.allocated_amount) < flt(latest.outstanding_amount):
frappe.throw(fail_message.format(d.idx)) frappe.throw(fail_message.format(d.idx))
def delink_advance_entry_references(self): def delink_advance_entry_references(self):
for reference in self.references: for reference in self.references: