Track Operations added to Production Order

This commit is contained in:
Neil Trini Lasrado 2015-07-09 14:46:32 +05:30
parent f3b0b95b15
commit 5da4d857c9
4 changed files with 46 additions and 16 deletions

View File

@ -186,15 +186,24 @@ $.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() {
return this.frm.call({
doc: this.frm.doc,
method: "track_operation"
});
},
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

@ -4,7 +4,7 @@
from __future__ import unicode_literals
import frappe, json
from frappe.utils import flt, nowdate, get_datetime, getdate, date_diff, cint
from frappe.utils import flt, nowdate, get_datetime, getdate, date_diff, cint, now
from frappe import _
from frappe.model.document import Document
from erpnext.manufacturing.doctype.bom.bom import validate_bom_no
@ -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:
@ -327,6 +329,12 @@ class ProductionOrder(Document):
if frappe.db.get_value("Item", self.production_item, "has_variants"):
frappe.throw(_("Production Order cannot be raised against a Item Template"))
def track_operation(self):
if self.track_operations:
self.set_production_order_operations()
else:
self.set('operations', [])
@frappe.whitelist()
def get_item_details(item):
@ -391,7 +399,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=now(), to_time=now(), 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):