From 370e711f488795cd67642f14f71579e259313a17 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 6 Oct 2016 15:19:36 +0530 Subject: [PATCH] [Fix] Expense Claim, sanctioned amount not auto-populated from claim amount --- .../hr/doctype/expense_claim/expense_claim.js | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.js b/erpnext/hr/doctype/expense_claim/expense_claim.js index bcd8bc09b00..8b3c45140c6 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.js +++ b/erpnext/hr/doctype/expense_claim/expense_claim.js @@ -129,9 +129,6 @@ cur_frm.cscript.calculate_total = function(doc,cdt,cdn){ doc.total_sanctioned_amount = 0; $.each((doc.expenses || []), function(i, d) { doc.total_claimed_amount += d.claim_amount; - if(d.sanctioned_amount==null) { - d.sanctioned_amount = d.claim_amount; - } doc.total_sanctioned_amount += d.sanctioned_amount; }); @@ -144,17 +141,6 @@ cur_frm.cscript.calculate_total_amount = function(doc,cdt,cdn){ cur_frm.cscript.calculate_total(doc,cdt,cdn); } -cur_frm.cscript.claim_amount = function(doc,cdt,cdn){ - cur_frm.cscript.calculate_total(doc,cdt,cdn); - - var child = locals[cdt][cdn]; - refresh_field("sanctioned_amount", child.name, child.parentfield); -} - -cur_frm.cscript.sanctioned_amount = function(doc,cdt,cdn){ - cur_frm.cscript.calculate_total(doc,cdt,cdn); -} - cur_frm.cscript.on_submit = function(doc, cdt, cdn) { if(cint(frappe.boot.notification_settings && frappe.boot.notification_settings.expense_claim)) { cur_frm.email_doc(frappe.boot.notification_settings.expense_claim_message); @@ -172,6 +158,25 @@ erpnext.expense_claim = { } } +frappe.ui.form.on("Expense Claim Detail", { + claim_amount: function(frm, cdt, cdn) { + var child = locals[cdt][cdn]; + var doc = frm.doc; + + if(!child.sanctioned_amount){ + frappe.model.set_value(cdt, cdn, 'sanctioned_amount', child.claim_amount) + } + + cur_frm.cscript.calculate_total(doc,cdt,cdn); + }, + + sanctioned_amount: function(frm, cdt, cdn) { + var doc = frm.doc; + cur_frm.cscript.calculate_total(doc,cdt,cdn); + } +}) + + frappe.ui.form.on("Expense Claim", "employee_name", function(frm) { erpnext.expense_claim.set_title(frm); });