Merge pull request #4104 from nabinhait/addresses_and_contacts

[fix] get permission query condition if no permitted links
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py
index a7b1d19..7bad361 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.py
+++ b/erpnext/accounts/report/general_ledger/general_ledger.py
@@ -161,40 +161,26 @@
 		for acc, acc_dict in gle_map.items():
 			if acc_dict.entries:
 				# Opening for individual ledger, if grouped by account
-				if filters.get("group_by_account"):
-					data.append(get_balance_row(_("Opening"), acc_dict.opening,
-						acc_dict.opening_in_account_currency))
+				data.append(get_balance_row(_("Opening"), acc_dict.opening,
+					acc_dict.opening_in_account_currency))
 
 				data += acc_dict.entries
 
 				# Totals and closing for individual ledger, if grouped by account
-				if filters.get("group_by_account"):
-					account_closing = acc_dict.opening + acc_dict.total_debit - acc_dict.total_credit
-					account_closing_in_account_currency = acc_dict.opening_in_account_currency \
-						+ acc_dict.total_debit_in_account_currency - acc_dict.total_credit_in_account_currency
+				account_closing = acc_dict.opening + acc_dict.total_debit - acc_dict.total_credit
+				account_closing_in_account_currency = acc_dict.opening_in_account_currency \
+					+ acc_dict.total_debit_in_account_currency - acc_dict.total_credit_in_account_currency
 
-					data += [{"account": "'" + _("Totals") + "'", "debit": acc_dict.total_debit,
-						"credit": acc_dict.total_credit},
-						get_balance_row(_("Closing (Opening + Totals)"),
-							account_closing, account_closing_in_account_currency), {}]
+				data += [{"account": "'" + _("Totals") + "'", "debit": acc_dict.total_debit,
+					"credit": acc_dict.total_credit},
+					get_balance_row(_("Closing (Opening + Totals)"),
+						account_closing, account_closing_in_account_currency), {}]
 
 	else:
-		from_date, to_date = getdate(filters.from_date), getdate(filters.to_date)
-		opening_debit = opening_credit = 0.0
-
 		for gl in gl_entries:
-			if gl.posting_date < from_date:
-				opening_debit += flt(gl.debit, 3)
-				opening_credit += flt(gl.credit, 3)
-			else:
+			if gl.posting_date >= getdate(filters.from_date) and gl.posting_date <= getdate(filters.to_date):
 				data.append(gl)
 
-	if not (filters.get("account") or filters.get("party")):
-		data = [{
-			"account": "'" + _("Opening") + "'",
-			"debit": opening_debit,
-			"credit": opening_credit
-		}] + data
 
 	# Total debit and credit between from and to date
 	if total_debit or total_credit:
diff --git a/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py b/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py
index f53acca..0dc25d2 100644
--- a/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py
+++ b/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py
@@ -5,6 +5,7 @@
 import frappe
 from frappe.utils import cstr, cint
 from frappe import msgprint, _
+from calendar import monthrange
 
 def execute(filters=None):
 	if not filters: filters = {}
@@ -73,23 +74,17 @@
 		msgprint(_("Please select month and year"), raise_exception=1)
 
 	filters["month"] = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov",
-		"Dec"].index(filters["month"]) + 1
+		"Dec"].index(filters.month) + 1
 
-	from frappe.model.document import Document
-	fiscal_years = frappe.get_doc("Fiscal Year",filters["fiscal_year"])
-	import datetime
-	year_start = fiscal_years.year_start_date.strftime("%Y")
-	year_end = fiscal_years.year_end_date.strftime("%Y")
-	dt_test = datetime.datetime.strptime(year_end + "-" + str(100+int(filters["month"]))[2:3] + "-01", "%Y-%m-%d")
-	date_test = datetime.date(dt_test.year, dt_test.month, dt_test.day)
-	if date_test > fiscal_years.year_end_date:
-		year_target = year_start
+	year_start_date, year_end_date = frappe.db.get_value("Fiscal Year", filters.fiscal_year, 
+		["year_start_date", "year_end_date"])
+		
+	if filters.month >= year_start_date.strftime("%m"):
+		year = year_start_date.strftime("%Y")
 	else:
-		year_target = year_end
-
-	from calendar import monthrange
-	filters["total_days_in_month"] = monthrange(cint(year_target),
-		filters["month"])[1]
+		year = year_end_date.strftime("%Y")
+	
+	filters["total_days_in_month"] = monthrange(cint(year), filters.month)[1]
 
 	conditions = " and month(att_date) = %(month)s and fiscal_year = %(fiscal_year)s"