Merge pull request #2656 from neilLasrado/po-capacity-planning

fixes for production order
This commit is contained in:
Nabin Hait 2015-02-06 16:04:08 +05:30
commit 4ed51416e5
3 changed files with 36 additions and 14 deletions

View File

@ -7,6 +7,13 @@ $.extend(cur_frm.cscript, {
cfn_set_fields(doc, dt, dn);
this.frm.add_fetch("sales_order", "delivery_date", "expected_delivery_date");
if(doc.__islocal) {
cur_frm.set_value({
"actual_start_date": "",
"actual_end_date": ""
});
}
},
before_submit: function() {
@ -60,10 +67,14 @@ $.extend(cur_frm.cscript, {
bom_no: function() {
return this.frm.call({
doc: this.frm.doc,
method: "set_production_order_operations",
callback: function(r) {
if(!r.exc) refresh_field("operations");
}
method: "set_production_order_operations"
});
},
planned_start_date: function() {
return this.frm.call({
doc: this.frm.doc,
method: "plan_operations"
});
},

View File

@ -175,16 +175,17 @@ class ProductionOrder(Document):
self.calculate_operating_cost()
def plan_operations(self):
scheduled_datetime = self.planned_start_date
for d in self.get('operations'):
while getdate(scheduled_datetime) in self.get_holidays(d.workstation):
scheduled_datetime = get_datetime(scheduled_datetime) + relativedelta(days=1)
if self.planned_start_date:
scheduled_datetime = self.planned_start_date
for d in self.get('operations'):
while getdate(scheduled_datetime) in self.get_holidays(d.workstation):
scheduled_datetime = get_datetime(scheduled_datetime) + relativedelta(days=1)
d.planned_start_time = scheduled_datetime
scheduled_datetime = get_datetime(scheduled_datetime) + relativedelta(minutes=d.time_in_mins)
d.planned_end_time = scheduled_datetime
d.planned_start_time = scheduled_datetime
scheduled_datetime = get_datetime(scheduled_datetime) + relativedelta(minutes=d.time_in_mins)
d.planned_end_time = scheduled_datetime
self.planned_end_date = scheduled_datetime
self.planned_end_date = scheduled_datetime
def get_holidays(self, workstation):
@ -208,7 +209,16 @@ class ProductionOrder(Document):
d.status = "Completed"
else:
frappe.throw(_("Completed Qty can not be greater than 'Qty to Manufacture'"))
def set_actual_dates(self):
if self.get("operations"):
actual_date = frappe.db.sql("""select min(actual_start_time) as start_date, max(actual_end_time) as end_date from `tabProduction Order Operation`
where parent = %s and docstatus=1""", self.name, as_dict=1)[0]
self.actual_start_date = actual_date.start_date
self.actual_end_date = actual_date.end_date
else:
self.actual_start_date = None
self.actual_end_date = None
@frappe.whitelist()
def get_item_details(item):
@ -288,7 +298,7 @@ def make_time_log(name, operation, from_time, to_time, qty=None, project=None,
@frappe.whitelist()
def auto_make_time_log(production_order_id):
if frappe.db.get_value("Time Log", filters={"production_order": production_order_id}):
if frappe.db.get_value("Time Log", filters={"production_order": production_order_id, "docstatus":1}):
frappe.throw(_("Time logs already exists against this Production Order"))
time_logs = []

View File

@ -111,6 +111,7 @@ class TimeLog(Document):
pro_order.ignore_validate_update_after_submit = True
pro_order.update_operation_status()
pro_order.calculate_operating_cost()
pro_order.set_actual_dates()
pro_order.save()
def get_operation_start_end_time(self):