fix: Timesheet timer button

This commit is contained in:
Deepesh Garg 2022-11-20 19:45:51 +05:30
parent 89631fa744
commit 64802d1220

View File

@ -48,21 +48,23 @@ erpnext.timesheet.control_timer = function(frm, dialog, row, timestamp=0) {
var $btn_complete = dialog.$wrapper.find(".playpause .btn-complete");
var interval = null;
var currentIncrement = timestamp;
var initialised = row ? true : false;
var initialized = row ? true : false;
var clicked = false;
var flag = true; // Alert only once
// If row with not completed status, initialize timer with the time elapsed on click of 'Start Timer'.
if (row) {
initialised = true;
initialized = true;
$btn_start.hide();
$btn_complete.show();
initialiseTimer();
initializeTimer();
}
if (!initialised) {
if (!initialized) {
$btn_complete.hide();
}
$btn_start.click(function(e) {
if (!initialised) {
if (!initialized) {
// New activity if no activities found
var args = dialog.get_values();
if(!args) return;
@ -90,11 +92,11 @@ erpnext.timesheet.control_timer = function(frm, dialog, row, timestamp=0) {
return false;
}
if (!initialised) {
initialised = true;
if (!initialized) {
initialized = true;
$btn_start.hide();
$btn_complete.show();
initialiseTimer();
initializeTimer();
}
});
@ -110,11 +112,13 @@ erpnext.timesheet.control_timer = function(frm, dialog, row, timestamp=0) {
grid_row.doc.hours = currentIncrement / 3600;
grid_row.doc.to_time = frappe.datetime.now_datetime();
grid_row.refresh();
frm.dirty();
frm.save();
reset();
dialog.hide();
});
function initialiseTimer() {
function initializeTimer() {
interval = setInterval(function() {
var current = setCurrentIncrement();
updateStopwatch(current);
@ -151,7 +155,7 @@ erpnext.timesheet.control_timer = function(frm, dialog, row, timestamp=0) {
function reset() {
currentIncrement = 0;
initialised = false;
initialized = false;
clearInterval(interval);
$(".hours").text("00");
$(".minutes").text("00");