diff --git a/erpnext/manufacturing/doctype/production_order/production_order.py b/erpnext/manufacturing/doctype/production_order/production_order.py index 6cd2ad2fb0..529c2a4b4b 100644 --- a/erpnext/manufacturing/doctype/production_order/production_order.py +++ b/erpnext/manufacturing/doctype/production_order/production_order.py @@ -176,18 +176,18 @@ class ProductionOrder(Document): self.set('operations', []) operations = frappe.db.sql("""select operation, description, workstation, idx, - hour_rate, time_in_mins, "Pending" as status from `tabBOM Operation` + hour_rate, time_in_mins, "Pending" as status from `tabBOM Operation` where parent = %s order by idx""", self.bom_no, as_dict=1) self.set('operations', operations) self.calculate_time() - + def calculate_time(self): bom_qty = frappe.db.get_value("BOM", self.bom_no, "quantity") - + for d in self.get("operations"): d.time_in_mins = flt(d.time_in_mins) / flt(bom_qty) * flt(self.qty) - + self.calculate_operating_cost() def get_holidays(self, workstation): @@ -220,7 +220,9 @@ class ProductionOrder(Document): 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) - 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: diff --git a/erpnext/manufacturing/doctype/workstation/workstation.py b/erpnext/manufacturing/doctype/workstation/workstation.py index bc9b190ce4..dae01df683 100644 --- a/erpnext/manufacturing/doctype/workstation/workstation.py +++ b/erpnext/manufacturing/doctype/workstation/workstation.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import frappe from frappe import _ -from frappe.utils import flt, cint, getdate, formatdate, comma_and, time_diff_in_seconds, get_datetime +from frappe.utils import flt, cint, getdate, formatdate, comma_and, time_diff_in_seconds, to_timedelta from frappe.model.document import Document from dateutil.parser import parse @@ -60,7 +60,7 @@ def is_within_operating_hours(workstation, operation, from_datetime, to_datetime workstation = frappe.get_doc("Workstation", workstation) for working_hour in workstation.working_hours: - slot_length = (get_datetime(working_hour.end_time) - get_datetime(working_hour.start_time)).total_seconds() + slot_length = (to_timedelta(working_hour.end_time or "") - to_timedelta(working_hour.start_time or "")).total_seconds() if slot_length >= operation_length: return