refactored communication and added to Lead / Contact
diff --git a/accounts/doctype/mis_control/mis_control.py b/accounts/doctype/mis_control/mis_control.py
index 2810067..b1c228b 100644
--- a/accounts/doctype/mis_control/mis_control.py
+++ b/accounts/doctype/mis_control/mis_control.py
@@ -248,11 +248,11 @@
 					# add rows for profit / loss in P/L
 					else:
 						if c[2]=='Debit':
-							self.return_data.append([1, 'Total Expenses (before Profit)'] + totals)
+							self.return_data.append([1, 'Total Expenses'] + totals)
 							self.return_data.append([5, 'Profit/Loss (Provisional)'] + level0_diff)
 							for i in range(len(totals)): # make totals
 								level0_diff[i] = flt(totals[i]) + level0_diff[i]
-							self.return_data.append([4, 'Total '+c[0]] + level0_diff)
+							self.return_data.append([4, 'Total Income'] + level0_diff)
 						else:
 							self.return_data.append([4, 'Total '+c[0]] + totals)
 	
diff --git a/accounts/page/financial_analytics/financial_analytics.js b/accounts/page/financial_analytics/financial_analytics.js
index 264ced3..06c8a29 100644
--- a/accounts/page/financial_analytics/financial_analytics.js
+++ b/accounts/page/financial_analytics/financial_analytics.js
@@ -23,6 +23,8 @@
 		single_column: true
 	});
 	erpnext.trial_balance = new erpnext.FinancialAnalytics(wrapper, 'Financial Analytics');
+	
+	wrapper.appframe.add_module_tab("Accounts");
 }
 
 erpnext.FinancialAnalytics = erpnext.AccountTreeGrid.extend({
diff --git a/accounts/page/general_ledger/general_ledger.js b/accounts/page/general_ledger/general_ledger.js
index c411e71..d163021 100644
--- a/accounts/page/general_ledger/general_ledger.js
+++ b/accounts/page/general_ledger/general_ledger.js
@@ -22,6 +22,8 @@
 	});
 	
 	erpnext.general_ledger = new erpnext.GeneralLedger(wrapper);
+	
+	wrapper.appframe.add_module_tab("Accounts");
 
 }
 
diff --git a/accounts/page/trial_balance/trial_balance.js b/accounts/page/trial_balance/trial_balance.js
index 698cf51..87f94ca 100644
--- a/accounts/page/trial_balance/trial_balance.js
+++ b/accounts/page/trial_balance/trial_balance.js
@@ -55,4 +55,6 @@
 		},
 	})
 	erpnext.trial_balance = new TrialBalance(wrapper, 'Trial Balance');
+	
+	wrapper.appframe.add_module_tab("Accounts");
 }
\ No newline at end of file
diff --git a/buying/doctype/purchase_order/purchase_order.js b/buying/doctype/purchase_order/purchase_order.js
index d0d878d..584648d 100644
--- a/buying/doctype/purchase_order/purchase_order.js
+++ b/buying/doctype/purchase_order/purchase_order.js
@@ -139,7 +139,7 @@
 //========================== Make Purchase Invoice =====================================================
 cur_frm.cscript['Make Purchase Invoice'] = function() {
 	n = createLocal('Purchase Invoice');
-	$c('dt_map', args={
+	$c('dt_map', {
 		'docs':compress_doclist([locals['Purchase Invoice'][n]]),
 		'from_doctype':cur_frm.doc.doctype,
 		'to_doctype':'Purchase Invoice',
diff --git a/buying/page/purchase_analytics/purchase_analytics.js b/buying/page/purchase_analytics/purchase_analytics.js
index 23db139..1e401c3 100644
--- a/buying/page/purchase_analytics/purchase_analytics.js
+++ b/buying/page/purchase_analytics/purchase_analytics.js
@@ -22,6 +22,8 @@
 	});					
 	
 	new erpnext.PurchaseAnalytics(wrapper);
+	
+	wrapper.appframe.add_module_tab("Buying");
 }
 
 erpnext.PurchaseAnalytics = wn.views.TreeGridReport.extend({
diff --git a/production/doctype/bom/bom.py b/production/doctype/bom/bom.py
index 69b6de4..913e7b6 100644
--- a/production/doctype/bom/bom.py
+++ b/production/doctype/bom/bom.py
@@ -398,3 +398,7 @@
 		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
+			
+		webnotes.conn.set(self.doc, "is_active", "No")
+		webnotes.conn.set(self.doc, "is_default", 0)
+		self.manage_default_bom()
diff --git a/public/js/communication.js b/public/js/communication.js
index ee6cce2..ca316cf 100644
--- a/public/js/communication.js
+++ b/public/js/communication.js
@@ -20,8 +20,9 @@
 		this.comm_list = [];
 		$.extend(this, opts);
 		
-		this.list.sort(function(a, b) { return new Date(a.modified) > new Date(b.modified) 
-			? -1 : 1 })
+		this.list.sort(function(a, b) { return 
+			(new Date(a.modified) > new Date(b.modified)) 
+			? -1 : 1; })
 				
 		this.make();
 	},
diff --git a/selling/doctype/sales_common/sales_common.py b/selling/doctype/sales_common/sales_common.py
index 4a24b59..2a8182d 100644
--- a/selling/doctype/sales_common/sales_common.py
+++ b/selling/doctype/sales_common/sales_common.py
@@ -717,7 +717,7 @@
 		
 		tolerance = flt(get_value('Item',item_code,'tolerance') or 0)
 
-		if not(tolerance):
+		if not tolerance:
 			if self.global_tolerance == None:
 				self.global_tolerance = flt(get_value('Global Defaults',None,'tolerance') or 0)
 			tolerance = self.global_tolerance
@@ -732,7 +732,7 @@
 	
 		# check if overflow is within tolerance
 		tolerance = self.get_tolerance_for(item['item_code'])
-		overflow_percent = ((item[args['compare_field']] - item[args['compare_ref_field']]) / item[args['compare_ref_field']] * 100)
+		overflow_percent = ((item[args['compare_field']] - item[args['compare_ref_field']]) / item[args['compare_ref_field']]) * 100
 	
 		if overflow_percent - tolerance > 0.01:
 			item['max_allowed'] = flt(item[args['compare_ref_field']] * (100+tolerance)/100)
diff --git a/selling/page/sales_analytics/sales_analytics.js b/selling/page/sales_analytics/sales_analytics.js
index b87ead5..d454d67 100644
--- a/selling/page/sales_analytics/sales_analytics.js
+++ b/selling/page/sales_analytics/sales_analytics.js
@@ -21,6 +21,8 @@
 		single_column: true
 	});
 	new erpnext.SalesAnalytics(wrapper);
+	
+	wrapper.appframe.add_module_tab("Selling");
 }
 
 erpnext.SalesAnalytics = wn.views.TreeGridReport.extend({
diff --git a/stock/page/stock_ageing/stock_ageing.js b/stock/page/stock_ageing/stock_ageing.js
index 7e9b84f..82ab0bc 100644
--- a/stock/page/stock_ageing/stock_ageing.js
+++ b/stock/page/stock_ageing/stock_ageing.js
@@ -24,6 +24,7 @@
 
 	new erpnext.StockAgeing(wrapper);
 	
+	wrapper.appframe.add_module_tab("Stock");
 }
 
 wn.require("app/js/stock_grid_report.js");
diff --git a/stock/page/stock_analytics/stock_analytics.js b/stock/page/stock_analytics/stock_analytics.js
index 9b0309f..f0d2a2b 100644
--- a/stock/page/stock_analytics/stock_analytics.js
+++ b/stock/page/stock_analytics/stock_analytics.js
@@ -22,6 +22,8 @@
 	});
 	
 	new erpnext.StockAnalytics(wrapper);
+	
+	wrapper.appframe.add_module_tab("Stock");
 }
 
 wn.require("app/js/stock_grid_report.js");
diff --git a/stock/page/stock_ledger/stock_ledger.js b/stock/page/stock_ledger/stock_ledger.js
index 2b8fa9e..f7427ab 100644
--- a/stock/page/stock_ledger/stock_ledger.js
+++ b/stock/page/stock_ledger/stock_ledger.js
@@ -22,6 +22,8 @@
 	});
 	
 	new erpnext.StockLedger(wrapper);
+	
+	wrapper.appframe.add_module_tab("Stock");
 }
 
 wn.require("app/js/stock_grid_report.js");
diff --git a/support/doctype/support_ticket/support_ticket.py b/support/doctype/support_ticket/support_ticket.py
index 6a55755..d42ad82 100644
--- a/support/doctype/support_ticket/support_ticket.py
+++ b/support/doctype/support_ticket/support_ticket.py
@@ -58,5 +58,5 @@
 		update_feed(self.doc)
 		
 	def on_trash(self):
-		webnotes.conn.sql("""update `tabCommunication` set support_ticket="" 
-			where support_ticket=%s`""", self.doc.name)
+		webnotes.conn.sql("""update `tabCommunication` set support_ticket=NULL 
+			where support_ticket=%s""", (self.doc.name,))