Merge pull request #10771 from nabinhait/pro_order_99
Update actual dates in Production Order from Timesheet
diff --git a/erpnext/manufacturing/doctype/production_order/production_order.py b/erpnext/manufacturing/doctype/production_order/production_order.py
index 5fedc72..5bd476e 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order.py
+++ b/erpnext/manufacturing/doctype/production_order/production_order.py
@@ -367,15 +367,11 @@
frappe.throw(_("Completed Qty can not be greater than 'Qty to Manufacture'"))
def set_actual_dates(self):
+ self.actual_start_date = None
+ self.actual_end_date = None
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
+ self.actual_start_date = min([d.actual_start_time for d in self.get("operations")])
+ self.actual_end_date = max([d.actual_end_time for d in self.get("operations")])
def delete_timesheet(self):
for timesheet in frappe.get_all("Timesheet", ["name"], {"production_order": self.name}):