From a125a6199c0a829345eea322045650b83f2cb3de Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 19 Jun 2018 12:06:48 +0530 Subject: [PATCH] Allowed paid amount against debit/credit note --- erpnext/accounts/doctype/payment_entry/payment_entry.js | 4 ++++ erpnext/accounts/doctype/payment_entry/payment_entry.py | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index 776bacfcce9..fc3eed36e9c 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -588,6 +588,10 @@ frappe.ui.form.on('Payment Entry', { allocate_party_amount_against_ref_docs: function(frm, paid_amount) { var total_positive_outstanding_including_order = 0; var total_negative_outstanding = 0; + var total_deductions = frappe.utils.sum($.map(frm.doc.deductions || [], + function(d) { return flt(d.amount) })); + + paid_amount -= total_deductions; $.each(frm.doc.references || [], function(i, row) { if(flt(row.outstanding_amount) > 0) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 2f8e6b83a2f..4e998596b01 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -337,14 +337,15 @@ class PaymentEntry(AccountsController): total_negative_outstanding = sum([abs(flt(d.outstanding_amount)) for d in self.get("references") if flt(d.outstanding_amount) < 0]) - party_amount = self.paid_amount if self.payment_type=="Receive" else self.received_amount + paid_amount = self.paid_amount if self.payment_type=="Receive" else self.received_amount + additional_charges = sum([flt(d.amount) for d in self.deductions]) if not total_negative_outstanding: frappe.throw(_("Cannot {0} {1} {2} without any negative outstanding invoice") .format(self.payment_type, ("to" if self.party_type=="Customer" else "from"), self.party_type), InvalidPaymentEntry) - elif party_amount > total_negative_outstanding: + elif paid_amount - additional_charges > total_negative_outstanding: frappe.throw(_("Paid Amount cannot be greater than total negative outstanding amount {0}") .format(total_negative_outstanding), InvalidPaymentEntry)