fix: Allocated amount validation for other party types (#35741)
* fix: Allocated amount validation for other party types * chore: Validation for return allocations * chore: minor typo --------- Co-authored-by: anandbaburajan <anandbaburajan@gmail.com>
This commit is contained in:
parent
78fbd6452b
commit
9d27a25e5f
@ -151,6 +151,19 @@ class PaymentEntry(AccountsController):
|
|||||||
if self.payment_type == "Internal Transfer":
|
if self.payment_type == "Internal Transfer":
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if self.party_type in ("Customer", "Supplier"):
|
||||||
|
self.validate_allocated_amount_with_latest_data()
|
||||||
|
else:
|
||||||
|
fail_message = _("Row #{0}: Allocated Amount cannot be greater than outstanding amount.")
|
||||||
|
for d in self.get("references"):
|
||||||
|
if (flt(d.allocated_amount)) > 0 and flt(d.allocated_amount) > flt(d.outstanding_amount):
|
||||||
|
frappe.throw(fail_message.format(d.idx))
|
||||||
|
|
||||||
|
# Check for negative outstanding invoices as well
|
||||||
|
if flt(d.allocated_amount) < 0 and flt(d.allocated_amount) < flt(d.outstanding_amount):
|
||||||
|
frappe.throw(fail_message.format(d.idx))
|
||||||
|
|
||||||
|
def validate_allocated_amount_with_latest_data(self):
|
||||||
latest_references = get_outstanding_reference_documents(
|
latest_references = get_outstanding_reference_documents(
|
||||||
{
|
{
|
||||||
"posting_date": self.posting_date,
|
"posting_date": self.posting_date,
|
||||||
@ -168,7 +181,7 @@ class PaymentEntry(AccountsController):
|
|||||||
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").copy():
|
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
|
||||||
@ -187,18 +200,14 @@ class PaymentEntry(AccountsController):
|
|||||||
).format(d.reference_doctype, d.reference_name)
|
).format(d.reference_doctype, d.reference_name)
|
||||||
)
|
)
|
||||||
|
|
||||||
d.outstanding_amount = latest.outstanding_amount
|
|
||||||
|
|
||||||
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:
|
if (flt(d.allocated_amount)) > 0 and flt(d.allocated_amount) > flt(latest.outstanding_amount):
|
||||||
if flt(d.allocated_amount) > flt(d.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:
|
if flt(d.allocated_amount) < 0 and flt(d.allocated_amount) < flt(latest.outstanding_amount):
|
||||||
if flt(d.allocated_amount) < flt(d.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:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user