Timer fixes (#13443)

* alert for exceeded time only when dialog is open

* fetch row having an activity without from_time

* fixes if timesheet created from work order

* reset timer limit exceeded
This commit is contained in:
Shreya Shah
2018-04-02 10:32:39 +05:30
committed by Nabin Hait
parent edd320e338
commit 5d71609f0b
2 changed files with 19 additions and 14 deletions

View File

@@ -53,16 +53,6 @@ frappe.ui.form.on("Timesheet", {
if (frm.doc.docstatus < 1) {
$.each(frm.doc.time_logs || [], function(i, row) {
if(row.from_time && !row.completed) {
if (row.to_time && frappe.datetime.now_datetime() > row.to_time) {
frappe.utils.play_sound("alert");
frappe.msgprint(__(`Timer exceeded the expected hours for activity ${row.activity_type} in row ${row.idx}.`));
}
}
frm.refresh_fields();
});
let button = 'Start Timer';
$.each(frm.doc.time_logs || [], function(i, row) {
if ((row.from_time <= frappe.datetime.now_datetime()) && !row.completed) {
@@ -72,8 +62,16 @@ frappe.ui.form.on("Timesheet", {
frm.add_custom_button(__(button), function() {
var flag = true;
// Fetch the row for timer where activity is not completed and from_time is not <= now_time
$.each(frm.doc.time_logs || [], function(i, row) {
// Fetch the row for which from_time is not present
if (flag && row.activity_type && !row.from_time){
erpnext.timesheet.timer(frm, row);
row.from_time = frappe.datetime.now_datetime();
frm.refresh_fields("time_logs");
frm.save();
flag = false;
}
// Fetch the row for timer where activity is not completed and from_time is before now_time
if (flag && row.from_time <= frappe.datetime.now_datetime() && !row.completed) {
let timestamp = moment(frappe.datetime.now_datetime()).diff(moment(row.from_time),"seconds");
erpnext.timesheet.timer(frm, row, timestamp);