fix: Validate negative allocated amount in Payment Entry (#25799)
diff --git a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py
index 7b62b61..95d2ee5 100644
--- a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py
+++ b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py
@@ -49,11 +49,11 @@
self.make_gl_entries()
def on_cancel(self):
- self.set_status()
+ self.set_status(cancel=1)
self.update_sales_invoice()
self.make_gl_entries()
- def set_status(self, status=None):
+ def set_status(self, status=None, cancel=0):
if status:
self.status = status
self.db_set("status", status)
@@ -66,6 +66,9 @@
elif self.docstatus == 2:
self.status = "Cancelled"
+ if cancel:
+ self.db_set('status', self.status, update_modified = True)
+
def update_sales_invoice(self):
for d in self.invoices:
if self.docstatus == 1:
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index 62ab76c..e01c651 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -65,7 +65,6 @@
self.set_status()
def on_submit(self):
- self.setup_party_account_field()
if self.difference_amount:
frappe.throw(_("Difference Amount must be zero"))
self.make_gl_entries()
@@ -78,7 +77,6 @@
def on_cancel(self):
self.ignore_linked_doctypes = ('GL Entry', 'Stock Ledger Entry')
- self.setup_party_account_field()
self.make_gl_entries(cancel=1)
self.update_outstanding_amounts()
self.update_advance_paid()
@@ -122,6 +120,11 @@
if flt(d.allocated_amount) > flt(d.outstanding_amount):
frappe.throw(_("Row #{0}: Allocated Amount cannot be greater than outstanding amount.").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(_("Row #{0}: Allocated Amount cannot be greater than outstanding amount.").format(d.idx))
+
def delink_advance_entry_references(self):
for reference in self.references:
if reference.reference_doctype in ("Sales Invoice", "Purchase Invoice"):
@@ -177,7 +180,7 @@
for field, value in iteritems(ref_details):
if field == 'exchange_rate' or not d.get(field) or force:
- d.set(field, value)
+ d.db_set(field, value)
def validate_payment_type(self):
if self.payment_type not in ("Receive", "Pay", "Internal Transfer"):
@@ -386,6 +389,8 @@
else:
self.status = 'Draft'
+ self.db_set('status', self.status, update_modified = True)
+
def set_amounts(self):
self.set_amounts_in_company_currency()
self.set_total_allocated_amount()
@@ -791,7 +796,7 @@
outstanding_invoices.pop(idx - 1)
outstanding_invoices += invoice_ref_based_on_payment_terms[idx]
-
+
return outstanding_invoices
def get_orders_to_be_billed(posting_date, party_type, party,
@@ -989,6 +994,7 @@
outstanding_amount = ref_doc.get("outstanding_amount")
elif reference_doctype == "Donation":
total_amount = ref_doc.get("amount")
+ outstanding_amount = total_amount
exchange_rate = 1
elif reference_doctype == "Dunning":
total_amount = ref_doc.get("dunning_amount")
diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py
index 53ac996..4689787 100644
--- a/erpnext/accounts/doctype/payment_request/payment_request.py
+++ b/erpnext/accounts/doctype/payment_request/payment_request.py
@@ -101,7 +101,7 @@
controller.validate_transaction_currency(self.currency)
controller.request_for_payment(**payment_record)
-
+
def get_request_amount(self):
data_of_completed_requests = frappe.get_all("Integration Request", filters={
'reference_doctype': self.doctype,
@@ -492,7 +492,6 @@
status = 'Requested'
pay_req_doc.db_set('status', status)
- frappe.db.commit()
def get_dummy_message(doc):
return frappe.render_template("""{% if doc.contact_person -%}
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
index db605f7..a11b77a 100755
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
@@ -584,6 +584,7 @@
`tabGL Entry`
where
docstatus < 2
+ and is_cancelled = 0
and party_type=%s
and (party is not null and party != '')
{1} {2} {3}"""