Merge pull request #2679 from neilLasrado/time-log-fix

Time log fix
diff --git a/erpnext/manufacturing/doctype/production_order/production_order.py b/erpnext/manufacturing/doctype/production_order/production_order.py
index 396ec98..a962248 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order.py
+++ b/erpnext/manufacturing/doctype/production_order/production_order.py
@@ -291,6 +291,7 @@
 	time_log.project = project
 	time_log.operation= operation
 	time_log.workstation= workstation
+	time_log.activity_type= "Manufacturing"
 	time_log.completed_qty = flt(qty)
 	if from_time and to_time :
 		time_log.calculate_total_hours()
diff --git a/erpnext/projects/doctype/time_log/time_log.js b/erpnext/projects/doctype/time_log/time_log.js
index 9a53836..3e28e70 100644
--- a/erpnext/projects/doctype/time_log/time_log.js
+++ b/erpnext/projects/doctype/time_log/time_log.js
@@ -10,13 +10,6 @@
 	}
 });
 
-frappe.ui.form.on("Time Log", "refresh", function(frm) {
-	var is_manufacturing = frm.doc.time_log_for=="Manufacturing" ? true : false;
-	frm.toggle_reqd("production_order", is_manufacturing);
-	frm.toggle_reqd("operation", is_manufacturing);
-	frm.toggle_reqd("completed_qty", is_manufacturing);
-});
-
 // set to time if hours is updated
 frappe.ui.form.on("Time Log", "hours", function(frm) {
 	if(!frm.doc.from_time) {
@@ -75,5 +68,11 @@
 				}
 			}
 		});
+	},
+	
+	time_log_for: function(doc) {
+		if (doc.time_log_for == 'Manufacturing') {
+			cur_frm.set_value("activity_type", "Manufacturing")
+		}
 	}
 });
diff --git a/erpnext/projects/doctype/time_log/time_log.json b/erpnext/projects/doctype/time_log/time_log.json
index e60e75e..9dc2d59 100644
--- a/erpnext/projects/doctype/time_log/time_log.json
+++ b/erpnext/projects/doctype/time_log/time_log.json
@@ -68,7 +68,7 @@
    "reqd": 0
   }, 
   {
-   "depends_on": "eval:doc.time_log_for != 'Manufacturing'", 
+   "depends_on": "", 
    "fieldname": "activity_type", 
    "fieldtype": "Link", 
    "in_list_view": 0, 
diff --git a/erpnext/projects/doctype/time_log/time_log.py b/erpnext/projects/doctype/time_log/time_log.py
index f4cb89e..a7401b4 100644
--- a/erpnext/projects/doctype/time_log/time_log.py
+++ b/erpnext/projects/doctype/time_log/time_log.py
@@ -23,6 +23,8 @@
 		self.validate_time_log_for()
 		self.check_workstation_timings()
 		self.validate_production_order()
+		self.validate_project()
+		self.validate_manufacturing()
 
 	def on_submit(self):
 		self.update_production_order()
@@ -127,6 +129,26 @@
 			from `tabTime Log`
 			where production_order = %s and operation = %s and docstatus=1""",
 			(self.production_order, self.operation), as_dict=1)[0]
+			
+	def validate_project(self):
+		if self.time_log_for == 'Project':
+			if not self.project:
+				frappe.throw(_("Project is Mandatory."))
+		if self.time_log_for == "":
+			self.project = None			
+		
+	def validate_manufacturing(self):
+		if self.time_log_for == 'Manufacturing':
+			if not self.production_order:
+				frappe.throw(_("Production Order is Mandatory"))
+			if not self.operation:
+				frappe.throw(_("Operation is Mandatory"))
+			if not self.completed_qty:
+				self.completed_qty=0
+		else:
+			self.production_order = None
+			self.operation = None
+			self.quantity = None
 
 @frappe.whitelist()
 def get_workstation(production_order, operation):
@@ -164,7 +186,7 @@
 
 	data = frappe.db.sql("""select name, from_time, to_time,
 		activity_type, task, project, production_order, workstation from `tabTime Log`
-		where ( from_time between %(start)s and %(end)s or to_time between %(start)s and %(end)s )
+		where docstatus < 2 and ( from_time between %(start)s and %(end)s or to_time between %(start)s and %(end)s )
 		{conditions}""".format(conditions=conditions), {
 			"start": start,
 			"end": end
diff --git a/erpnext/setup/page/setup_wizard/install_fixtures.py b/erpnext/setup/page/setup_wizard/install_fixtures.py
index 5312192..f83ab35 100644
--- a/erpnext/setup/page/setup_wizard/install_fixtures.py
+++ b/erpnext/setup/page/setup_wizard/install_fixtures.py
@@ -135,7 +135,8 @@
 		{'doctype': 'Activity Type', 'activity_type': _('Proposal Writing')},
 		{'doctype': 'Activity Type', 'activity_type': _('Execution')},
 		{'doctype': 'Activity Type', 'activity_type': _('Communication')},
-
+		{'doctype': 'Activity Type', 'activity_type': _('Manufacturing')},
+		
 		# Industry Type
 		{'doctype': 'Industry Type', 'industry': _('Accounting')},
 		{'doctype': 'Industry Type', 'industry': _('Advertising')},