time log and workstations

This commit is contained in:
Nabin Hait
2014-12-22 14:31:53 +05:30
parent 0f4350dd61
commit 0de6256bcc
13 changed files with 203 additions and 109 deletions

View File

@@ -5,6 +5,16 @@ frappe.provide("erpnext.projects");
frappe.ui.form.on("Time Log", "onload", function(frm) {
frm.set_query("task", erpnext.queries.task);
if (frm.doc.time_log_for == "Manufacturing") {
frappe.ui.form.trigger("Time Log", "production_order");
}
});
frappe.ui.form.on("Time Log", "refresh", function(frm) {
var is_manufacturing = frm.doc.time_log_for=="Manufacturing" ? true : false;
frm.toggle_reqd("production_order", is_manufacturing);
frm.toggle_reqd("operation", is_manufacturing);
frm.toggle_reqd("operation_status", is_manufacturing);
});
// set to time if hours is updated
@@ -45,7 +55,7 @@ $.extend(cur_frm.cscript, {
$.each(doc.production_order_operations , function(i, row){
operations[i] = (i+1) +". "+ row.operation;
});
frappe.meta.get_docfield("Time Log", "operation", me.frm.doc.name).options = operations.join("\n");
frappe.meta.get_docfield("Time Log", "operation", me.frm.doc.name).options = "\n" + operations.join("\n");
refresh_field("operation");
})
}
@@ -60,14 +70,10 @@ $.extend(cur_frm.cscript, {
},
callback: function(r) {
if(!r.exc) {
console.log(r.message)
cur_frm.set_value("workstation", r.message)
}
doc.workstation = r.workstation;
}
});
}
});
if (cur_frm.doc.time_log_for == "Manufacturing") {
cur_frm.cscript.onload = cur_frm.cscript.production_order;
}

View File

@@ -152,7 +152,7 @@
"read_only": 0
},
{
"depends_on": "eval:doc.time_log_for == 'Project'",
"depends_on": "eval:doc.time_log_for",
"fieldname": "project",
"fieldtype": "Link",
"in_list_view": 1,
@@ -200,7 +200,7 @@
"icon": "icon-time",
"idx": 1,
"is_submittable": 1,
"modified": "2014-12-18 17:21:01.520646",
"modified": "2014-12-19 14:20:41.381152",
"modified_by": "Administrator",
"module": "Projects",
"name": "Time Log",

View File

@@ -8,7 +8,6 @@ import frappe, json
from frappe import _
from frappe.utils import cstr, comma_and, flt
class OverlapError(frappe.ValidationError): pass
class OverProductionError(frappe.ValidationError): pass
class NotSubmittedError(frappe.ValidationError): pass
@@ -21,8 +20,10 @@ class TimeLog(Document):
self.validate_overlap()
self.validate_timings()
self.calculate_total_hours()
self.validate_time_log_for()
self.check_workstation_timings()
self.validate_production_order()
self.validate_operation_status()
def on_submit(self):
self.update_production_order()
@@ -74,6 +75,11 @@ class TimeLog(Document):
from frappe.utils import time_diff_in_seconds
self.hours = flt(time_diff_in_seconds(self.to_time, self.from_time)) / 3600
def validate_time_log_for(self):
if self.time_log_for == "Project":
for fld in ["production_order", "operation", "workstation", "operation_status"]:
self.set(fld, None)
def check_workstation_timings(self):
"""Checks if **Time Log** is between operating hours of the **Workstation**."""
if self.workstation:
@@ -82,28 +88,39 @@ class TimeLog(Document):
def validate_production_order(self):
"""Throws 'NotSubmittedError' if **production order** is not submitted. """
if self.production_order:
if frappe.db.get_value("Production Order", self.production_order, "docstatus") != 1 :
frappe.throw(_("You can make a time log only against a submitted production order"), NotSubmittedError)
def validate_operation_status(self):
if self.time_log_for=="Manufacturing" and self.production_order and self.operation:
if self.operation_status == "Work in Progress":
latest_time_log = self.get_latest_time_log()
if latest_time_log and latest_time_log[0].operation_status == "Completed":
frappe.throw("Operation is already completed via Time Log {}".format(latest_time_log[0].name))
def update_production_order(self):
"""Updates `start_date`, `end_date`, `status` for operation in Production Order."""
if self.time_log_for=="Manufacturing" and self.operation:
dates = self.get_operation_start_end_time()
op_status = self.get_op_status()
actual_op_time = self.get_actual_op_time()
latest_time_log = self.get_latest_time_log()
op_status = latest_time_log[0].operation_status if latest_time_log else "Pending"
actual_op_time = self.get_actual_op_time()
d = self.operation.split('. ',1)
frappe.db.sql("""update `tabProduction Order Operation`
set actual_start_time = %s, actual_end_time = %s, status = %s, actual_operation_time = %s
where parent=%s and idx=%s and operation = %s""",
(dates.start_date, dates.end_date, op_status, actual_op_time,
self.production_order, d[0], d[1]))
(dates.start_date, dates.end_date, op_status,
actual_op_time, self.production_order, d[0], d[1]))
frappe.get_doc("Production Order", self.production_order).save()
pro_order = frappe.get_doc("Production Order", self.production_order)
pro_order.ignore_validate_update_after_submit = True
pro_order.calculate_operating_cost()
pro_order.save()
def get_operation_start_end_time(self):
"""Returns Min From and Max To Dates of Time Logs against a specific Operation. """
@@ -118,12 +135,10 @@ class TimeLog(Document):
(self.production_order, self.operation))
return actual_time[0][0] if actual_time else 0
def get_op_status(self):
status = frappe.db.sql("""select operation_status from `tabTime Log`
def get_latest_time_log(self):
return frappe.db.sql("""select name, operation_status from `tabTime Log`
where production_order=%s and operation=%s and docstatus=1
order by to_time desc limit 1""", (self.production_order, self.operation))
return status if status else self.status
order by to_time desc limit 1""", (self.production_order, self.operation), as_dict=1)
@frappe.whitelist()
def get_workstation(production_order, operation):