Merge pull request #1289 from pdvyas/hotfix-installer

fix installer python packages issue
diff --git a/accounts/report/accounts_payable/accounts_payable.py b/accounts/report/accounts_payable/accounts_payable.py
index f9266dc..1bd8a9f 100644
--- a/accounts/report/accounts_payable/accounts_payable.py
+++ b/accounts/report/accounts_payable/accounts_payable.py
@@ -9,18 +9,20 @@
 
 def execute(filters=None):
 	if not filters: filters = {}
-	columns = get_columns()
+	supplier_naming_by = webnotes.conn.get_value("Buying Settings", None, "supp_master_name")
+	columns = get_columns(supplier_naming_by)
 	entries = get_gl_entries(filters)
-	account_supplier = dict(webnotes.conn.sql("""select account.name, supplier.supplier_name
-		from `tabAccount` account, `tabSupplier` supplier 
-		where account.master_type="Supplier" and supplier.name=account.master_name"""))
-	
+	account_map = dict(((r.name, r) for r in webnotes.conn.sql("""select acc.name, 
+		supp.supplier_name, supp.name as supplier 
+		from `tabAccount` acc, `tabSupplier` supp 
+		where acc.master_type="Supplier" and supp.name=acc.master_name""", as_dict=1)))
+
 	entries_after_report_date = [[gle.voucher_type, gle.voucher_no] 
 		for gle in get_gl_entries(filters, before_report_date=False)]
-	
+
 	account_supplier_type_map = get_account_supplier_type_map()
 	voucher_detail_map = get_voucher_details()
-	
+
 	# Age of the invoice on this date
 	age_on = getdate(filters.get("report_date")) > getdate(nowdate()) \
 		and nowdate() or filters.get("report_date")
@@ -37,9 +39,7 @@
 
 			if abs(flt(outstanding_amount)) > 0.01:
 				paid_amount = invoiced_amount - outstanding_amount
-				row = [gle.posting_date, gle.account, account_supplier.get(gle.account, ""),
-					gle.voucher_type, gle.voucher_no, gle.remarks, 
-					account_supplier_type_map.get(gle.account), 
+				row = [gle.posting_date, gle.account, gle.voucher_type, gle.voucher_no, 
 					voucher_details.get("due_date", ""), voucher_details.get("bill_no", ""), 
 					voucher_details.get("bill_date", ""), invoiced_amount, 
 					paid_amount, outstanding_amount]
@@ -50,21 +50,38 @@
 				else:
 					ageing_based_on_date = gle.posting_date
 					
-				row += get_ageing_data(age_on, ageing_based_on_date, outstanding_amount)
+				row += get_ageing_data(age_on, ageing_based_on_date, outstanding_amount) + \
+					[account_map.get(gle.account).get("supplier") or ""]
+
+				if supplier_naming_by == "Naming Series":
+					row += [account_map.get(gle.account).get("supplier_name") or ""]
+
+				row += [account_supplier_type_map.get(gle.account), gle.remarks]
 				data.append(row)
-				
+
+	for i in range(0, len(data)):
+		data[i].insert(4, """<a href="%s"><i class="icon icon-share" style="cursor: pointer;"></i></a>""" \
+			% ("/".join(["#Form", data[i][2], data[i][3]]),))
+
 	return columns, data
 	
-def get_columns():
-	return [
-		"Posting Date:Date:80", "Account:Link/Account:150", "Supplier::150", "Voucher Type::110", 
-		"Voucher No::120", "Remarks::150", "Supplier Type:Link/Supplier Type:120", 
-		"Due Date:Date:80", "Bill No::80", "Bill Date:Date:80", 
+def get_columns(supplier_naming_by):
+	columns = [
+		"Posting Date:Date:80", "Account:Link/Account:150", "Voucher Type::110", 
+		"Voucher No::120", "::30", "Due Date:Date:80", "Bill No::80", "Bill Date:Date:80", 
 		"Invoiced Amount:Currency:100", "Paid Amount:Currency:100", 
 		"Outstanding Amount:Currency:100", "Age:Int:50", "0-30:Currency:100", 
-		"30-60:Currency:100", "60-90:Currency:100", "90-Above:Currency:100"
+		"30-60:Currency:100", "60-90:Currency:100", "90-Above:Currency:100",
+		"Supplier:Link/Supplier:150"
 	]
-	
+
+	if supplier_naming_by == "Naming Series":
+		columns += ["Supplier Name::110"]
+
+	columns += ["Supplier Type:Link/Supplier Type:120", "Remarks::150"]
+
+	return columns
+
 def get_gl_entries(filters, before_report_date=True):
 	conditions, supplier_accounts = get_conditions(filters, before_report_date)
 	gl_entries = []
@@ -102,10 +119,10 @@
 	
 def get_account_supplier_type_map():
 	account_supplier_type_map = {}
-	for each in webnotes.conn.sql("""select t2.name, t1.supplier_type from `tabSupplier` t1, 
-			`tabAccount` t2 where t1.name = t2.master_name group by t2.name"""):
+	for each in webnotes.conn.sql("""select acc.name, supp.supplier_type from `tabSupplier` supp, 
+			`tabAccount` acc where supp.name = acc.master_name group by acc.name"""):
 		account_supplier_type_map[each[0]] = each[1]
-		
+
 	return account_supplier_type_map
 	
 def get_voucher_details():
diff --git a/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py b/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
index 7d81308..7d8a358 100644
--- a/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
+++ b/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
@@ -12,7 +12,8 @@
 	
 	item_list = get_items(filters)
 	aii_account_map = get_aii_accounts()
-	item_tax, tax_accounts = get_tax_accounts(item_list, columns)
+	if item_list:
+		item_tax, tax_accounts = get_tax_accounts(item_list, columns)
 	
 	data = []
 	for d in item_list:
diff --git a/accounts/report/item_wise_sales_register/item_wise_sales_register.py b/accounts/report/item_wise_sales_register/item_wise_sales_register.py
index dc5ecda..9f1fd87 100644
--- a/accounts/report/item_wise_sales_register/item_wise_sales_register.py
+++ b/accounts/report/item_wise_sales_register/item_wise_sales_register.py
@@ -11,7 +11,8 @@
 	last_col = len(columns)
 
 	item_list = get_items(filters)
-	item_tax, tax_accounts = get_tax_accounts(item_list, columns)
+	if item_list:
+		item_tax, tax_accounts = get_tax_accounts(item_list, columns)
 	
 	data = []
 	for d in item_list:
@@ -39,7 +40,6 @@
 		"Qty:Float:120", "Rate:Currency:120", "Amount:Currency:120"
 	]
 	
-	
 def get_conditions(filters):
 	conditions = ""
 	
diff --git a/config.json b/config.json
index 536e5af..078ca16 100644
--- a/config.json
+++ b/config.json
@@ -1,6 +1,6 @@
 {
  "app_name": "ERPNext", 
- "app_version": "3.4.6", 
+ "app_version": "3.4.8", 
  "base_template": "app/portal/templates/base.html", 
  "modules": {
   "Accounts": {
@@ -74,5 +74,5 @@
    "type": "module"
   }
  }, 
- "requires_framework_version": "==3.4.3"
+ "requires_framework_version": "==3.4.4"
 }
\ No newline at end of file
diff --git a/controllers/accounts_controller.py b/controllers/accounts_controller.py
index 778348d..839dce0 100644
--- a/controllers/accounts_controller.py
+++ b/controllers/accounts_controller.py
@@ -387,35 +387,38 @@
 		
 		for item in self.doclist.get({"parentfield": "entries"}):
 			if item.fields.get(item_ref_dn):
-				already_billed = webnotes.conn.sql("""select sum(%s) from `tab%s` 
-					where %s=%s and docstatus=1 and parent != %s""" % 
-					(based_on, self.tname, item_ref_dn, '%s', '%s'), 
-					(item.fields[item_ref_dn], self.doc.name), debug=1)[0][0]
-				
-				total_billed_amt = flt(flt(already_billed) + flt(item.fields[based_on]), 
-					self.precision(based_on, item))
-				
 				ref_amt = flt(webnotes.conn.get_value(ref_dt + " Item", 
 					item.fields[item_ref_dn], based_on), self.precision(based_on, item))
+				if not ref_amt:
+					webnotes.msgprint(_("As amount for item") + ": " + item.item_code + _(" in ") + 
+						ref_dt + _(" is zero, system will not check for over-billed"))
+				else:
+					already_billed = webnotes.conn.sql("""select sum(%s) from `tab%s` 
+						where %s=%s and docstatus=1 and parent != %s""" % 
+						(based_on, self.tname, item_ref_dn, '%s', '%s'), 
+						(item.fields[item_ref_dn], self.doc.name))[0][0]
 				
-				tolerance, item_tolerance, global_tolerance = get_tolerance_for(item.item_code, 
-					item_tolerance, global_tolerance)
-					
-				max_allowed_amt = flt(ref_amt * (100 + tolerance) / 100)
+					total_billed_amt = flt(flt(already_billed) + flt(item.fields[based_on]), 
+						self.precision(based_on, item))
 				
-				if total_billed_amt - max_allowed_amt > 0.01:
-					reduce_by = total_billed_amt - max_allowed_amt
+					tolerance, item_tolerance, global_tolerance = get_tolerance_for(item.item_code, 
+						item_tolerance, global_tolerance)
 					
-					webnotes.throw(_("Row #") + cstr(item.idx) + ": " + 
-						_(" Max amount allowed for Item ") + cstr(item.item_code) + 
-						_(" against ") + ref_dt + " " + 
-						cstr(item.fields[ref_dt.lower().replace(" ", "_")]) + _(" is ") + 
-						cstr(max_allowed_amt) + ". \n" + 
-						_("""If you want to increase your overflow tolerance, please increase \
-						tolerance % in Global Defaults or Item master. 				
-						Or, you must reduce the amount by """) + cstr(reduce_by) + "\n" + 
-						_("""Also, please check if the order item has already been billed \
-							in the Sales Order"""))
+					max_allowed_amt = flt(ref_amt * (100 + tolerance) / 100)
+				
+					if total_billed_amt - max_allowed_amt > 0.01:
+						reduce_by = total_billed_amt - max_allowed_amt
+					
+						webnotes.throw(_("Row #") + cstr(item.idx) + ": " + 
+							_(" Max amount allowed for Item ") + cstr(item.item_code) + 
+							_(" against ") + ref_dt + " " + 
+							cstr(item.fields[ref_dt.lower().replace(" ", "_")]) + _(" is ") + 
+							cstr(max_allowed_amt) + ". \n" + 
+							_("""If you want to increase your overflow tolerance, please increase \
+							tolerance % in Global Defaults or Item master. 				
+							Or, you must reduce the amount by """) + cstr(reduce_by) + "\n" + 
+							_("""Also, please check if the order item has already been billed \
+								in the Sales Order"""))
 				
 	def get_company_default(self, fieldname):
 		from accounts.utils import get_company_default