fix: timesheet fetching in sales invoice

This commit is contained in:
Saqib Ansari
2022-05-25 12:12:35 +05:30
parent 22aeacb088
commit 216c32f4bc

View File

@@ -475,7 +475,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
let row = frappe.get_doc(d.doctype, d.name) let row = frappe.get_doc(d.doctype, d.name)
set_timesheet_detail_rate(row.doctype, row.name, me.frm.doc.currency, row.timesheet_detail) set_timesheet_detail_rate(row.doctype, row.name, me.frm.doc.currency, row.timesheet_detail)
}); });
frm.trigger("calculate_timesheet_totals"); this.frm.trigger("calculate_timesheet_totals");
} }
} }
}); });
@@ -885,27 +885,44 @@ frappe.ui.form.on('Sales Invoice', {
set_timesheet_data: function(frm, timesheets) { set_timesheet_data: function(frm, timesheets) {
frm.clear_table("timesheets") frm.clear_table("timesheets")
timesheets.forEach(timesheet => { timesheets.forEach(async (timesheet) => {
if (frm.doc.currency != timesheet.currency) { if (frm.doc.currency != timesheet.currency) {
frappe.call({ const exchange_rate = await frm.events.get_exchange_rate(
method: "erpnext.setup.utils.get_exchange_rate", frm, timesheet.currency, frm.doc.currency
args: { )
from_currency: timesheet.currency, frm.events.append_time_log(frm, timesheet, exchange_rate)
to_currency: frm.doc.currency
},
callback: function(r) {
if (r.message) {
exchange_rate = r.message;
frm.events.append_time_log(frm, timesheet, exchange_rate);
}
}
});
} else { } else {
frm.events.append_time_log(frm, timesheet, 1.0); frm.events.append_time_log(frm, timesheet, 1.0);
} }
}); });
}, },
async get_exchange_rate(frm, from_currency, to_currency) {
if (
frm.exchange_rates
&& frm.exchange_rates[from_currency]
&& frm.exchange_rates[from_currency][to_currency]
) {
return frm.exchange_rates[from_currency][to_currency];
}
return frappe.call({
method: "erpnext.setup.utils.get_exchange_rate",
args: {
from_currency,
to_currency
},
callback: function(r) {
if (r.message) {
// cache exchange rates
frm.exchange_rates = frm.exchange_rates || {};
frm.exchange_rates[from_currency] = frm.exchange_rates[from_currency] || {};
frm.exchange_rates[from_currency][to_currency] = r.message;
}
}
});
},
append_time_log: function(frm, time_log, exchange_rate) { append_time_log: function(frm, time_log, exchange_rate) {
const row = frm.add_child("timesheets"); const row = frm.add_child("timesheets");
row.activity_type = time_log.activity_type; row.activity_type = time_log.activity_type;
@@ -916,7 +933,7 @@ frappe.ui.form.on('Sales Invoice', {
row.billing_hours = time_log.billing_hours; row.billing_hours = time_log.billing_hours;
row.billing_amount = flt(time_log.billing_amount) * flt(exchange_rate); row.billing_amount = flt(time_log.billing_amount) * flt(exchange_rate);
row.timesheet_detail = time_log.name; row.timesheet_detail = time_log.name;
row.project_name = time_log.project_name; row.project_name = time_log.project_name;
frm.refresh_field("timesheets"); frm.refresh_field("timesheets");
frm.trigger("calculate_timesheet_totals"); frm.trigger("calculate_timesheet_totals");