From fd1ab37bc86f1a10b83385f1a2ccd8806a7a4414 Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Wed, 29 Apr 2020 15:19:08 +0530 Subject: [PATCH 1/2] chore: validate and warn payment against paid invoices --- .../doctype/payment_entry/payment_entry.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index c89742cfb7f..6130a1401fc 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -60,6 +60,7 @@ class PaymentEntry(AccountsController): self.set_remarks() self.validate_duplicate_entry() self.validate_allocated_amount() + self.validate_paid_invoices() self.ensure_supplier_is_not_blocked() self.set_status() @@ -264,6 +265,25 @@ class PaymentEntry(AccountsController): frappe.throw(_("{0} {1} must be submitted") .format(d.reference_doctype, d.reference_name)) + def validate_paid_invoices(self): + no_oustanding_refs = {} + + for d in self.get("references"): + if not d.allocated_amount: + continue + + if d.reference_doctype in ("Sales Invoice", "Purchase Invoice", "Fees"): + outstanding_amount = frappe.get_cached_value(d.reference_doctype, d.reference_name, "outstanding_amount") + if outstanding_amount <= 0: + no_oustanding_refs.setdefault(d.reference_doctype, []).append(d) + + for k, v in no_oustanding_refs.items(): + frappe.msgprint(_("{} - {} now have {} as they had no outstanding amount left before submitting the Payment Entry. \n \ + If this is undesirable please cancel the corresponding Payment Entry.") + .format(k, frappe.bold(", ".join([d.reference_name for d in v])), frappe.bold("negative outstanding amount")), + title=_("Warning"), indicator="orange") + + def validate_journal_entry(self): for d in self.get("references"): if d.allocated_amount and d.reference_doctype == "Journal Entry": From 393857d7dec2917092348f9b72a404b5b2218bfe Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Thu, 30 Apr 2020 13:23:59 +0530 Subject: [PATCH 2/2] chore: handle credit note validation --- erpnext/accounts/doctype/payment_entry/payment_entry.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 6130a1401fc..56be17d4405 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -273,12 +273,12 @@ class PaymentEntry(AccountsController): continue if d.reference_doctype in ("Sales Invoice", "Purchase Invoice", "Fees"): - outstanding_amount = frappe.get_cached_value(d.reference_doctype, d.reference_name, "outstanding_amount") - if outstanding_amount <= 0: + outstanding_amount, is_return = frappe.get_cached_value(d.reference_doctype, d.reference_name, ["outstanding_amount", "is_return"]) + if outstanding_amount <= 0 and not is_return: no_oustanding_refs.setdefault(d.reference_doctype, []).append(d) for k, v in no_oustanding_refs.items(): - frappe.msgprint(_("{} - {} now have {} as they had no outstanding amount left before submitting the Payment Entry. \n \ + frappe.msgprint(_("{} - {} now have {} as they had no outstanding amount left before submitting the Payment Entry.

\ If this is undesirable please cancel the corresponding Payment Entry.") .format(k, frappe.bold(", ".join([d.reference_name for d in v])), frappe.bold("negative outstanding amount")), title=_("Warning"), indicator="orange")