fix(Payroll): Exchange Rate not getting set in Salary Slip

This commit is contained in:
Rucha Mahabal 2021-03-25 14:48:08 +05:30
parent 52701dcbbc
commit b2b12f303e

View File

@ -74,43 +74,46 @@ frappe.ui.form.on("Salary Slip", {
if (!frm.doc.letter_head && company.default_letter_head) { if (!frm.doc.letter_head && company.default_letter_head) {
frm.set_value('letter_head', company.default_letter_head); frm.set_value('letter_head', company.default_letter_head);
} }
},
currency: function(frm) {
frm.trigger("set_dynamic_labels"); frm.trigger("set_dynamic_labels");
}, },
set_dynamic_labels: function(frm) { set_dynamic_labels: function(frm) {
var company_currency = frm.doc.company? erpnext.get_currency(frm.doc.company): frappe.defaults.get_default("currency"); var company_currency = frm.doc.company? erpnext.get_currency(frm.doc.company): frappe.defaults.get_default("currency");
frappe.run_serially([ if (frm.doc.employee && frm.doc.currency) {
() => frm.events.set_exchange_rate(frm, company_currency), frappe.run_serially([
() => frm.events.change_form_labels(frm, company_currency), () => frm.events.set_exchange_rate(frm, company_currency),
() => frm.events.change_grid_labels(frm), () => frm.events.change_form_labels(frm, company_currency),
() => frm.refresh_fields() () => frm.events.change_grid_labels(frm),
]); () => frm.refresh_fields()
]);
}
}, },
set_exchange_rate: function(frm, company_currency) { set_exchange_rate: function(frm, company_currency) {
if (frm.doc.docstatus === 0) { if (frm.doc.currency) {
if (frm.doc.currency) { var from_currency = frm.doc.currency;
var from_currency = frm.doc.currency; if (from_currency != company_currency) {
if (from_currency != company_currency) { frm.events.hide_loan_section(frm);
frm.events.hide_loan_section(frm); frappe.call({
frappe.call({ method: "erpnext.setup.utils.get_exchange_rate",
method: "erpnext.setup.utils.get_exchange_rate", args: {
args: { from_currency: from_currency,
from_currency: from_currency, to_currency: company_currency,
to_currency: company_currency, },
}, callback: function(r) {
callback: function(r) { frm.set_value("exchange_rate", flt(r.message));
frm.set_value("exchange_rate", flt(r.message)); frm.set_df_property("exchange_rate", "hidden", 0);
frm.set_df_property('exchange_rate', 'hidden', 0); frm.set_df_property("exchange_rate", "description", "1 " + frm.doc.currency
frm.set_df_property("exchange_rate", "description", "1 " + frm.doc.currency + " = [?] " + company_currency);
+ " = [?] " + company_currency); }
} });
}); } else {
} else { frm.set_value("exchange_rate", 1.0);
frm.set_value("exchange_rate", 1.0); frm.set_df_property("exchange_rate", "hidden", 1);
frm.set_df_property('exchange_rate', 'hidden', 1); frm.set_df_property("exchange_rate", "description", "");
frm.set_df_property("exchange_rate", "description", "" );
}
} }
} }
}, },