Merge pull request #6433 from RobertSchouten/validate_sale_ware

[fix] si validate warehouse if is_stock item
diff --git a/erpnext/accounts/report/sales_register/sales_register.py b/erpnext/accounts/report/sales_register/sales_register.py
index 97b7173..5b1742a 100644
--- a/erpnext/accounts/report/sales_register/sales_register.py
+++ b/erpnext/accounts/report/sales_register/sales_register.py
@@ -124,7 +124,7 @@
 def get_invoices(filters):
 	conditions = get_conditions(filters)
 	return frappe.db.sql("""select name, posting_date, debit_to, project, customer, customer_name, remarks, 
-		base_net_total, base_grand_total, base_rounded_total, outstanding_amount, mode_of_payment
+		base_net_total, base_grand_total, base_rounded_total, outstanding_amount
 		from `tabSales Invoice`
 		where docstatus = 1 %s order by posting_date desc, name desc""" %
 		conditions, filters, as_dict=1)
@@ -196,11 +196,12 @@
 
 def get_mode_of_payments(invoice_list):
 	mode_of_payments = {}
-	inv_mop = frappe.db.sql("""select parent, mode_of_payment
-		from `tabSales Invoice Payment` where parent in (%s) group by parent, mode_of_payment""" %
-		', '.join(['%s']*len(invoice_list)), tuple(invoice_list), as_dict=1)
+	if invoice_list:
+		inv_mop = frappe.db.sql("""select parent, mode_of_payment
+			from `tabSales Invoice Payment` where parent in (%s) group by parent, mode_of_payment""" %
+			', '.join(['%s']*len(invoice_list)), tuple(invoice_list), as_dict=1)
 
-	for d in inv_mop:
-		mode_of_payments.setdefault(d.parent, []).append(d.mode_of_payment)
+		for d in inv_mop:
+			mode_of_payments.setdefault(d.parent, []).append(d.mode_of_payment)
 
 	return mode_of_payments
\ No newline at end of file
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index c9ae6e0..c6910c7 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -175,6 +175,7 @@
 execute:frappe.db.sql_list("delete from `tabDocPerm` where parent='Issue' and modified_by='Administrator' and role='Guest'")
 erpnext.patches.v5_0.update_item_and_description_again
 erpnext.patches.v6_0.multi_currency
+erpnext.patches.v7_0.create_budget_record
 erpnext.patches.v5_0.repost_gle_for_jv_with_multiple_party
 erpnext.patches.v5_0.portal_fixes
 erpnext.patches.v5_0.reset_values_in_tools # 02-05-2016
@@ -237,7 +238,6 @@
 erpnext.patches.v6_4.set_user_in_contact
 erpnext.patches.v6_4.make_image_thumbnail #2015-10-20
 erpnext.patches.v6_5.show_in_website_for_template_item
-erpnext.patches.v7_0.create_budget_record
 erpnext.patches.v6_4.fix_expense_included_in_valuation
 execute:frappe.delete_doc_if_exists("Report", "Item-wise Last Purchase Rate")
 erpnext.patches.v6_6.fix_website_image
diff --git a/erpnext/projects/report/daily_timesheet_summary/daily_timesheet_summary.py b/erpnext/projects/report/daily_timesheet_summary/daily_timesheet_summary.py
index cc854a4..682fb2e 100644
--- a/erpnext/projects/report/daily_timesheet_summary/daily_timesheet_summary.py
+++ b/erpnext/projects/report/daily_timesheet_summary/daily_timesheet_summary.py
@@ -4,6 +4,7 @@
 from __future__ import unicode_literals
 import frappe
 from frappe import _
+from frappe.desk.reportview import build_match_conditions
 
 def execute(filters=None):
 	if not filters:
@@ -12,25 +13,36 @@
 		filters["from_time"] = "00:00:00"
 		filters["to_time"] = "24:00:00"
 
-	columns = [_("Timesheet") + ":Link/Timesheet:120", _("Employee") + "::150", _("Employee Name") + "::150", 
-		_("From Datetime") + "::140", _("To Datetime") + "::140", _("Hours") + "::70", 
-		_("Activity Type") + "::120", _("Task") + ":Link/Task:150",
-		_("Project") + ":Link/Project:120", _("Status") + "::70"]
-		
-	conditions = "ts.docstatus = 1"
-	if filters.get("from_date"):
-		conditions += " and tsd.from_time >= timestamp(%(from_date)s, %(from_time)s)"
-	if filters.get("to_date"):
-		conditions += " and tsd.to_time <= timestamp(%(to_date)s, %(to_time)s)"
-	
+	columns = get_column()
+	conditions = get_conditions(filters)
 	data = get_data(conditions, filters)
 
 	return columns, data
 
+def get_column():
+	return [_("Timesheet") + ":Link/Timesheet:120", _("Employee") + "::150", _("Employee Name") + "::150", 
+		_("From Datetime") + "::140", _("To Datetime") + "::140", _("Hours") + "::70", 
+		_("Activity Type") + "::120", _("Task") + ":Link/Task:150",
+		_("Project") + ":Link/Project:120", _("Status") + "::70"]
+
 def get_data(conditions, filters):
-	time_sheet = frappe.db.sql(""" select ts.name, ts.employee, ts.employee_name, 
-		tsd.from_time, tsd.to_time, tsd.hours,
-		tsd.activity_type, tsd.task, tsd.project, ts.status from `tabTimesheet Detail` tsd, 
-		`tabTimesheet` ts where ts.name = tsd.parent and %s order by ts.name"""%(conditions), filters, as_list=1)
+	time_sheet = frappe.db.sql(""" select `tabTimesheet`.name, `tabTimesheet`.employee, `tabTimesheet`.employee_name,
+		`tabTimesheet Detail`.from_time, `tabTimesheet Detail`.to_time, `tabTimesheet Detail`.hours,
+		`tabTimesheet Detail`.activity_type, `tabTimesheet Detail`.task, `tabTimesheet Detail`.project,
+		`tabTimesheet`.status from `tabTimesheet Detail`, `tabTimesheet` where
+		`tabTimesheet Detail`.parent = `tabTimesheet`.name and %s order by `tabTimesheet`.name"""%(conditions), filters, as_list=1)
 
 	return time_sheet
+
+def get_conditions(filters):
+	conditions = "`tabTimesheet`.docstatus = 1"
+	if filters.get("from_date"):
+		conditions += " and `tabTimesheet Detail`.from_time >= timestamp(%(from_date)s, %(from_time)s)"
+	if filters.get("to_date"):
+		conditions += " and `tabTimesheet Detail`.to_time <= timestamp(%(to_date)s, %(to_time)s)"
+
+	match_conditions = build_match_conditions("Timesheet")
+	if match_conditions:
+		conditions += " and %s" % match_conditions
+
+	return conditions
\ No newline at end of file