Merge pull request #1828 from rmehta/develop

item query fix
diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py
index 789e7a3..0f1d5f6 100644
--- a/erpnext/controllers/queries.py
+++ b/erpnext/controllers/queries.py
@@ -141,7 +141,7 @@
 			concat(substr(tabItem.description, 1, 40), "..."), description) as decription
 		from tabItem
 		where tabItem.docstatus < 2
-			and (tabItem.end_of_life is null or tabItem.end_of_life > %(today)s)
+			and (tabItem.end_of_life > %(today)s or ifnull(tabItem.end_of_life, '0000-00-00')='0000-00-00')
 			and (tabItem.`{key}` LIKE %(txt)s
 				or tabItem.item_name LIKE %(txt)s)
 			{fcond} {mcond}
diff --git a/erpnext/manufacturing/doctype/bom/bom.js b/erpnext/manufacturing/doctype/bom/bom.js
index 1cee6b9..ef4f399 100644
--- a/erpnext/manufacturing/doctype/bom/bom.js
+++ b/erpnext/manufacturing/doctype/bom/bom.js
@@ -2,6 +2,7 @@
 // License: GNU General Public License v3. See license.txt
 
 // On REFRESH
+frappe.provide("erpnext.bom");
 cur_frm.cscript.refresh = function(doc,dt,dn){
 	cur_frm.toggle_enable("item", doc.__islocal);
 
@@ -10,7 +11,7 @@
 	}
 
 	cur_frm.cscript.with_operations(doc);
-	set_operation_no(doc);
+	erpnext.bom.set_operation_no(doc);
 }
 
 cur_frm.cscript.update_cost = function() {
@@ -30,10 +31,10 @@
 
 cur_frm.cscript.operation_no = function(doc, cdt, cdn) {
 	var child = locals[cdt][cdn];
-	if(child.parentfield=="bom_operations") set_operation_no(doc);
+	if(child.parentfield=="bom_operations") erpnext.bom.set_operation_no(doc);
 }
 
-var set_operation_no = function(doc) {
+erpnext.bom.set_operation_no = function(doc) {
 	var op_table = doc.bom_operations || [];
 	var operations = [];
 
@@ -53,7 +54,7 @@
 }
 
 cur_frm.fields_dict["bom_operations"].grid.on_row_delete = function(cdt, cdn){
-	set_operation_no(doc);
+	erpnext.bom.set_operation_no(doc);
 }
 
 cur_frm.add_fetch("item", "description", "description");
@@ -64,15 +65,15 @@
 	frappe.model.with_doc("Workstation", d.workstation, function(i, r) {
 		d.hour_rate = r.docs[0].hour_rate;
 		refresh_field("hour_rate", dn, "bom_operations");
-		calculate_op_cost(doc);
-		calculate_total(doc);
+		erpnext.bom.calculate_op_cost(doc);
+		erpnext.bom.calculate_total(doc);
 	});
 }
 
 
 cur_frm.cscript.hour_rate = function(doc, dt, dn) {
-	calculate_op_cost(doc);
-	calculate_total(doc);
+	erpnext.bom.calculate_op_cost(doc);
+	erpnext.bom.calculate_total(doc);
 }
 
 
@@ -106,8 +107,8 @@
 				$.extend(d, r.message);
 				refresh_field("bom_materials");
 				doc = locals[doc.doctype][doc.name];
-				calculate_rm_cost(doc);
-				calculate_total(doc);
+				erpnext.bom.calculate_rm_cost(doc);
+				erpnext.bom.calculate_total(doc);
 			},
 			freeze: true
 		});
@@ -116,8 +117,8 @@
 
 
 cur_frm.cscript.qty = function(doc, cdt, cdn) {
-	calculate_rm_cost(doc);
-	calculate_total(doc);
+	erpnext.bom.calculate_rm_cost(doc);
+	erpnext.bom.calculate_total(doc);
 }
 
 cur_frm.cscript.rate = function(doc, cdt, cdn) {
@@ -126,12 +127,12 @@
 		msgprint(__("You can not change rate if BOM mentioned agianst any item"));
 		get_bom_material_detail(doc, cdt, cdn);
 	} else {
-		calculate_rm_cost(doc);
-		calculate_total(doc);
+		erpnext.bom.calculate_rm_cost(doc);
+		erpnext.bom.calculate_total(doc);
 	}
 }
 
-var calculate_op_cost = function(doc) {
+erpnext.bom.calculate_op_cost = function(doc) {
 	var op = doc.bom_operations || [];
 	total_op_cost = 0;
 	for(var i=0;i<op.length;i++) {
@@ -143,7 +144,7 @@
 	refresh_field('operating_cost');
 }
 
-var calculate_rm_cost = function(doc) {
+erpnext.bom.calculate_rm_cost = function(doc) {
 	var rm = doc.bom_materials || [];
 	total_rm_cost = 0;
 	for(var i=0;i<rm.length;i++) {
@@ -159,7 +160,7 @@
 
 
 // Calculate Total Cost
-var calculate_total = function(doc) {
+erpnext.bom.calculate_total = function(doc) {
 	doc.total_cost = flt(doc.raw_material_cost) + flt(doc.operating_cost);
 	refresh_field('total_cost');
 }
@@ -200,7 +201,7 @@
 }
 
 cur_frm.cscript.validate = function(doc, dt, dn) {
-	calculate_op_cost(doc);
-	calculate_rm_cost(doc);
-	calculate_total(doc);
+	erpnext.bom.calculate_op_cost(doc);
+	erpnext.bom.calculate_rm_cost(doc);
+	erpnext.bom.calculate_total(doc);
 }