fix(projects): Auto-set employee and company in Timesheet (#16743)
* fix(projects): auto-set employee and company * only set employee and company if document is unsaved * use frm.set_value()
This commit is contained in:
parent
843b7f6dd5
commit
fdbb516a1b
@ -10,8 +10,8 @@ frappe.ui.form.on("Timesheet", {
|
|||||||
filters:{
|
filters:{
|
||||||
'status': 'Active'
|
'status': 'Active'
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
frm.fields_dict['time_logs'].grid.get_field('task').get_query = function(frm, cdt, cdn) {
|
frm.fields_dict['time_logs'].grid.get_field('task').get_query = function(frm, cdt, cdn) {
|
||||||
var child = locals[cdt][cdn];
|
var child = locals[cdt][cdn];
|
||||||
@ -20,33 +20,37 @@ frappe.ui.form.on("Timesheet", {
|
|||||||
'project': child.project,
|
'project': child.project,
|
||||||
'status': ["!=", "Cancelled"]
|
'status': ["!=", "Cancelled"]
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
frm.fields_dict['time_logs'].grid.get_field('project').get_query = function() {
|
frm.fields_dict['time_logs'].grid.get_field('project').get_query = function() {
|
||||||
return{
|
return{
|
||||||
filters: {
|
filters: {
|
||||||
'company': frm.doc.company
|
'company': frm.doc.company
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
onload: function(frm){
|
onload: function(frm){
|
||||||
if (frm.doc.__islocal && frm.doc.time_logs) {
|
if (frm.doc.__islocal && frm.doc.time_logs) {
|
||||||
calculate_time_and_amount(frm);
|
calculate_time_and_amount(frm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (frm.is_new()) {
|
||||||
|
set_employee_and_company(frm);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
if(frm.doc.docstatus==1) {
|
if(frm.doc.docstatus==1) {
|
||||||
if(frm.doc.per_billed < 100 && frm.doc.total_billable_hours && frm.doc.total_billable_hours > frm.doc.total_billed_hours){
|
if(frm.doc.per_billed < 100 && frm.doc.total_billable_hours && frm.doc.total_billable_hours > frm.doc.total_billed_hours){
|
||||||
frm.add_custom_button(__("Make Sales Invoice"), function() { frm.trigger("make_invoice") },
|
frm.add_custom_button(__("Make Sales Invoice"), function() { frm.trigger("make_invoice"); },
|
||||||
"fa fa-file-alt");
|
"fa fa-file-alt");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!frm.doc.salary_slip && frm.doc.employee){
|
if(!frm.doc.salary_slip && frm.doc.employee){
|
||||||
frm.add_custom_button(__("Make Salary Slip"), function() { frm.trigger("make_salary_slip") },
|
frm.add_custom_button(__("Make Salary Slip"), function() { frm.trigger("make_salary_slip"); },
|
||||||
"fa fa-file-alt");
|
"fa fa-file-alt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,7 +62,7 @@ frappe.ui.form.on("Timesheet", {
|
|||||||
if ((row.from_time <= frappe.datetime.now_datetime()) && !row.completed) {
|
if ((row.from_time <= frappe.datetime.now_datetime()) && !row.completed) {
|
||||||
button = 'Resume Timer';
|
button = 'Resume Timer';
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
frm.add_custom_button(__(button), function() {
|
frm.add_custom_button(__(button), function() {
|
||||||
var flag = true;
|
var flag = true;
|
||||||
@ -77,7 +81,7 @@ frappe.ui.form.on("Timesheet", {
|
|||||||
erpnext.timesheet.timer(frm, row, timestamp);
|
erpnext.timesheet.timer(frm, row, timestamp);
|
||||||
flag = false;
|
flag = false;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
// If no activities found to start a timer, create new
|
// If no activities found to start a timer, create new
|
||||||
if (flag) {
|
if (flag) {
|
||||||
erpnext.timesheet.timer(frm);
|
erpnext.timesheet.timer(frm);
|
||||||
@ -125,8 +129,8 @@ frappe.ui.form.on("Timesheet", {
|
|||||||
frappe.set_route("Form", r.message.doctype, r.message.name);
|
frappe.set_route("Form", r.message.doctype, r.message.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
dialog.show();
|
dialog.show();
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -136,7 +140,7 @@ frappe.ui.form.on("Timesheet", {
|
|||||||
frm: frm
|
frm: frm
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
frappe.ui.form.on("Timesheet Detail", {
|
frappe.ui.form.on("Timesheet Detail", {
|
||||||
time_logs_remove: function(frm) {
|
time_logs_remove: function(frm) {
|
||||||
@ -171,22 +175,22 @@ frappe.ui.form.on("Timesheet Detail", {
|
|||||||
.find('[data-fieldname="timer"]')
|
.find('[data-fieldname="timer"]')
|
||||||
.append(frappe.render_template("timesheet"));
|
.append(frappe.render_template("timesheet"));
|
||||||
frm.trigger("control_timer");
|
frm.trigger("control_timer");
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
hours: function(frm, cdt, cdn) {
|
hours: function(frm, cdt, cdn) {
|
||||||
calculate_end_time(frm, cdt, cdn)
|
calculate_end_time(frm, cdt, cdn);
|
||||||
},
|
},
|
||||||
|
|
||||||
billing_hours: function(frm, cdt, cdn) {
|
billing_hours: function(frm, cdt, cdn) {
|
||||||
calculate_billing_costing_amount(frm, cdt, cdn)
|
calculate_billing_costing_amount(frm, cdt, cdn);
|
||||||
},
|
},
|
||||||
|
|
||||||
billing_rate: function(frm, cdt, cdn) {
|
billing_rate: function(frm, cdt, cdn) {
|
||||||
calculate_billing_costing_amount(frm, cdt, cdn)
|
calculate_billing_costing_amount(frm, cdt, cdn);
|
||||||
},
|
},
|
||||||
|
|
||||||
costing_rate: function(frm, cdt, cdn) {
|
costing_rate: function(frm, cdt, cdn) {
|
||||||
calculate_billing_costing_amount(frm, cdt, cdn)
|
calculate_billing_costing_amount(frm, cdt, cdn);
|
||||||
},
|
},
|
||||||
|
|
||||||
billable: function(frm, cdt, cdn) {
|
billable: function(frm, cdt, cdn) {
|
||||||
@ -212,7 +216,7 @@ frappe.ui.form.on("Timesheet Detail", {
|
|||||||
calculate_billing_costing_amount(frm, cdt, cdn);
|
calculate_billing_costing_amount(frm, cdt, cdn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -244,19 +248,19 @@ var calculate_end_time = function(frm, cdt, cdn) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
var update_billing_hours = function(frm, cdt, cdn){
|
var update_billing_hours = function(frm, cdt, cdn){
|
||||||
var child = locals[cdt][cdn];
|
var child = locals[cdt][cdn];
|
||||||
if(!child.billable) frappe.model.set_value(cdt, cdn, 'billing_hours', 0.0);
|
if(!child.billable) frappe.model.set_value(cdt, cdn, 'billing_hours', 0.0);
|
||||||
}
|
};
|
||||||
|
|
||||||
var update_time_rates = function(frm, cdt, cdn){
|
var update_time_rates = function(frm, cdt, cdn){
|
||||||
var child = locals[cdt][cdn];
|
var child = locals[cdt][cdn];
|
||||||
if(!child.billable){
|
if(!child.billable){
|
||||||
frappe.model.set_value(cdt, cdn, 'billing_rate', 0.0);
|
frappe.model.set_value(cdt, cdn, 'billing_rate', 0.0);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
var calculate_billing_costing_amount = function(frm, cdt, cdn){
|
var calculate_billing_costing_amount = function(frm, cdt, cdn){
|
||||||
var child = locals[cdt][cdn];
|
var child = locals[cdt][cdn];
|
||||||
@ -270,7 +274,7 @@ var calculate_billing_costing_amount = function(frm, cdt, cdn){
|
|||||||
frappe.model.set_value(cdt, cdn, 'billing_amount', billing_amount);
|
frappe.model.set_value(cdt, cdn, 'billing_amount', billing_amount);
|
||||||
frappe.model.set_value(cdt, cdn, 'costing_amount', costing_amount);
|
frappe.model.set_value(cdt, cdn, 'costing_amount', costing_amount);
|
||||||
calculate_time_and_amount(frm);
|
calculate_time_and_amount(frm);
|
||||||
}
|
};
|
||||||
|
|
||||||
var calculate_time_and_amount = function(frm) {
|
var calculate_time_and_amount = function(frm) {
|
||||||
var tl = frm.doc.time_logs || [];
|
var tl = frm.doc.time_logs || [];
|
||||||
@ -294,4 +298,17 @@ var calculate_time_and_amount = function(frm) {
|
|||||||
frm.set_value("total_hours", total_working_hr);
|
frm.set_value("total_hours", total_working_hr);
|
||||||
frm.set_value("total_billable_amount", total_billable_amount);
|
frm.set_value("total_billable_amount", total_billable_amount);
|
||||||
frm.set_value("total_costing_amount", total_costing_amount);
|
frm.set_value("total_costing_amount", total_costing_amount);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
// set employee (and company) to the one that's currently logged in
|
||||||
|
const set_employee_and_company = function(frm) {
|
||||||
|
const options = { user_id: frappe.session.user };
|
||||||
|
const fields = ['name', 'company'];
|
||||||
|
frappe.db.get_value('Employee', options, fields).then(({ message }) => {
|
||||||
|
if (message) {
|
||||||
|
// there is an employee with the currently logged in user_id
|
||||||
|
frm.set_value("employee", message.name);
|
||||||
|
frm.set_value("company", message.company);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user