fix: job card time issue

This commit is contained in:
Rohit Waghchaure 2020-04-16 23:02:17 +05:30
parent 17ab1592c7
commit 250daa3f94
3 changed files with 38 additions and 7 deletions

View File

@ -82,7 +82,9 @@ frappe.ui.form.on('Job Card', {
frm.set_value('current_time' , 0);
}
frm.save();
frm.save("Save", () => {}, "", () => {
frm.doc.time_logs.pop(-1);
});
},
complete_job: function(frm, completed_time, completed_qty) {
@ -105,6 +107,24 @@ frappe.ui.form.on('Job Card', {
});
},
validate: function(frm) {
if ((!frm.doc.time_logs || !frm.doc.time_logs.length) && frm.doc.started_time) {
frm.trigger("reset_timer");
}
},
employee: function(frm) {
if (frm.doc.job_started && !frm.doc.current_time) {
frm.trigger("reset_timer");
}
},
reset_timer: function(frm) {
frm.set_value('started_time' , '');
frm.set_value('job_started', 0);
frm.set_value('current_time' , 0);
},
make_dashboard: function(frm) {
if(frm.doc.__islocal)
return;
@ -137,12 +157,12 @@ frappe.ui.form.on('Job Card', {
updateStopwatch(current);
}, 1000);
}
function updateStopwatch(increment) {
var hours = Math.floor(increment / 3600);
var minutes = Math.floor((increment - (hours * 3600)) / 60);
var seconds = increment - (hours * 3600) - (minutes * 60);
$(section).find(".hours").text(hours < 10 ? ("0" + hours.toString()) : hours.toString());
$(section).find(".minutes").text(minutes < 10 ? ("0" + minutes.toString()) : minutes.toString());
$(section).find(".seconds").text(seconds < 10 ? ("0" + seconds.toString()) : seconds.toString());
@ -205,5 +225,10 @@ frappe.ui.form.on('Job Card', {
frappe.ui.form.on('Job Card Time Log', {
completed_qty: function(frm) {
frm.events.set_total_completed_qty(frm);
},
to_time: function(frm) {
frm.set_value('job_started', 0);
frm.set_value('started_time', '');
}
})

View File

@ -9,7 +9,7 @@ from frappe import _
from frappe.model.mapper import get_mapped_doc
from frappe.model.document import Document
from frappe.utils import (flt, cint, time_diff_in_hours, get_datetime, getdate,
get_time, add_to_date, time_diff, add_days, get_datetime_str)
get_time, add_to_date, time_diff, add_days, get_datetime_str, get_link_to_form)
from erpnext.manufacturing.doctype.manufacturing_settings.manufacturing_settings import get_mins_between_operations
@ -189,11 +189,15 @@ class JobCard(Document):
def validate_job_card(self):
if not self.time_logs:
frappe.throw(_("Time logs are required for job card {0}").format(self.name))
frappe.throw(_("Time logs are required for {0} {1}")
.format(frappe.bold("Job Card"), get_link_to_form("Job Card", self.name)))
if self.for_quantity and self.total_completed_qty != self.for_quantity:
frappe.throw(_("The total completed qty({0}) must be equal to qty to manufacture({1})"
.format(frappe.bold(self.total_completed_qty),frappe.bold(self.for_quantity))))
total_completed_qty = frappe.bold(_("Total Completed Qty"))
qty_to_manufacture = frappe.bold(_("Qty to Manufacture"))
frappe.throw(_("The {0} ({1}) must be equal to {2} ({3})"
.format(total_completed_qty, frappe.bold(self.total_completed_qty), qty_to_manufacture,frappe.bold(self.for_quantity))))
def update_work_order(self):
if not self.work_order:

View File

@ -240,6 +240,8 @@ frappe.ui.form.on("Work Order", {
});
}, __("Job Card"), __("Create"));
dialog.fields_dict["operations"].grid.wrapper.find('.grid-add-row').hide();
var pending_qty = 0;
frm.doc.operations.forEach(data => {
if(data.completed_qty != frm.doc.qty) {