Merge pull request #3614 from neilLasrado/po

Track Operations added to Production Order
This commit is contained in:
Nabin Hait 2015-07-13 12:29:45 +05:30
commit 7daa7900ea
4 changed files with 41 additions and 15 deletions

View File

@ -186,15 +186,26 @@ $.extend(cur_frm.cscript, {
},
bom_no: function() {
return this.frm.call({
doc: this.frm.doc,
method: "set_production_order_operations"
});
if (this.frm.doc.track_operations) {
return this.frm.call({
doc: this.frm.doc,
method: "set_production_order_operations"
});
}
},
qty: function() {
frappe.ui.form.trigger("Production Order", 'bom_no')
},
track_operations: function(doc) {
if (doc.track_operations) {
frappe.ui.form.trigger("Production Order", 'bom_no')
}
else {
doc.operations =[];
}
},
show_time_logs: function(doc, cdt, cdn) {
var child = locals[cdt][cdn]

View File

@ -73,6 +73,14 @@
"label": "Use Multi-Level BOM",
"permlevel": 0
},
{
"default": "1",
"fieldname": "track_operations",
"fieldtype": "Check",
"label": "Track Operations",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "column_break1",
"fieldtype": "Column Break",
@ -207,7 +215,7 @@
"read_only": 1
},
{
"depends_on": "",
"depends_on": "track_operations",
"fieldname": "operations_section",
"fieldtype": "Section Break",
"label": "Operations",
@ -216,6 +224,7 @@
"precision": ""
},
{
"depends_on": "",
"fieldname": "operations",
"fieldtype": "Table",
"label": "Operations",
@ -225,6 +234,7 @@
"read_only": 1
},
{
"depends_on": "track_operations",
"fieldname": "section_break_22",
"fieldtype": "Section Break",
"label": "Operation Cost",
@ -358,7 +368,7 @@
"idx": 1,
"in_create": 0,
"is_submittable": 1,
"modified": "2015-04-13 02:44:17.319988",
"modified": "2015-07-09 03:31:01.291811",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Production Order",

View File

@ -174,13 +174,17 @@ class ProductionOrder(Document):
def set_production_order_operations(self):
"""Fetch operations from BOM and set in 'Production Order'"""
if not self.bom_no:
return
self.set('operations', [])
operations = frappe.db.sql("""select operation, description, workstation, idx,
hour_rate, time_in_mins, "Pending" as status from `tabBOM Operation`
where parent = %s order by idx""", self.bom_no, as_dict=1)
if operations:
self.track_operations=1
else:
self.track_operations=0
frappe.msgprint(_("Cannot 'track operations' as selected BOM does not have Operations."))
self.set('operations', operations)
self.calculate_time()
@ -219,14 +223,12 @@ class ProductionOrder(Document):
for i, d in enumerate(self.operations):
self.set_operation_start_end_time(i, d)
if not d.workstation:
continue
time_log = make_time_log(self.name, d.operation, d.planned_start_time, d.planned_end_time,
flt(self.qty) - flt(d.completed_qty), self.project_name, d.workstation, operation_id=d.name)
# validate operating hours if workstation [not mandatory] is specified
self.check_operation_fits_in_working_hours(d)
if d.workstation:
# validate operating hours if workstation [not mandatory] is specified
self.check_operation_fits_in_working_hours(d)
original_start_time = time_log.from_time
while True:
@ -391,7 +393,7 @@ def get_events(start, end, filters=None):
return data
@frappe.whitelist()
def make_time_log(name, operation, from_time, to_time, qty=None, project=None, workstation=None, operation_id=None):
def make_time_log(name, operation, from_time=None, to_time=None, qty=None, project=None, workstation=None, operation_id=None):
time_log = frappe.new_doc("Time Log")
time_log.for_manufacturing = 1
time_log.from_time = from_time

View File

@ -201,6 +201,9 @@ class StockEntry(StockController):
def check_if_operations_completed(self):
"""Check if Time Logs are completed against before manufacturing to capture operating costs."""
prod_order = frappe.get_doc("Production Order", self.production_order)
if not prod_order.track_operations:
return
for d in prod_order.get("operations"):
total_completed_qty = flt(self.fg_completed_qty) + flt(prod_order.produced_qty)
if total_completed_qty > flt(d.completed_qty):