I want to change the reports_to_name field as the reporting person has changed.I want the field to be updated from today’s date i.e. 19/11/19 but the reports_to_name field before 19/11/19 should show the old person’s name.How do I do this?? Please help I am new to erpnext.
Below is the custom script for same:
frappe.ui.form.on("Employee", {
"year": function(frm) {
frappe.model.with_doc("Calendar Year", frm.doc.year, function() {
var tabletransfer = frappe.model.get_doc("Calendar Year", frm.doc.year);
$.each(tabletransfer.c_dates, function(index, row){
var d = frm.add_child("dsr_submitted");
d.date = row.date;
d.employee = cur_frm.doc.name;
d.employee_name = cur_frm.doc.employee_name;
d.report_to = cur_frm.doc.reports_to;
d.reports_to_name = cur_frm.doc.reports_to_name;
frm.refresh_field("c_dates");
});
});
}
});
frappe.ui.form.on("Employee", {
"holiday_year": function(frm) {
frappe.model.with_doc("Calendar Year", frm.doc.holiday_year, function() {
var tabletransfer = frappe.model.get_doc("Calendar Year", frm.doc.holiday_year);
$.each(tabletransfer.c_dates, function(index, row){
var d = frm.add_child("dsr_submitted");
d.date = row.date;
d.employee = cur_frm.doc.name;
d.employee_name = cur_frm.doc.employee_name;
d.report_to = cur_frm.doc.reports_to;
d.reports_to_name = cur_frm.doc.reports_to_name;
d.holiday = 1;
frm.refresh_field("c_dates");
});
});
}
});
frappe.ui.form.on("Employee", "pause_dsr", function(frm){
if (cur_frm.doc.pause_dsr == "1")
{
cur_frm.toggle_reqd("from_date", true);
cur_frm.toggle_reqd("to_date", true);
}
});
frappe.ui.form.on("Employee", "validate", function(frm){
if (cur_frm.doc.pause_dsr == "1"){
var start = new Date(cur_frm.doc.from_date);
var end = new Date(cur_frm.doc.to_date);
while (start <= end) {
for(var i = 0; i < cur_frm.doc.dsr_submitted.length; i++)
{
var dsr = new Date(cur_frm.doc.dsr_submitted[i].date);
if(dsr.getTime() === start.getTime())
{
cur_frm.doc.dsr_submitted[i].dsr_pause = 1;
}
}
start.setDate(start.getDate() + 1);
}
}
});
frappe.ui.form.on("Employee","reports_to", function()
{
for (var i =0; i < cur_frm.doc.dsr_submitted.length; i++){
cur_frm.doc.dsr_submitted[i].report_to = cur_frm.doc.reports_to;
}
cur_frm.refresh_field('dsr_submitted')
});
frappe.ui.form.on("Employee","reports_to", function()
{
for (var i =0; i < cur_frm.doc.dsr_submitted.length; i++){
cur_frm.doc.dsr_submitted[i].reports_to_name = cur_frm.doc.reports_to_name;
}
cur_frm.refresh_field('dsr_submitted')
});
frappe.ui.form.on("Employee","status", function()
{
for (var i =0; i < cur_frm.doc.dsr_submitted.length; i++){
if(cur_frm.doc.status = 'Left')
{
cur_frm.doc.dsr_submitted[i].deactivated = 1;
}
}
cur_frm.refresh_field('dsr_submitted')
});