From a9b3ec180e261c04df985e0f39eafbe4656b0a39 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Thu, 29 Jan 2015 17:56:37 +0530 Subject: [PATCH 1/4] fixes for productiojn order --- .../production_order/production_order.js | 17 ++++++++--- .../production_order/production_order.py | 28 +++++++++++++------ 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/erpnext/manufacturing/doctype/production_order/production_order.js b/erpnext/manufacturing/doctype/production_order/production_order.js index 502277bc97..f8bb99ebdb 100644 --- a/erpnext/manufacturing/doctype/production_order/production_order.js +++ b/erpnext/manufacturing/doctype/production_order/production_order.js @@ -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" }); }, diff --git a/erpnext/manufacturing/doctype/production_order/production_order.py b/erpnext/manufacturing/doctype/production_order/production_order.py index 9ac1c4848a..83a7ff12ab 100644 --- a/erpnext/manufacturing/doctype/production_order/production_order.py +++ b/erpnext/manufacturing/doctype/production_order/production_order.py @@ -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): From 2017796de79a44f20a5d414a61c1dcc18576c956 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Fri, 30 Jan 2015 15:26:04 +0530 Subject: [PATCH 2/4] fixes in auto create time logs --- .../manufacturing/doctype/production_order/production_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/manufacturing/doctype/production_order/production_order.py b/erpnext/manufacturing/doctype/production_order/production_order.py index 83a7ff12ab..396ec98c51 100644 --- a/erpnext/manufacturing/doctype/production_order/production_order.py +++ b/erpnext/manufacturing/doctype/production_order/production_order.py @@ -298,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 = [] From de164c91e0f6fb8d5185ad6c80ba6638300b204f Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Wed, 4 Feb 2015 11:35:10 +0530 Subject: [PATCH 3/4] actual start and end date calculation - call moved to submit and cancel of Time Log --- .../doctype/production_order/production_order.js | 5 ----- erpnext/projects/doctype/time_log/time_log.py | 1 + 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/erpnext/manufacturing/doctype/production_order/production_order.js b/erpnext/manufacturing/doctype/production_order/production_order.js index f8bb99ebdb..d7dc79a953 100644 --- a/erpnext/manufacturing/doctype/production_order/production_order.js +++ b/erpnext/manufacturing/doctype/production_order/production_order.js @@ -7,11 +7,6 @@ $.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() { diff --git a/erpnext/projects/doctype/time_log/time_log.py b/erpnext/projects/doctype/time_log/time_log.py index 52257437b3..f4cb89e74e 100644 --- a/erpnext/projects/doctype/time_log/time_log.py +++ b/erpnext/projects/doctype/time_log/time_log.py @@ -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): From 59a706585ce0a4bde85bfebc5d30ab063fbd7972 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Wed, 4 Feb 2015 11:44:24 +0530 Subject: [PATCH 4/4] actual start and end date made blank if islocal --- .../doctype/production_order/production_order.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/erpnext/manufacturing/doctype/production_order/production_order.js b/erpnext/manufacturing/doctype/production_order/production_order.js index d7dc79a953..f7ebaa95d9 100644 --- a/erpnext/manufacturing/doctype/production_order/production_order.js +++ b/erpnext/manufacturing/doctype/production_order/production_order.js @@ -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() {