fix: Made outstanding amount field read only and added validation
Made the field editable so that outstanding amount can be adjusted
diff --git a/erpnext/accounts/doctype/discounted_invoice/discounted_invoice.json b/erpnext/accounts/doctype/discounted_invoice/discounted_invoice.json
index ee7f750..9a276ca 100644
--- a/erpnext/accounts/doctype/discounted_invoice/discounted_invoice.json
+++ b/erpnext/accounts/doctype/discounted_invoice/discounted_invoice.json
@@ -38,13 +38,11 @@
"read_only": 1
},
{
- "fetch_from": "sales_invoice.outstanding_amount",
"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 +58,7 @@
}
],
"istable": 1,
- "modified": "2019-09-23 13:59:16.450344",
+ "modified": "2019-09-23 15:29:54.199318",
"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 f1f88a8..c061fb7 100644
--- a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.js
+++ b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.js
@@ -97,7 +97,6 @@
}
frm.set_value("total_amount", total_amount);
},
-
get_invoices: (frm) => {
var d = new frappe.ui.Dialog({
title: __('Get Invoices based on Filters'),
@@ -205,9 +204,15 @@
});
frappe.ui.form.on('Discounted Invoice', {
- sales_invoice: (frm) => {
+ sales_invoice: (frm, cdt, cdn) => {
frm.events.calculate_total_amount(frm);
- frm.events.refresh_filters(frm);
+ frm.events.refresh_filters(frm);
+
+ let row = locals[cdt][cdn];
+ frappe.db.get_value("Sales Invoice",row["sales_invoice"], "outstanding_amount", (res) => {
+ row.outstanding_amount = res["outstanding_amount"];
+ frm.refresh_field("invoices");
+ });
},
invoices_remove: (frm) => {
frm.events.calculate_total_amount(frm);
diff --git a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py
index 36c2911..39fc203 100644
--- a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py
+++ b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py
@@ -26,14 +26,20 @@
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])