Merge branch '1310' of github.com:webnotes/erpnext into 1310
diff --git a/accounts/report/budget_variance_report/budget_variance_report.py b/accounts/report/budget_variance_report/budget_variance_report.py
index 50593bc..0e241de 100644
--- a/accounts/report/budget_variance_report/budget_variance_report.py
+++ b/accounts/report/budget_variance_report/budget_variance_report.py
@@ -17,7 +17,6 @@
 	cam_map = get_costcenter_account_month_map(filters)
 
 	data = []
-
 	for cost_center, cost_center_items in cam_map.items():
 		for account, monthwise_data in cost_center_items.items():
 			row = [cost_center, account]
@@ -120,8 +119,7 @@
 			tav_dict.target = flt(ccd.budget_allocated) * month_percentage /100
 			
 			for ad in actual_details.get(ccd.name, {}).get(ccd.account, []):
-				if ad.month_name == month and ad.account == ccd.account \
-					and ad.cost_center == ccd.name:
+				if ad.month_name == month:
 						tav_dict.actual += ad.debit - ad.credit
 						
 	return cam_map
\ No newline at end of file
diff --git a/buying/doctype/supplier/supplier.js b/buying/doctype/supplier/supplier.js
index 75542c8..58045f5 100644
--- a/buying/doctype/supplier/supplier.js
+++ b/buying/doctype/supplier/supplier.js
@@ -3,10 +3,6 @@
 
 wn.require('app/setup/doctype/contact_control/contact_control.js');
 
-cur_frm.cscript.onload = function(doc,dt,dn){
-	
-}
-
 cur_frm.cscript.refresh = function(doc,dt,dn) {
 	cur_frm.cscript.make_dashboard(doc);
 	if(sys_defaults.supp_master_name == 'Supplier Name')
@@ -35,7 +31,8 @@
 	cur_frm.dashboard.reset();
 	if(doc.__islocal) 
 		return;
-	cur_frm.dashboard.set_headline('<span class="text-muted">Loading...</span>')
+	if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager"))
+		cur_frm.dashboard.set_headline('<span class="text-muted">Loading...</span>')
 	
 	cur_frm.dashboard.add_doctype_badge("Supplier Quotation", "supplier");
 	cur_frm.dashboard.add_doctype_badge("Purchase Order", "supplier");
@@ -49,12 +46,14 @@
 			supplier: cur_frm.doc.name
 		},
 		callback: function(r) {
-			cur_frm.dashboard.set_headline(
-				wn._("Total Billing This Year: ") + "<b>" 
-				+ format_currency(r.message.total_billing, cur_frm.doc.default_currency)
-				+ '</b> / <span class="text-muted">' + wn._("Unpaid") + ": <b>" 
-				+ format_currency(r.message.total_unpaid, cur_frm.doc.default_currency) 
-				+ '</b></span>');
+			if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager")) {
+				cur_frm.dashboard.set_headline(
+					wn._("Total Billing This Year: ") + "<b>" 
+					+ format_currency(r.message.total_billing, cur_frm.doc.default_currency)
+					+ '</b> / <span class="text-muted">' + wn._("Unpaid") + ": <b>" 
+					+ format_currency(r.message.total_unpaid, cur_frm.doc.default_currency) 
+					+ '</b></span>');
+			}
 			cur_frm.dashboard.set_badge_count(r.message);
 		}
 	})
diff --git a/selling/doctype/customer/customer.js b/selling/doctype/customer/customer.js
index d2c6325..014efe6 100644
--- a/selling/doctype/customer/customer.js
+++ b/selling/doctype/customer/customer.js
@@ -45,7 +45,8 @@
 	cur_frm.dashboard.reset(doc);
 	if(doc.__islocal) 
 		return;
-	cur_frm.dashboard.set_headline('<span class="text-muted">'+ wn._('Loading...')+ '</span>')
+	if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager"))
+		cur_frm.dashboard.set_headline('<span class="text-muted">'+ wn._('Loading...')+ '</span>')
 	
 	cur_frm.dashboard.add_doctype_badge("Opportunity", "customer");
 	cur_frm.dashboard.add_doctype_badge("Quotation", "customer");
@@ -60,12 +61,14 @@
 			customer: cur_frm.doc.name
 		},
 		callback: function(r) {
-			cur_frm.dashboard.set_headline(
-				wn._("Total Billing This Year: ") + "<b>" 
-				+ format_currency(r.message.total_billing, cur_frm.doc.default_currency)
-				+ '</b> / <span class="text-muted">' + wn._("Unpaid") + ": <b>" 
-				+ format_currency(r.message.total_unpaid, cur_frm.doc.default_currency) 
-				+ '</b></span>');
+			if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager")) {
+				cur_frm.dashboard.set_headline(
+					wn._("Total Billing This Year: ") + "<b>" 
+					+ format_currency(r.message.total_billing, cur_frm.doc.default_currency)
+					+ '</b> / <span class="text-muted">' + wn._("Unpaid") + ": <b>" 
+					+ format_currency(r.message.total_unpaid, cur_frm.doc.default_currency) 
+					+ '</b></span>');
+			}
 			cur_frm.dashboard.set_badge_count(r.message);
 		}
 	})
diff --git a/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py b/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py
index 6fdafe0..ebb2d9f 100644
--- a/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py
+++ b/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py
@@ -58,7 +58,8 @@
 			
 			columns.append(label+":Float:120")
 
-	return columns + ["Total Target::120", "Total Achieved::120", "Total Variance::120"]
+	return columns + ["Total Target:Float:120", "Total Achieved:Float:120", 
+		"Total Variance:Float:120"]
 
 #Get sales person & item group details
 def get_salesperson_details(filters):
@@ -83,7 +84,7 @@
 def get_achieved_details(filters):
 	start_date, end_date = get_fiscal_year(fiscal_year = filters["fiscal_year"])[1:]
 	
-	return webnotes.conn.sql("""select soi.item_code, soi.qty, soi.amount, so.transaction_date, 
+	item_details = webnotes.conn.sql("""select soi.item_code, soi.qty, soi.amount, so.transaction_date, 
 		st.sales_person, MONTHNAME(so.transaction_date) as month_name 
 		from `tabSales Order Item` soi, `tabSales Order` so, `tabSales Team` st 
 		where soi.parent=so.name and so.docstatus=1 and 
@@ -91,6 +92,13 @@
 		so.transaction_date<=%s""" % ('%s', '%s'), 
 		(start_date, end_date), as_dict=1)
 
+	item_actual_details = {}
+	for d in item_details:
+		item_actual_details.setdefault(d.sales_person, {}).setdefault(\
+			get_item_group(d.item_code), []).append(d)
+
+	return item_actual_details
+
 def get_salesperson_item_month_map(filters):
 	import datetime
 	salesperson_details = get_salesperson_details(filters)
@@ -110,17 +118,15 @@
 			month_percentage = sd.distribution_id and \
 				tdd.get(sd.distribution_id, {}).get(month, 0) or 100.0/12
 			
-			for ad in achieved_details:
+			for ad in achieved_details.get(sd.name, {}).get(sd.item_group, []):
 				if (filters["target_on"] == "Quantity"):
-					tav_dict.target = flt(flt(sd.target_qty) * month_percentage/100, 2)
-					if ad.month_name == month and get_item_group(ad.item_code) == sd.item_group \
-						and ad.sales_person == sd.name:
+					tav_dict.target = flt(sd.target_qty) * month_percentage / 100
+					if ad.month_name == month:
 							tav_dict.achieved += ad.qty
 
 				if (filters["target_on"] == "Amount"):
-					tav_dict.target = flt(flt(sd.target_amount) * month_percentage/100, 2)
-					if ad.month_name == month and get_item_group(ad.item_code) == sd.item_group \
-						and ad.sales_person == sd.name:
+					tav_dict.target = flt(sd.target_amount) * month_percentage / 100
+					if ad.month_name == month:
 							tav_dict.achieved += ad.amount
 
 	return sim_map
diff --git a/selling/report/territory_target_variance_item_group_wise/territory_target_variance_item_group_wise.py b/selling/report/territory_target_variance_item_group_wise/territory_target_variance_item_group_wise.py
index 829f781..2aafe3c 100644
--- a/selling/report/territory_target_variance_item_group_wise/territory_target_variance_item_group_wise.py
+++ b/selling/report/territory_target_variance_item_group_wise/territory_target_variance_item_group_wise.py
@@ -15,11 +15,8 @@
 	columns = get_columns(filters)
 	period_month_ranges = get_period_month_ranges(filters["period"], filters["fiscal_year"])
 	tim_map = get_territory_item_month_map(filters)
-
-	precision = webnotes.conn.get_value("Global Defaults", None, "float_precision") or 2
-
+	
 	data = []
-
 	for territory, territory_items in tim_map.items():
 		for item_group, monthwise_data in territory_items.items():
 			row = [territory, item_group]
@@ -29,7 +26,7 @@
 				for month in relevant_months:
 					month_data = monthwise_data.get(month, {})
 					for i, fieldname in enumerate(["target", "achieved", "variance"]):
-						value = flt(month_data.get(fieldname), precision)
+						value = flt(month_data.get(fieldname))
 						period_data[i] += value
 						totals[i] += value
 				period_data[2] = period_data[0] - period_data[1]
@@ -58,7 +55,8 @@
 				label = label % from_date.strftime("%b")
 			columns.append(label+":Float:120")
 
-	return columns + ["Total Target::120", "Total Achieved::120", "Total Variance::120"]
+	return columns + ["Total Target:Float:120", "Total Achieved:Float:120", 
+		"Total Variance:Float:120"]
 
 #Get territory & item group details
 def get_territory_details(filters):
@@ -83,14 +81,22 @@
 def get_achieved_details(filters):
 	start_date, end_date = get_fiscal_year(fiscal_year = filters["fiscal_year"])[1:]
 
-	return webnotes.conn.sql("""select soi.item_code, soi.qty, soi.amount, so.transaction_date, 
+	item_details = webnotes.conn.sql("""select soi.item_code, soi.qty, soi.amount, so.transaction_date, 
 		so.territory, MONTHNAME(so.transaction_date) as month_name 
 		from `tabSales Order Item` soi, `tabSales Order` so 
 		where soi.parent=so.name and so.docstatus=1 and so.transaction_date>=%s and 
 		so.transaction_date<=%s""" % ('%s', '%s'), 
 		(start_date, end_date), as_dict=1)
 
+	item_actual_details = {}
+	for d in item_details:
+		item_actual_details.setdefault(d.territory, {}).setdefault(\
+			get_item_group(d.item_code), []).append(d)
+
+	return item_actual_details
+
 def get_territory_item_month_map(filters):
+	import datetime
 	territory_details = get_territory_details(filters)
 	tdd = get_target_distribution_details(filters)
 	achieved_details = get_achieved_details(filters)
@@ -110,17 +116,15 @@
 			month_percentage = td.distribution_id and \
 				tdd.get(td.distribution_id, {}).get(month, 0) or 100.0/12
 
-			for ad in achieved_details:
+			for ad in achieved_details.get(td.name, {}).get(td.item_group, []):
 				if (filters["target_on"] == "Quantity"):
-					tav_dict.target = flt(flt(td.target_qty) * month_percentage /100)
-					if ad.month_name == month and get_item_group(ad.item_code) == td.item_group \
-						and ad.territory == td.name:
+					tav_dict.target = flt(td.target_qty) * month_percentage / 100
+					if ad.month_name == month:
 							tav_dict.achieved += ad.qty
 
 				if (filters["target_on"] == "Amount"):
-					tav_dict.target = flt(flt(td.target_amount) * month_percentage / 100)
-					if ad.month_name == month and get_item_group(ad.item_code) == td.item_group \
-						and ad.territory == td.name:
+					tav_dict.target = flt(td.target_amount) * month_percentage / 100
+					if ad.month_name == month:
 							tav_dict.achieved += ad.amount
 
 	return tim_map