Merge branch 'staging' into develop
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index 699dcf3..4def02c 100644
--- a/erpnext/__init__.py
+++ b/erpnext/__init__.py
@@ -5,7 +5,7 @@
 from erpnext.hooks import regional_overrides
 from frappe.utils import getdate
 
-__version__ = '10.1.61'
+__version__ = '10.1.63'
 
 def get_default_company(user=None):
 	'''Get default company for user'''
diff --git a/erpnext/accounts/doctype/subscription/test_subscription.py b/erpnext/accounts/doctype/subscription/test_subscription.py
index a5285ea..3d96f23 100644
--- a/erpnext/accounts/doctype/subscription/test_subscription.py
+++ b/erpnext/accounts/doctype/subscription/test_subscription.py
@@ -41,24 +41,14 @@
 		plan.billing_interval_count = 14
 		plan.insert()
 
-
-def create_subscriber():
-	if not frappe.db.exists('Subscriber', '_Test Customer'):
-		subscriber = frappe.new_doc('Subscriber')
-		subscriber.subscriber_name = '_Test Customer'
-		subscriber.customer = '_Test Customer'
-		subscriber.insert()
-
-
 class TestSubscription(unittest.TestCase):
 
 	def setUp(self):
 		create_plan()
-		create_subscriber()
 
 	def test_create_subscription_with_trial_with_correct_period(self):
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.trial_period_start = nowdate()
 		subscription.trial_period_end = add_days(nowdate(), 30)
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
@@ -75,7 +65,7 @@
 
 	def test_create_subscription_without_trial_with_correct_period(self):
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
 		subscription.save()
 
@@ -91,7 +81,7 @@
 
 	def test_create_subscription_trial_with_wrong_dates(self):
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.trial_period_end = nowdate()
 		subscription.trial_period_start = add_days(nowdate(), 30)
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
@@ -101,7 +91,7 @@
 
 	def test_create_subscription_multi_with_different_billing_fails(self):
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.trial_period_end = nowdate()
 		subscription.trial_period_start = add_days(nowdate(), 30)
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
@@ -112,7 +102,7 @@
 
 	def test_invoice_is_generated_at_end_of_billing_period(self):
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.start = '2018-01-01'
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
 		subscription.insert()
@@ -129,7 +119,7 @@
 
 	def test_status_goes_back_to_active_after_invoice_is_paid(self):
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
 		subscription.start = '2018-01-01'
 		subscription.insert()
@@ -159,7 +149,7 @@
 		settings.save()
 
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
 		subscription.start = '2018-01-01'
 		subscription.insert()
@@ -182,7 +172,7 @@
 		settings.save()
 
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
 		subscription.start = '2018-01-01'
 		subscription.insert()
@@ -200,7 +190,7 @@
 
 	def test_subscription_invoice_days_until_due(self):
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
 		subscription.days_until_due = 10
 		subscription.start = add_months(nowdate(), -1)
@@ -218,7 +208,7 @@
 		settings.save()
 
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
 		subscription.start = '2018-01-01'
 		subscription.insert()
@@ -242,7 +232,7 @@
 
 	def test_subscription_remains_active_during_invoice_period(self):
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
 		subscription.save()
 		subscription.process()		# no changes expected
@@ -268,7 +258,7 @@
 
 	def test_subscription_cancelation(self):
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
 		subscription.save()
 		subscription.cancel_subscription()
@@ -284,7 +274,7 @@
 		settings.save()
 
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
 		subscription.save()
 
@@ -319,7 +309,7 @@
 		settings.save()
 
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
 		subscription.save()
 		subscription.cancel_subscription()
@@ -339,7 +329,7 @@
 		settings.save()
 
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
 		subscription.save()
 		subscription.cancel_subscription()
@@ -363,7 +353,7 @@
 		settings.save()
 
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
 		subscription.start = '2018-01-01'
 		subscription.insert()
@@ -397,7 +387,7 @@
 		settings.save()
 
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
 		subscription.start = '2018-01-01'
 		subscription.insert()
@@ -434,7 +424,7 @@
 		settings.save()
 
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
 		subscription.start = '2018-01-01'
 		subscription.insert()
@@ -463,7 +453,7 @@
 
 	def test_restart_active_subscription(self):
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
 		subscription.save()
 
@@ -473,7 +463,7 @@
 
 	def test_subscription_invoice_discount_percentage(self):
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.additional_discount_percentage = 10
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
 		subscription.save()
@@ -488,7 +478,7 @@
 
 	def test_subscription_invoice_discount_amount(self):
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.additional_discount_amount = 11
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
 		subscription.save()
@@ -505,7 +495,7 @@
 		# Create a non pre-billed subscription, processing should not create
 		# invoices.
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
 		subscription.save()
 		subscription.process()
@@ -527,7 +517,7 @@
 		settings.save()
 
 		subscription = frappe.new_doc('Subscription')
-		subscription.subscriber = '_Test Customer'
+		subscription.customer = '_Test Customer'
 		subscription.generate_invoice_at_period_start = True
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
 		subscription.save()
diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py
index e7eff63..1098057 100644
--- a/erpnext/accounts/report/financial_statements.py
+++ b/erpnext/accounts/report/financial_statements.py
@@ -339,19 +339,20 @@
 
 	additional_conditions = get_additional_conditions(from_date, ignore_closing_entries, filters)
 
+	accounts = frappe.db.sql_list("""select name from `tabAccount`
+		where lft >= %s and rgt <= %s""", (root_lft, root_rgt))
+	additional_conditions += " and account in ('{}')"\
+		.format("', '".join([frappe.db.escape(d) for d in accounts]))
+
 	gl_entries = frappe.db.sql("""select posting_date, account, debit, credit, is_opening, fiscal_year, debit_in_account_currency, credit_in_account_currency, account_currency from `tabGL Entry`
 		where company=%(company)s
 		{additional_conditions}
 		and posting_date <= %(to_date)s
-		and account in (select name from `tabAccount`
-			where lft >= %(lft)s and rgt <= %(rgt)s)
 		order by account, posting_date""".format(additional_conditions=additional_conditions),
 		{
 			"company": company,
 			"from_date": from_date,
 			"to_date": to_date,
-			"lft": root_lft,
-			"rgt": root_rgt,
 			"cost_center": filters.cost_center,
 			"project": filters.project
 		},
diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
index 2ff8075..873d210 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
@@ -128,7 +128,7 @@
 						doctype: "Supplier",
 						order_by: "name",
 						fields: ["name"],
-						filters: [["Supplier", "supplier_group_name", "=", args.supplier_group]]
+						filters: [["Supplier", "supplier_group", "=", args.supplier_group]]
 
 					},
 					callback: load_suppliers
diff --git a/erpnext/hooks.py b/erpnext/hooks.py
index f242894..636f089 100644
--- a/erpnext/hooks.py
+++ b/erpnext/hooks.py
@@ -12,7 +12,7 @@
 source_link = "https://github.com/frappe/erpnext"
 
 develop_version = '12.x.x-develop'
-staging_version = '11.0.3-beta.13'
+staging_version = '11.0.3-beta.14'
 
 error_report_email = "support@erpnext.com"
 
diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py
index 2278036..aca277e 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.py
+++ b/erpnext/hr/doctype/leave_application/leave_application.py
@@ -191,9 +191,8 @@
 				frappe.throw(_("The day(s) on which you are applying for leave are holidays. You need not apply for leave."))
 
 			if not is_lwp(self.leave_type):
-				self.leave_balance = get_leave_balance_on(self.employee, self.leave_type, self.from_date,
+				self.leave_balance = get_leave_balance_on(self.employee, self.leave_type, self.from_date, docname=self.name,
 					consider_all_leaves_in_the_allocation_period=True)
-
 				if self.status != "Rejected" and self.leave_balance < self.total_leave_days:
 					if frappe.db.get_value("Leave Type", self.leave_type, "allow_negative"):
 						frappe.msgprint(_("Note: There is not enough leave balance for Leave Type {0}")
@@ -385,26 +384,24 @@
 	return ret
 
 @frappe.whitelist()
-def get_leave_balance_on(employee, leave_type, date, allocation_records=None,
+def get_leave_balance_on(employee, leave_type, date, allocation_records=None, docname=None,
 		consider_all_leaves_in_the_allocation_period=False, consider_encashed_leaves=True):
+
 	if allocation_records == None:
 		allocation_records = get_leave_allocation_records(date, employee).get(employee, frappe._dict())
-
 	allocation = allocation_records.get(leave_type, frappe._dict())
-
 	if consider_all_leaves_in_the_allocation_period:
 		date = allocation.to_date
-	leaves_taken = get_leaves_for_period(employee, leave_type, allocation.from_date, date, status="Approved")
-
+	leaves_taken = get_leaves_for_period(employee, leave_type, allocation.from_date, date, status="Approved", docname=docname)
 	leaves_encashed = 0
 	if frappe.db.get_value("Leave Type", leave_type, 'allow_encashment') and consider_encashed_leaves:
 		leaves_encashed = flt(allocation.total_leaves_encashed)
 
 	return flt(allocation.total_leaves_allocated) - (flt(leaves_taken) + flt(leaves_encashed))
 
-def get_leaves_for_period(employee, leave_type, from_date, to_date, status):
+def get_leaves_for_period(employee, leave_type, from_date, to_date, status, docname=None):
 	leave_applications = frappe.db.sql("""
-		select employee, leave_type, from_date, to_date, total_leave_days
+		select name, employee, leave_type, from_date, to_date, total_leave_days
 		from `tabLeave Application`
 		where employee=%(employee)s and leave_type=%(leave_type)s
 			and status = %(status)s and docstatus != 2
@@ -418,9 +415,10 @@
 		"status": status,
 		"leave_type": leave_type
 	}, as_dict=1)
-
 	leave_days = 0
 	for leave_app in leave_applications:
+		if docname and leave_app.name == docname:
+			continue
 		if leave_app.from_date >= getdate(from_date) and leave_app.to_date <= getdate(to_date):
 			leave_days += leave_app.total_leave_days
 		else:
@@ -450,7 +448,6 @@
 			"total_leaves_allocated": d.total_leaves_allocated,
 			"total_leaves_encashed":d.total_leaves_encashed
 		}))
-
 	return allocated_leaves
 
 @frappe.whitelist()
diff --git a/erpnext/hr/doctype/leave_application/test_leave_application.py b/erpnext/hr/doctype/leave_application/test_leave_application.py
index 71c602b..4748011 100644
--- a/erpnext/hr/doctype/leave_application/test_leave_application.py
+++ b/erpnext/hr/doctype/leave_application/test_leave_application.py
@@ -392,6 +392,34 @@
 			i += 1
 		self.assertEqual(get_leave_balance_on(employee.name, leave_type, nowdate()), 6)
 
+	# test to not consider current leave in leave balance while submitting
+	def test_current_leave_on_submit(self):
+		employee = get_employee()
+		leave_type = 'Sick leave'
+		allocation = frappe.get_doc(dict(
+			doctype = 'Leave Allocation',
+			employee = employee.name,
+			leave_type = leave_type,
+			from_date = '2018-10-01',
+			to_date = '2018-10-10',
+			new_leaves_allocated = 1
+		))
+		allocation.insert(ignore_permissions=True)
+		allocation.submit()
+		leave_application = frappe.get_doc(dict(
+		doctype = 'Leave Application',
+			employee = employee.name,
+			leave_type = leave_type,
+			from_date = '2018-10-02',
+			to_date = '2018-10-02',
+			company = '_Test Company',
+			status = 'Approved',
+			leave_approver = 'test@example.com'
+		))
+		self.assertTrue(leave_application.insert())
+		leave_application.submit()
+		self.assertEqual(leave_application.docstatus, 1)
+
 def make_allocation_record(employee=None, leave_type=None):
 	frappe.db.sql("delete from `tabLeave Allocation`")
 
diff --git a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py
index 9bfa39f..91c7bf5 100644
--- a/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py
+++ b/erpnext/hub_node/doctype/marketplace_settings/marketplace_settings.py
@@ -5,7 +5,7 @@
 import frappe, requests, json, time
 
 from frappe.model.document import Document
-from frappe.utils import add_years, now, get_datetime, get_datetime_str
+from frappe.utils import add_years, now, get_datetime, get_datetime_str, cint
 from frappe import _
 from frappe.frappeclient import FrappeClient
 from erpnext.utilities.product import get_price, get_qty_in_stock
@@ -84,3 +84,11 @@
 	def unregister(self):
 		"""Disable the User on hubmarket.org"""
 		pass
+
+@frappe.whitelist()
+def is_marketplace_enabled():
+	if not hasattr(frappe.local, 'is_marketplace_enabled'):
+		frappe.local.is_marketplace_enabled = cint(frappe.db.get_single_value('Marketplace Settings',
+			'disable_marketplace'))
+
+	return frappe.local.is_marketplace_enabled
diff --git a/erpnext/public/js/hub/hub_factory.js b/erpnext/public/js/hub/hub_factory.js
index 506d374..7d9fefc 100644
--- a/erpnext/public/js/hub/hub_factory.js
+++ b/erpnext/public/js/hub/hub_factory.js
@@ -32,8 +32,9 @@
 };
 
 function is_marketplace_disabled() {
-	return frappe.model.with_doc('Marketplace Settings')
-		.then(doc => doc.disable_marketplace);
+	return frappe.call({
+		method: "erpnext.hub_node.doctype.marketplace_settings.marketplace_settings.is_marketplace_enabled"
+	}).then(r => r.message)
 }
 
 $(document).on('toolbar_setup', () => {
diff --git a/erpnext/public/js/pos/pos.html b/erpnext/public/js/pos/pos.html
index 7287d79..89e2940 100644
--- a/erpnext/public/js/pos/pos.html
+++ b/erpnext/public/js/pos/pos.html
@@ -82,7 +82,7 @@
 						{% for(var j=i*3; j
 						<(i+1)*3; j++) { %} <button type="button" class="btn btn-default numeric-keypad" val="{{j+1}}">{{j+1}}</button>
 							{% } %}
-							<button type="button" {% if((!allow_user_to_edit_rate && chartData[i] == __("Price")) || (!allow_user_to_edit_discount && chartData[i] == __("Disc"))) { %} disabled {% } %} id="pos-item-{{ chartData[i].toLowerCase() }}" class="btn text-center btn-default numeric-keypad pos-operation">{{ __(chartData[i]) }}</button>
+							<button type="button" {% if((!allow_user_to_edit_rate && __(chartData[i]) == __("Price")) || (!allow_user_to_edit_discount && __(chartData[i]) == __("Disc"))) { %} disabled {% } %} id="pos-item-{{ chartData[i].toLowerCase() }}" class="btn text-center btn-default numeric-keypad pos-operation">{{ __(chartData[i]) }}</button>
 				</div>
 				{% } %}
 				<div class="row text-right">
diff --git a/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.py b/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.py
index 180fd09..db11ae9 100644
--- a/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.py
+++ b/erpnext/selling/report/sales_person_wise_transaction_summary/sales_person_wise_transaction_summary.py
@@ -20,7 +20,7 @@
 	for d in entries:
 		if d.stock_qty > 0 or filters.get('show_return_entries', 0):
 			data.append([
-				d.name, d.customer, d.territory, item_details.get(d.item_code, {}).get("website_warehouse"), d.posting_date, d.item_code,
+				d.name, d.customer, d.territory, d.warehouse, d.posting_date, d.item_code,
 				item_details.get(d.item_code, {}).get("item_group"), item_details.get(d.item_code, {}).get("brand"),
 				d.stock_qty, d.base_net_amount, d.sales_person, d.allocated_percentage, d.contribution_amt, company_currency
 			])
@@ -144,10 +144,10 @@
 	conditions, values = get_conditions(filters, date_field)
 
 	entries = frappe.db.sql("""
-		select
+		SELECT
 			dt.name, dt.customer, dt.territory, dt.%s as posting_date, dt_item.item_code,
-			st.sales_person, st.allocated_percentage,
-		CASE 
+			st.sales_person, st.allocated_percentage, dt_item.warehouse,
+		CASE
 			WHEN dt.status = "Closed" THEN dt_item.%s * dt_item.conversion_factor
 			ELSE dt_item.stock_qty
 		END as stock_qty,
@@ -159,9 +159,9 @@
 			WHEN dt.status = "Closed" THEN ((dt_item.base_net_rate * dt_item.%s * dt_item.conversion_factor) * st.allocated_percentage/100)
 			ELSE dt_item.base_net_amount * st.allocated_percentage/100
 		END as contribution_amt
-		from
+		FROM
 			`tab%s` dt, `tab%s Item` dt_item, `tabSales Team` st
-		where
+		WHERE
 			st.parent = dt.name and dt.name = dt_item.parent and st.parenttype = %s
 			and dt.docstatus = 1 %s order by st.sales_person, dt.name desc
 		""" %(date_field, qty_field, qty_field, qty_field, filters["doc_type"], filters["doc_type"], '%s', conditions),
@@ -211,7 +211,7 @@
 
 def get_item_details():
 	item_details = {}
-	for d in frappe.db.sql("""select name, item_group, brand, website_warehouse from `tabItem`""", as_dict=1):
+	for d in frappe.db.sql("""SELECT `name`, `item_group`, `brand` FROM `tabItem`""", as_dict=1):
 		item_details.setdefault(d.name, d)
 
 	return item_details
diff --git a/erpnext/stock/doctype/serial_no/serial_no.json b/erpnext/stock/doctype/serial_no/serial_no.json
index 09973d9..8c3dafe 100644
--- a/erpnext/stock/doctype/serial_no/serial_no.json
+++ b/erpnext/stock/doctype/serial_no/serial_no.json
@@ -1,5 +1,6 @@
 {
  "allow_copy": 0,
+ "allow_events_in_timeline": 0,
  "allow_guest_to_view": 0,
  "allow_import": 1,
  "allow_rename": 1,
@@ -397,7 +398,7 @@
    "precision": "",
    "print_hide": 0,
    "print_hide_if_no_value": 0,
-   "read_only": 1,
+   "read_only": 0,
    "remember_last_selected_value": 0,
    "report_hide": 0,
    "reqd": 0,
@@ -1613,7 +1614,7 @@
  "issingle": 0,
  "istable": 0,
  "max_attachments": 0,
- "modified": "2018-08-29 06:29:51.682813",
+ "modified": "2018-10-19 12:38:34.448513",
  "modified_by": "Administrator",
  "module": "Stock",
  "name": "Serial No",
@@ -1684,7 +1685,7 @@
  "show_name_in_global_search": 1,
  "sort_field": "modified",
  "sort_order": "DESC",
- "track_changes": 0,
+ "track_changes": 1,
  "track_seen": 0,
  "track_views": 0
 }
\ No newline at end of file