diff --git a/erpnext/accounts/doctype/discounted_invoice/discounted_invoice.json b/erpnext/accounts/doctype/discounted_invoice/discounted_invoice.json index 04d6303774a..5c3519a1592 100644 --- a/erpnext/accounts/doctype/discounted_invoice/discounted_invoice.json +++ b/erpnext/accounts/doctype/discounted_invoice/discounted_invoice.json @@ -38,13 +38,13 @@ "read_only": 1 }, { - "fetch_from": "sales_invoice.grand_total", + "fetch_from": "sales_invoice.outstanding_amount", + "fetch_if_empty": 1, "fieldname": "outstanding_amount", "fieldtype": "Currency", "in_list_view": 1, "label": "Outstanding Amount", - "options": "Company:company:default_currency", - "read_only": 1 + "options": "Company:company:default_currency" }, { "fieldname": "column_break_3", @@ -60,7 +60,7 @@ } ], "istable": 1, - "modified": "2019-08-07 15:13:55.808349", + "modified": "2019-09-26 11:05:36.016772", "modified_by": "Administrator", "module": "Accounts", "name": "Discounted Invoice", diff --git a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.js b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.js index f1f88a8d649..0fab8b70f43 100644 --- a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.js +++ b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.js @@ -97,7 +97,6 @@ frappe.ui.form.on('Invoice Discounting', { } frm.set_value("total_amount", total_amount); }, - get_invoices: (frm) => { var d = new frappe.ui.Dialog({ title: __('Get Invoices based on Filters'), diff --git a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py index 36c29113eaa..39fc203d53f 100644 --- a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py +++ b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py @@ -26,14 +26,20 @@ class InvoiceDiscounting(AccountsController): frappe.throw(_("Loan Start Date and Loan Period are mandatory to save the Invoice Discounting")) def validate_invoices(self): - discounted_invoices = [record.sales_invoice for record in - frappe.get_all("Discounted Invoice",fields = ["sales_invoice"], filters= {"docstatus":1})] + discounted_invoices = [record.sales_invoice for record in + frappe.get_all("Discounted Invoice",fields=["sales_invoice"], filters={"docstatus":1})] for record in self.invoices: if record.sales_invoice in discounted_invoices: - frappe.throw("Row({0}): {1} is already discounted in {2}" + frappe.throw(_("Row({0}): {1} is already discounted in {2}") .format(record.idx, frappe.bold(record.sales_invoice), frappe.bold(record.parent))) + actual_outstanding = frappe.db.get_value("Sales Invoice", record.sales_invoice,"outstanding_amount") + if record.outstanding_amount > actual_outstanding : + frappe.throw(_ + ("Row({0}): Outstanding Amount cannot be greater than actual Outstanding Amount {1} in {2}").format( + record.idx, frappe.bold(actual_outstanding), frappe.bold(record.sales_invoice))) + def calculate_total_amount(self): self.total_amount = sum([flt(d.outstanding_amount) for d in self.invoices])