bom cleanup
diff --git a/manufacturing/doctype/bom/bom.js b/manufacturing/doctype/bom/bom.js
index 7cd6e06..6d049bd 100644
--- a/manufacturing/doctype/bom/bom.js
+++ b/manufacturing/doctype/bom/bom.js
@@ -17,9 +17,40 @@
 // On REFRESH
 cur_frm.cscript.refresh = function(doc,dt,dn){
 	cur_frm.toggle_enable("item", doc.__islocal);
+	
 	if (!doc.__islocal && doc.docstatus==0) {
 		cur_frm.set_intro("Submit the BOM to use it in production");
 	} else cur_frm.set_intro("");
+	
+	cur_frm.cscript.track_operations(doc);
+	set_operation_no(doc);
+}
+
+cur_frm.cscript.track_operations = function(doc) {
+	cur_frm.fields_dict["bom_materials"].grid.set_column_disp("operation_no", doc.track_operations);
+	cur_frm.fields_dict["bom_materials"].grid.toggle_reqd("operation_no", doc.track_operations)
+}
+
+cur_frm.cscript.operation_no = function(doc, cdt, cdn) {
+	var child = locals[cdt][cdn];
+	if(child.parentfield=="bom_operations") set_operation_no(doc);
+}
+
+var set_operation_no = function(doc) {
+	var op_table = getchildren('BOM Operation', doc.name, 'bom_operations');
+	var operations = [];
+
+	for (var i=0, j=op_table.length; i<j; i++) {
+		var op = op_table[i].operation_no;
+		if (op && !inList(operations, op)) operations.push(op);
+	}
+	cur_frm.fields_dict["bom_materials"].grid.get_field("operation_no")
+		.df.options = operations.join("\n");
+	refresh_field("bom_materials");
+}
+
+cur_frm.fields_dict["bom_operations"].grid.on_row_delete = function(cdt, cdn){
+	set_operation_no(doc);
 }
 
 cur_frm.cscript.item = function(doc, dt, dn) {
@@ -28,7 +59,6 @@
 	}
 }
 
-
 cur_frm.cscript.workstation = function(doc,dt,dn) {
 	var d = locals[dt][dn];
 	if (d.workstation) {
@@ -167,11 +197,11 @@
 cur_frm.fields_dict['bom_materials'].grid.get_field('bom_no').get_query = function(doc, cdt, cdn) {
 	var d = locals[cdt][cdn];
 	msgprint('SELECT DISTINCT `tabBOM`.`name`, `tabBOM`.`remarks` FROM `tabBOM` \
-		WHERE `tabBOM`.`item` = "' + d.item_code + '" AND `tabBOM`.`is_active` = "Yes" AND \
+		WHERE `tabBOM`.`item` = "' + d.item_code + '" AND `tabBOM`.`is_active` = 1 AND \
 		 	`tabBOM`.docstatus = 1 AND `tabBOM`.`name` like "%s" \
 		ORDER BY `tabBOM`.`name` LIMIT 50');
 	return 'SELECT DISTINCT `tabBOM`.`name`, `tabBOM`.`remarks` FROM `tabBOM` \
-		WHERE `tabBOM`.`item` = "' + d.item_code + '" AND `tabBOM`.`is_active` = "Yes" AND \
+		WHERE `tabBOM`.`item` = "' + d.item_code + '" AND `tabBOM`.`is_active` = 1 AND \
 		 	`tabBOM`.docstatus = 1 AND `tabBOM`.`name` like "%s" \
 		ORDER BY `tabBOM`.`name` LIMIT 50';
 }
diff --git a/manufacturing/doctype/bom/bom.py b/manufacturing/doctype/bom/bom.py
index 7345569..99c72e1 100644
--- a/manufacturing/doctype/bom/bom.py
+++ b/manufacturing/doctype/bom/bom.py
@@ -108,7 +108,7 @@
 
 	def get_bom_unitcost(self, bom_no):
 		bom = sql("""select name, total_cost/quantity as unit_cost from `tabBOM`
-			where is_active = 'Yes' and name = %s""", bom_no, as_dict=1)
+			where is_active = 1 and name = %s""", bom_no, as_dict=1)
 		return bom and bom[0]['unit_cost'] or 0
 
 	def get_valuation_rate(self, arg):
@@ -134,7 +134,7 @@
 			update default bom in item master
 		"""
 
-		if self.doc.is_default and self.doc.is_active == 'Yes':
+		if self.doc.is_default and self.doc.is_active:
 			sql("update `tabBOM` set is_default = 0 where name != %s and item=%s", 
 				(self.doc.name, self.doc.item))
 
@@ -178,7 +178,7 @@
 		check_list = []
 		for m in getlist(self.doclist, 'bom_materials'):
 			# check if operation no not in op table
-			if cstr(m.operation_no) not in self.op:
+			if self.doc.track_operations and cstr(m.operation_no) not in self.op:
 				msgprint("""Operation no: %s against item: %s at row no: %s \
 					is not present at Operations table""" % 
 					(m.operation_no, m.item_code, m.idx), raise_exception = 1)
@@ -207,7 +207,7 @@
 	def validate_bom_no(self, item, bom_no, idx):
 		"""Validate BOM No of sub-contracted items"""
 		bom = sql("""select name from `tabBOM` where name = %s and item = %s 
-			and ifnull(is_active, 'No') = 'Yes'	and docstatus < 2 """, 
+			and is_active = 1 and docstatus < 2 """, 
 			(bom_no, item), as_dict =1)
 		if not bom:
 			msgprint("""Incorrect BOM No: %s against item: %s at row no: %s.
@@ -374,12 +374,12 @@
 		# check if used in any other bom
 		par = sql("""select t1.parent from `tabBOM Item` t1, `tabBOM` t2 
 			where t1.parent = t2.name and t1.bom_no = %s and t1.docstatus = 1 
-			and t2.is_active = 'Yes'""", self.doc.name)
+			and t2.is_active = 1""", self.doc.name)
 		if par:
 			msgprint("""BOM can not be cancelled, as it is a child item \
 				in following active BOM %s""" % [d[0] for d in par], raise_exception=1)
 			
-		webnotes.conn.set(self.doc, "is_active", "No")
+		webnotes.conn.set(self.doc, "is_active", 0)
 		webnotes.conn.set(self.doc, "is_default", 0)
 		self.manage_default_bom()
 		self.update_cost_and_exploded_items(calculate_cost=False)
@@ -391,9 +391,9 @@
 	
 	
 	def validate_inactive_bom(self):
-		if self.doc.is_active == 'No':
+		if not self.doc.is_active:
 			act_pbom = sql("""select distinct t1.parent from `tabBOM Item` t1, `tabBOM` t2 
-				where t1.bom_no =%s and t2.name = t1.parent and t2.is_active = 'Yes' 
+				where t1.bom_no =%s and t2.name = t1.parent and t2.is_active = 1 
 				and t2.docstatus = 1 and t1.docstatus =1 """, self.doc.name)
 			if act_pbom and act_pbom[0][0]:
 				msgprint("""Sorry cannot inactivate as BOM: %s is child 
diff --git a/manufacturing/doctype/bom/bom.txt b/manufacturing/doctype/bom/bom.txt
index 39f0f84..d0993c4 100644
--- a/manufacturing/doctype/bom/bom.txt
+++ b/manufacturing/doctype/bom/bom.txt
@@ -2,9 +2,9 @@
  {
   "owner": "Administrator", 
   "docstatus": 0, 
-  "creation": "2012-12-12 10:17:41", 
+  "creation": "2012-12-14 10:15:15", 
   "modified_by": "Administrator", 
-  "modified": "2012-12-13 11:48:39"
+  "modified": "2012-12-14 13:40:48"
  }, 
  {
   "istable": 0, 
@@ -45,14 +45,6 @@
   "doctype": "DocType"
  }, 
  {
-  "oldfieldtype": "Column Break", 
-  "doctype": "DocField", 
-  "width": "50%", 
-  "fieldname": "column_break0", 
-  "fieldtype": "Column Break", 
-  "permlevel": 0
- }, 
- {
   "description": "Select the item code for which Bill of Material is being created", 
   "oldfieldtype": "Link", 
   "doctype": "DocField", 
@@ -67,55 +59,15 @@
   "options": "Item"
  }, 
  {
-  "description": "Total quantity of items for which raw materials required and operations done will be defined", 
-  "default": "1", 
-  "oldfieldtype": "Currency", 
   "doctype": "DocField", 
-  "label": "Quantity", 
-  "oldfieldname": "quantity", 
-  "fieldname": "quantity", 
-  "fieldtype": "Currency", 
-  "reqd": 1, 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "label": "Item UOM", 
-  "options": "link:UOM", 
-  "fieldname": "uom", 
-  "fieldtype": "Select", 
-  "permlevel": 1
- }, 
- {
-  "doctype": "DocField", 
-  "width": "50%", 
-  "fieldname": "column_break1", 
+  "fieldname": "cb0", 
   "fieldtype": "Column Break", 
   "permlevel": 0
  }, 
  {
-  "permlevel": 0, 
-  "no_copy": 1, 
-  "oldfieldtype": "Select", 
-  "allow_on_submit": 1, 
   "doctype": "DocField", 
-  "label": "Is Active", 
-  "oldfieldname": "is_active", 
-  "default": "Yes", 
-  "fieldname": "is_active", 
-  "fieldtype": "Select", 
-  "reqd": 1, 
-  "hidden": 0, 
-  "options": "\nYes\nNo"
- }, 
- {
-  "no_copy": 1, 
-  "oldfieldtype": "Check", 
-  "allow_on_submit": 1, 
-  "doctype": "DocField", 
-  "label": "Is Default", 
-  "oldfieldname": "is_default", 
-  "fieldname": "is_default", 
+  "label": "Track Operations", 
+  "fieldname": "track_operations", 
   "fieldtype": "Check", 
   "permlevel": 0
  }, 
@@ -123,12 +75,13 @@
   "oldfieldtype": "Section Break", 
   "doctype": "DocField", 
   "label": "Operations", 
+  "options": "Specify the operations, operating cost and give a unique Operation no to your operations.", 
   "fieldname": "operations", 
   "fieldtype": "Section Break", 
+  "depends_on": "track_operations", 
   "permlevel": 0
  }, 
  {
-  "description": "Specify the operations, operating cost and give a unique Operation no to your operations.", 
   "oldfieldtype": "Table", 
   "doctype": "DocField", 
   "label": "BOM Operations", 
@@ -147,14 +100,6 @@
   "permlevel": 0
  }, 
  {
-  "doctype": "DocField", 
-  "label": "Consider Raw Material Cost As Per", 
-  "options": "Valuation Rate\nLast Purchase Rate\nStandard Rate", 
-  "fieldname": "rm_cost_as_per", 
-  "fieldtype": "Select", 
-  "permlevel": 0
- }, 
- {
   "description": "Enter the raw materials required to manufacture the BOM item. Specify the operation no as entered in the previous tab which will be performed on the raw materials entered.", 
   "oldfieldtype": "Table", 
   "doctype": "DocField", 
@@ -175,6 +120,27 @@
  }, 
  {
   "doctype": "DocField", 
+  "label": "Consider Raw Material Cost As Per", 
+  "options": "Valuation Rate\nLast Purchase Rate", 
+  "fieldname": "rm_cost_as_per", 
+  "fieldtype": "Select", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Total Cost", 
+  "fieldname": "total_cost", 
+  "fieldtype": "Float", 
+  "permlevel": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "cb1", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
   "label": "Raw Material Cost", 
   "fieldname": "raw_material_cost", 
   "fieldtype": "Float", 
@@ -189,16 +155,35 @@
  }, 
  {
   "doctype": "DocField", 
-  "label": "Total Cost", 
-  "fieldname": "total_cost", 
-  "fieldtype": "Float", 
+  "label": "More Info", 
+  "fieldname": "more_info_section", 
+  "fieldtype": "Section Break", 
+  "permlevel": 0
+ }, 
+ {
+  "description": "Total quantity of items for which raw materials required and operations done will be defined", 
+  "default": "1", 
+  "oldfieldtype": "Currency", 
+  "doctype": "DocField", 
+  "label": "Quantity", 
+  "oldfieldname": "quantity", 
+  "fieldname": "quantity", 
+  "fieldtype": "Currency", 
+  "reqd": 1, 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Item UOM", 
+  "options": "link:UOM", 
+  "fieldname": "uom", 
+  "fieldtype": "Select", 
   "permlevel": 1
  }, 
  {
   "doctype": "DocField", 
-  "label": "More Info", 
-  "fieldname": "more_info_section", 
-  "fieldtype": "Section Break", 
+  "fieldname": "col_break23", 
+  "fieldtype": "Column Break", 
   "permlevel": 0
  }, 
  {
@@ -214,18 +199,28 @@
   "in_filter": 1
  }, 
  {
-  "oldfieldtype": "Data", 
+  "no_copy": 1, 
+  "oldfieldtype": "Select", 
+  "allow_on_submit": 1, 
   "doctype": "DocField", 
-  "label": "Maintained By", 
-  "oldfieldname": "maintained_by", 
-  "fieldname": "maintained_by", 
-  "fieldtype": "Data", 
+  "label": "Is Active", 
+  "oldfieldname": "is_active", 
+  "default": "1", 
+  "fieldname": "is_active", 
+  "fieldtype": "Check", 
+  "reqd": 1, 
+  "hidden": 0, 
   "permlevel": 0
  }, 
  {
+  "no_copy": 1, 
+  "oldfieldtype": "Check", 
+  "allow_on_submit": 1, 
   "doctype": "DocField", 
-  "fieldname": "col_break23", 
-  "fieldtype": "Column Break", 
+  "label": "Is Default", 
+  "oldfieldname": "is_default", 
+  "fieldname": "is_default", 
+  "fieldtype": "Check", 
   "permlevel": 0
  }, 
  {
@@ -239,27 +234,6 @@
   "permlevel": 1
  }, 
  {
-  "print_hide": 1, 
-  "description": "The date at which current entry is corrected in the system.", 
-  "no_copy": 1, 
-  "depends_on": "eval:doc.amended_from", 
-  "doctype": "DocField", 
-  "label": "Amendment Date", 
-  "fieldname": "amendment_date", 
-  "fieldtype": "Date", 
-  "permlevel": 0
- }, 
- {
-  "no_copy": 1, 
-  "oldfieldtype": "Text", 
-  "doctype": "DocField", 
-  "label": "Remarks", 
-  "oldfieldname": "remarks", 
-  "fieldname": "remarks", 
-  "fieldtype": "Small Text", 
-  "permlevel": 0
- }, 
- {
   "print_hide": 0, 
   "depends_on": "eval:!doc.__islocal", 
   "doctype": "DocField", 
@@ -285,6 +259,17 @@
   "options": "BOM Explosion Item"
  }, 
  {
+  "print_hide": 1, 
+  "description": "The date at which current entry is corrected in the system.", 
+  "no_copy": 1, 
+  "depends_on": "eval:doc.amended_from", 
+  "doctype": "DocField", 
+  "label": "Amendment Date", 
+  "fieldname": "amendment_date", 
+  "fieldtype": "Date", 
+  "permlevel": 0
+ }, 
+ {
   "create": 1, 
   "doctype": "DocPerm", 
   "submit": 1, 
diff --git a/manufacturing/doctype/bom/bom_list.js b/manufacturing/doctype/bom/bom_list.js
index 2aae904..8e355f3 100644
--- a/manufacturing/doctype/bom/bom_list.js
+++ b/manufacturing/doctype/bom/bom_list.js
@@ -17,7 +17,7 @@
 	prepare_data: function(data) {
 		this._super(data);
 		data.costing_date = wn.datetime.str_to_user(data.costing_date);
-		data.description = (data.is_active === 'Yes' ? '' : '[Inactive] ') + data.description;
+		data.description = (data.is_active ? '' : '[Inactive] ') + data.description;
 	},
 
 	columns: [
diff --git a/manufacturing/doctype/bom_item/bom_item.txt b/manufacturing/doctype/bom_item/bom_item.txt
index d5a9943..7c97e8d 100644
--- a/manufacturing/doctype/bom_item/bom_item.txt
+++ b/manufacturing/doctype/bom_item/bom_item.txt
@@ -2,20 +2,15 @@
  {
   "owner": "Administrator", 
   "docstatus": 0, 
-  "creation": "2012-03-27 14:36:02", 
+  "creation": "2012-12-14 10:15:16", 
   "modified_by": "Administrator", 
-  "modified": "2012-12-10 18:30:00"
+  "modified": "2012-12-14 13:11:49"
  }, 
  {
-  "section_style": "Simple", 
   "istable": 1, 
   "name": "__common__", 
-  "colour": "White:FFF", 
-  "module": "Manufacturing", 
-  "show_in_menu": 0, 
-  "version": 27, 
-  "server_code_error": " ", 
-  "doctype": "DocType"
+  "doctype": "DocType", 
+  "module": "Manufacturing"
  }, 
  {
   "name": "__common__", 
@@ -38,35 +33,25 @@
   "doctype": "DocType"
  }, 
  {
-  "write": 1, 
-  "permlevel": 0, 
-  "doctype": "DocPerm"
- }, 
- {
-  "permlevel": 1, 
-  "doctype": "DocPerm"
- }, 
- {
   "oldfieldtype": "Data", 
   "doctype": "DocField", 
   "label": "Operation No", 
   "oldfieldname": "operation_no", 
   "fieldname": "operation_no", 
-  "fieldtype": "Data", 
-  "reqd": 1, 
+  "fieldtype": "Select", 
+  "reqd": 0, 
   "permlevel": 0
  }, 
  {
-  "search_index": 1, 
+  "oldfieldtype": "Link", 
   "doctype": "DocField", 
   "label": "Item Code", 
   "oldfieldname": "item_code", 
-  "trigger": "Client", 
+  "options": "Item", 
   "fieldname": "item_code", 
   "fieldtype": "Link", 
-  "oldfieldtype": "Link", 
+  "search_index": 1, 
   "reqd": 1, 
-  "options": "Item", 
   "permlevel": 0, 
   "in_filter": 1
  }, 
@@ -77,7 +62,6 @@
   "label": "BOM No", 
   "oldfieldname": "bom_no", 
   "width": "150px", 
-  "trigger": "Client", 
   "fieldname": "bom_no", 
   "fieldtype": "Link", 
   "search_index": 1, 
@@ -90,7 +74,6 @@
   "doctype": "DocField", 
   "label": "Qty", 
   "oldfieldname": "qty", 
-  "trigger": "Client", 
   "fieldname": "qty", 
   "fieldtype": "Float", 
   "reqd": 1, 
@@ -154,5 +137,14 @@
   "fieldtype": "Float", 
   "hidden": 1, 
   "permlevel": 1
+ }, 
+ {
+  "write": 1, 
+  "doctype": "DocPerm", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocPerm", 
+  "permlevel": 1
  }
 ]
\ No newline at end of file
diff --git a/manufacturing/doctype/production_order/production_order.js b/manufacturing/doctype/production_order/production_order.js
index ea8dd5b..d36c548 100644
--- a/manufacturing/doctype/production_order/production_order.js
+++ b/manufacturing/doctype/production_order/production_order.js
@@ -102,8 +102,7 @@
 }
 
 cur_frm.cscript.make_se = function(doc, process) {
-	var se = LocalDB.create('Stock Entry');
-	se = locals['Stock Entry'][se];
+	var se = wn.model.get_new_doc("Stock Entry");
 	se.purpose = 'Production Order';
 	se.process = process;
 	se.production_order = doc.name;
diff --git a/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/manufacturing/doctype/production_planning_tool/production_planning_tool.py
index 76bf84b..d58a1a9 100644
--- a/manufacturing/doctype/production_planning_tool/production_planning_tool.py
+++ b/manufacturing/doctype/production_planning_tool/production_planning_tool.py
@@ -173,7 +173,7 @@
 				(d.item_code, d.idx), raise_exception=1)
 		else:
 			bom = sql("""select name from `tabBOM` where name = %s and item = %s 
-				and docstatus = 1 and ifnull(is_active, 'No') = 'Yes'""", 
+				and docstatus = 1 and is_active = 1""", 
 				(d.bom_no, d.item_code), as_dict = 1)
 			if not bom:
 				msgprint("""Incorrect BOM No: %s entered for item: %s at row no: %s
diff --git a/manufacturing/doctype/production_planning_tool/production_planning_tool.txt b/manufacturing/doctype/production_planning_tool/production_planning_tool.txt
index 6e750a8..dd7acfd 100644
--- a/manufacturing/doctype/production_planning_tool/production_planning_tool.txt
+++ b/manufacturing/doctype/production_planning_tool/production_planning_tool.txt
@@ -2,9 +2,9 @@
  {
   "owner": "jai@webnotestech.com", 
   "docstatus": 0, 
-  "creation": "2012-12-11 15:15:06", 
+  "creation": "2012-12-14 10:15:16", 
   "modified_by": "Administrator", 
-  "modified": "2012-12-11 16:13:59"
+  "modified": "2012-12-14 11:37:40"
  }, 
  {
   "read_only": 1, 
@@ -149,15 +149,6 @@
   "options": "clear_item_table"
  }, 
  {
-  "description": "If checked, BOM for sub-assembly items will be considered for getting raw materials. Otherwise, all sub-assembly items will be treated as a raw material.", 
-  "default": "1", 
-  "doctype": "DocField", 
-  "label": "Use Multi-Level BOM", 
-  "fieldname": "use_multi_level_bom", 
-  "fieldtype": "Check", 
-  "reqd": 0
- }, 
- {
   "doctype": "DocField", 
   "fieldname": "section_break3", 
   "fieldtype": "Section Break", 
@@ -184,6 +175,15 @@
   "fieldtype": "Column Break"
  }, 
  {
+  "description": "If checked, BOM for sub-assembly items will be considered for getting raw materials. Otherwise, all sub-assembly items will be treated as a raw material.", 
+  "default": "1", 
+  "doctype": "DocField", 
+  "label": "Use Multi-Level BOM", 
+  "fieldname": "use_multi_level_bom", 
+  "fieldtype": "Check", 
+  "reqd": 0
+ }, 
+ {
   "description": "Download a report containing all raw materials with their latest inventory status", 
   "doctype": "DocField", 
   "label": "Download Materials Required", 
diff --git a/patches/december_2012/production_cleanup.py b/patches/december_2012/production_cleanup.py
index cb78bd1..5efb43f 100644
--- a/patches/december_2012/production_cleanup.py
+++ b/patches/december_2012/production_cleanup.py
@@ -4,12 +4,14 @@
 	delete_doctypes()
 	rename_module()
 	rebuilt_exploded_bom()
+	cleanup_bom()
 	
 def delete_doctypes():
 	from webnotes.model import delete_doc
 	delete_doc("DocType", "Production Control")
 	delete_doc("DocType", "BOM Control")
 	
+	
 def rename_module():
 	webnotes.reload_doc("core", "doctype", "role")
 	webnotes.reload_doc("core", "doctype", "page")
@@ -38,3 +40,8 @@
 	from webnotes.model.code import get_obj
 	for bom in webnotes.conn.sql("""select name from `tabBOM` where docstatus < 2"""):
 		get_obj("BOM", bom[0], with_children=1).on_update()
+
+def cleanup_bom():
+	webnotes.conn.sql("""UPDATE `tabBOM` SET is_active = if(is_active='Yes', 1, 0), 
+		track_operations = 1""")
+	
\ No newline at end of file
diff --git a/patches/november_2012/cancelled_bom_patch.py b/patches/november_2012/cancelled_bom_patch.py
index 3420a08..761227d 100644
--- a/patches/november_2012/cancelled_bom_patch.py
+++ b/patches/november_2012/cancelled_bom_patch.py
@@ -5,7 +5,7 @@
 		where docstatus = 2""")
 	
 	for bom in cancelled_boms:
-		webnotes.conn.sql("""update `tabBOM` set is_default=0, is_active='No'
+		webnotes.conn.sql("""update `tabBOM` set is_default=0, is_active=0
 			where name=%s""", (bom[0],))
 		
 		webnotes.conn.sql("""update `tabItem` set default_bom=null
diff --git a/public/js/utils.js b/public/js/utils.js
index 599232d..4a88cd8 100644
--- a/public/js/utils.js
+++ b/public/js/utils.js
@@ -119,7 +119,7 @@
 	return 'SELECT tabBOM.name, tabBOM.item \
 		FROM tabBOM \
 		WHERE tabBOM.docstatus=1 \
-		AND tabBOM.is_active="Yes" \
+		AND tabBOM.is_active=1 \
 		AND tabBOM.%(key)s LIKE "%s" ' + (conditions.length 
 			? (" AND " + conditions.join(" AND "))
 			: "")
diff --git a/stock/doctype/item/item.js b/stock/doctype/item/item.js
index ca64d59..376cf54 100644
--- a/stock/doctype/item/item.js
+++ b/stock/doctype/item/item.js
@@ -52,7 +52,7 @@
 
 cur_frm.fields_dict['default_bom'].get_query = function(doc) {
    //var d = locals[this.doctype][this.docname];
-   return 'SELECT DISTINCT `tabBOM`.`name` FROM `tabBOM` WHERE `tabBOM`.`item` = "' + doc.item_code + '"  AND `tabBOM`.`is_active` = "No" and `tabBOM`.docstatus != 2 AND `tabBOM`.%(key)s LIKE "%s" ORDER BY `tabBOM`.`name` LIMIT 50'
+   return 'SELECT DISTINCT `tabBOM`.`name` FROM `tabBOM` WHERE `tabBOM`.`item` = "' + doc.item_code + '"  AND ifnull(`tabBOM`.`is_active`, 0) = 0 and `tabBOM`.docstatus != 2 AND `tabBOM`.%(key)s LIKE "%s" ORDER BY `tabBOM`.`name` LIMIT 50'
 }
 
 
diff --git a/stock/doctype/purchase_receipt/purchase_receipt.py b/stock/doctype/purchase_receipt/purchase_receipt.py
index 9e23c27..4683abb 100644
--- a/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -375,7 +375,11 @@
 
 	def add_bom(self, d):
 		#----- fetching default bom from Bill of Materials instead of Item Master --
-		bom_det = sql("select t1.item, t2.item_code, t2.qty_consumed_per_unit, t2.moving_avg_rate, t2.value_as_per_mar, t2.stock_uom, t2.name, t2.description from `tabBOM` t1, `tabBOM Item` t2 where t2.parent = t1.name and t1.item = '%s' and ifnull(t1.is_default,0) = 1 and t1.docstatus = 1 and t2.docstatus =1" % d.item_code)
+		bom_det = sql("""select t1.item, t2.item_code, t2.qty_consumed_per_unit, 
+			t2.moving_avg_rate, t2.value_as_per_mar, t2.stock_uom, t2.name, t2.description 
+			from `tabBOM` t1, `tabBOM Item` t2 
+			where t2.parent = t1.name and t1.item = %s and t1.is_default = 1 
+			and t1.docstatus = 1 and t2.docstatus =1 and t1.is_active = 1""", d.item_code)
 		if not bom_det:
 			msgprint("No default BOM exists for item: %s" % d.item_code)
 			raise Exception
diff --git a/stock/doctype/stock_entry/stock_entry.py b/stock/doctype/stock_entry/stock_entry.py
index 574c24e..45dcb80 100644
--- a/stock/doctype/stock_entry/stock_entry.py
+++ b/stock/doctype/stock_entry/stock_entry.py
@@ -214,7 +214,7 @@
 	def validate_bom_no(self):
 		if self.doc.bom_no:
 			if not webnotes.conn.sql("""select name from tabBOM where name = %s and docstatus = 1
-			 		and ifnull(is_active, 'No') = 'Yes'""", self.doc.bom_no):
+			 		and is_active = 1""", self.doc.bom_no):
 				msgprint("""BOM: %s not found, may be it has been cancelled or inactivated""" %
 					self.doc.bom_no, raise_exception=1)
 			if not self.doc.fg_completed_qty: