fixes for productiojn order

This commit is contained in:
Neil Trini Lasrado 2015-01-29 17:56:37 +05:30
parent b736443e3f
commit a9b3ec180e
2 changed files with 32 additions and 13 deletions

View File

@ -7,6 +7,11 @@ $.extend(cur_frm.cscript, {
cfn_set_fields(doc, dt, dn);
this.frm.add_fetch("sales_order", "delivery_date", "expected_delivery_date");
return this.frm.call({
doc: this.frm.doc,
method: "set_actual_dates"
});
},
before_submit: function() {
@ -60,10 +65,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):