From 8b4a49cb41bc0c7f2f890623d3a8f72e9b3c257e Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Fri, 16 Jun 2023 15:29:23 +0530 Subject: [PATCH 1/3] fix: Allocated amount validation for other party types --- .../doctype/payment_entry/payment_entry.py | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index b6d3e5a30e16..f1ade7e3813f 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -151,6 +151,19 @@ def validate_allocated_amount(self): if self.payment_type == "Internal Transfer": return + if self.party_type in ("Customer", "Supplier"): + self.validate_allocated_amount_with_latest_date() + else: + fail_message = _("Row #{0}: Allocated Amount cannot be greater than outstanding amount.") + for d in self.get("references"): + if (flt(d.allocated_amount)) 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) and flt(d.allocated_amount) < flt(d.outstanding_amount): + frappe.throw(fail_message.format(d.idx)) + + def validate_allocated_amount_with_latest_date(self): latest_references = get_outstanding_reference_documents( { "posting_date": self.posting_date, @@ -168,7 +181,7 @@ def validate_allocated_amount(self): d = frappe._dict(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)) # The reference has already been fully paid @@ -187,18 +200,14 @@ def validate_allocated_amount(self): ).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.") - if (flt(d.allocated_amount)) > 0: - if flt(d.allocated_amount) > flt(d.outstanding_amount): - frappe.throw(fail_message.format(d.idx)) + if (flt(d.allocated_amount)) and flt(d.allocated_amount) > flt(latest.outstanding_amount): + frappe.throw(fail_message.format(d.idx)) # Check for negative outstanding invoices as well - if flt(d.allocated_amount) < 0: - if flt(d.allocated_amount) < flt(d.outstanding_amount): - frappe.throw(fail_message.format(d.idx)) + if flt(d.allocated_amount) and flt(d.allocated_amount) < flt(latest.outstanding_amount): + frappe.throw(fail_message.format(d.idx)) def delink_advance_entry_references(self): for reference in self.references: From 96201044528828102f377bc51ba8482a29a3be00 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Fri, 16 Jun 2023 16:04:56 +0530 Subject: [PATCH 2/3] chore: Validation for return allocations --- erpnext/accounts/doctype/payment_entry/payment_entry.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index f1ade7e3813f..d14fff6466ef 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -156,11 +156,11 @@ def validate_allocated_amount(self): else: fail_message = _("Row #{0}: Allocated Amount cannot be greater than outstanding amount.") for d in self.get("references"): - if (flt(d.allocated_amount)) and flt(d.allocated_amount) > flt(d.outstanding_amount): + 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) and flt(d.allocated_amount) < flt(d.outstanding_amount): + 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_date(self): @@ -202,11 +202,11 @@ def validate_allocated_amount_with_latest_date(self): fail_message = _("Row #{0}: Allocated Amount cannot be greater than outstanding amount.") - if (flt(d.allocated_amount)) 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)) # Check for negative outstanding invoices as well - if flt(d.allocated_amount) 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)) def delink_advance_entry_references(self): From 5f716b4221c6e5ece25239bec1ffb0b4e9c0372e Mon Sep 17 00:00:00 2001 From: anandbaburajan Date: Mon, 19 Jun 2023 10:58:19 +0530 Subject: [PATCH 3/3] chore: minor typo --- erpnext/accounts/doctype/payment_entry/payment_entry.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index d14fff6466ef..b9be5ec7244a 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -152,7 +152,7 @@ def validate_allocated_amount(self): return if self.party_type in ("Customer", "Supplier"): - self.validate_allocated_amount_with_latest_date() + 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"): @@ -163,7 +163,7 @@ def validate_allocated_amount(self): 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_date(self): + def validate_allocated_amount_with_latest_data(self): latest_references = get_outstanding_reference_documents( { "posting_date": self.posting_date,