Merge pull request #6651 from shreyasp/del-company-txn

Delete Communications while Deleting Company Transactions
diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py
index c1a9a06..a51e2b5 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.py
+++ b/erpnext/hr/doctype/leave_application/leave_application.py
@@ -193,7 +193,7 @@
 
 	def validate_max_days(self):
 		max_days = frappe.db.get_value("Leave Type", self.leave_type, "max_days_allowed")
-		if max_days and self.total_leave_days > max_days:
+		if max_days and self.total_leave_days > cint(max_days):
 			frappe.throw(_("Leave of type {0} cannot be longer than {1}").format(self.leave_type, max_days))
 
 	def validate_leave_approver(self):
@@ -279,7 +279,7 @@
 
 @frappe.whitelist()
 def get_number_of_leave_days(employee, leave_type, from_date, to_date, half_day=None):
-	if half_day:
+	if half_day==1:
 		return 0.5
 	number_of_days = date_diff(to_date, from_date) + 1
 	if not frappe.db.get_value("Leave Type", leave_type, "include_holiday"):
diff --git a/erpnext/hr/doctype/process_payroll/process_payroll.json b/erpnext/hr/doctype/process_payroll/process_payroll.json
index 13d3191..546da97 100644
--- a/erpnext/hr/doctype/process_payroll/process_payroll.json
+++ b/erpnext/hr/doctype/process_payroll/process_payroll.json
@@ -609,7 +609,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "depends_on": "payment_account", 
+   "depends_on": "eval:doc.payment_account", 
    "description": "Create Bank Entry for the total salary paid for the above selected criteria", 
    "fieldname": "make_bank_entry", 
    "fieldtype": "Button", 
@@ -692,7 +692,7 @@
  "issingle": 1, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-09-28 05:43:26.472928", 
+ "modified": "2016-10-22 08:10:44.293748", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Process Payroll", 
@@ -708,6 +708,7 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
+   "is_custom": 0, 
    "permlevel": 0, 
    "print": 0, 
    "read": 1, 
diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.py b/erpnext/hr/doctype/salary_slip/salary_slip.py
index 84a20d9..8c0206e 100644
--- a/erpnext/hr/doctype/salary_slip/salary_slip.py
+++ b/erpnext/hr/doctype/salary_slip/salary_slip.py
@@ -280,24 +280,26 @@
 		holidays = [cstr(i) for i in holidays]
 
 		return holidays
-
+	
 	def calculate_lwp(self, holidays, working_days):
 		lwp = 0
+		holidays = "','".join(holidays)
 		for d in range(working_days):
 			dt = add_days(cstr(getdate(self.start_date)), d)
-			if dt not in holidays:
-				leave = frappe.db.sql("""
-					select t1.name, t1.half_day
-					from `tabLeave Application` t1, `tabLeave Type` t2
-					where t2.name = t1.leave_type
-					and t2.is_lwp = 1
-					and t1.docstatus = 1
-					and t1.employee = %s
-					and %s between from_date and to_date
-				""", (self.employee, dt))
-				if leave:
-					lwp = cint(leave[0][1]) and (lwp + 0.5) or (lwp + 1)
-		return lwp
+			leave = frappe.db.sql("""
+				select t1.name, t1.half_day
+				from `tabLeave Application` t1, `tabLeave Type` t2
+				where t2.name = t1.leave_type
+				and t2.is_lwp = 1
+				and t1.docstatus = 1
+				and t1.employee = %(employee)s
+				and CASE WHEN t2.include_holiday != 1 THEN %(dt)s not in ('{0}') and %(dt)s between from_date and to_date
+				WHEN t2.include_holiday THEN %(dt)s between from_date and to_date
+				END
+				""".format(holidays), {"employee": self.employee, "dt": dt})
+			if leave:
+				lwp = cint(leave[0][1]) and (lwp + 0.5) or (lwp + 1)
+		return lwp	
 
 	def check_existing(self):
 		if not self.salary_slip_based_on_timesheet:
diff --git a/erpnext/stock/doctype/material_request/material_request.js b/erpnext/stock/doctype/material_request/material_request.js
index 78f17d3..44b7dea 100644
--- a/erpnext/stock/doctype/material_request/material_request.js
+++ b/erpnext/stock/doctype/material_request/material_request.js
@@ -7,7 +7,13 @@
 	onload: function(frm) {
 		// formatter for material request item
 		frm.set_indicator_formatter('item_code',
-			function(doc) { return (doc.qty<=doc.ordered_qty) ? "green" : "orange" })
+			function(doc) { return (doc.qty<=doc.ordered_qty) ? "green" : "orange" }),
+
+		frm.fields_dict["items"].grid.get_field("warehouse").get_query = function(doc, cdt, cdn){
+			return{
+				filters: {'company': doc.company}
+			}
+		}
 	}
 });