Merge branch 'hotfix'
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index c1ec571..d812208 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.0.8'
+__version__ = '10.0.9'
 
 def get_default_company(user=None):
 	'''Get default company for user'''
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index e5809fe..0e35768 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -252,7 +252,7 @@
 	if not ac.parent_account:
 		ac.parent_account = args.get("parent")
 
-	if ac.is_root:
+	if getattr(ac, 'is_root', None):
 		ac.parent_account=''
 
 	ac.old_parent = ""
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index e176472..81d2786 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -54,6 +54,7 @@
 
 		if self.meta.get_field("taxes_and_charges"):
 			self.validate_enabled_taxes_and_charges()
+			self.validate_tax_account_company()
 
 		self.validate_party()
 		self.validate_currency()
@@ -255,6 +256,14 @@
 		if frappe.db.get_value(taxes_and_charges_doctype, self.taxes_and_charges, "disabled"):
 			frappe.throw(_("{0} '{1}' is disabled").format(taxes_and_charges_doctype, self.taxes_and_charges))
 
+	def validate_tax_account_company(self):
+		for d in self.get("taxes"):
+			if d.account_head:
+				tax_account_company = frappe.db.get_value("Account", d.account_head, "company")
+				if tax_account_company != self.company:
+					frappe.throw(_("Row #{0}: Account {1} does not belong to company {2}")
+						.format(d.idx, d.account_head, self.company))
+
 	def get_gl_dict(self, args, account_currency=None):
 		"""this method populates the common properties of a gl entry record"""
 
@@ -722,11 +731,15 @@
 	return frappe.db.get_value("Account", account_head, ["tax_rate", "account_name"], as_dict=True)
 
 @frappe.whitelist()
-def get_default_taxes_and_charges(master_doctype, company=None):
+def get_default_taxes_and_charges(master_doctype, tax_template=None, company=None):
 	if not company: return {}
 
-	default_tax = frappe.db.get_value(master_doctype,
-		{"is_default": 1, "company": company})
+	if tax_template and company:
+		tax_template_company = frappe.db.get_value(master_doctype, tax_template, "company")
+		if tax_template_company == company:
+			return
+
+	default_tax = frappe.db.get_value(master_doctype, {"is_default": 1, "company": company})
 
 	return {
 		'taxes_and_charges': default_tax,
diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py
index 9b5d6a6..75f9dea 100644
--- a/erpnext/crm/doctype/opportunity/opportunity.py
+++ b/erpnext/crm/doctype/opportunity/opportunity.py
@@ -232,7 +232,7 @@
 		quotation.conversion_rate = exchange_rate
 
 		# get default taxes
-		taxes = get_default_taxes_and_charges("Sales Taxes and Charges Template", quotation.company)
+		taxes = get_default_taxes_and_charges("Sales Taxes and Charges Template", company=quotation.company)
 		if taxes.get('taxes'):
 			quotation.update(taxes)
 
diff --git a/erpnext/non_profit/doctype/chapter/chapter.py b/erpnext/non_profit/doctype/chapter/chapter.py
index d484882..3320690 100644
--- a/erpnext/non_profit/doctype/chapter/chapter.py
+++ b/erpnext/non_profit/doctype/chapter/chapter.py
@@ -35,4 +35,16 @@
 	context.title = 'All Chapters'
 	context.no_breadcrumbs = True
 	context.order_by = 'creation desc'
-	context.introduction = '<p>All Chapters</p>'
\ No newline at end of file
+	context.introduction = '<p>All Chapters</p>'
+
+
+@frappe.whitelist()
+def leave(title, user_id, leave_reason):
+	chapter = frappe.get_doc("Chapter", title)
+	for member in chapter.members:
+		if member.user == user_id:
+			member.enabled = 0
+			member.leave_reason = leave_reason
+	chapter.save(ignore_permissions=1)
+	frappe.db.commit()
+	return "Thank you for Feedback"
\ No newline at end of file
diff --git a/erpnext/non_profit/doctype/chapter/templates/chapter.html b/erpnext/non_profit/doctype/chapter/templates/chapter.html
index 8953481..671a13a 100644
--- a/erpnext/non_profit/doctype/chapter/templates/chapter.html
+++ b/erpnext/non_profit/doctype/chapter/templates/chapter.html
@@ -5,34 +5,39 @@
 <h3>Details</h3>
 <p>{{ introduction }}</p>
 {% if meetup_embed_html %}
-{{ meetup_embed_html }}
+	{{ meetup_embed_html }}
 {% endif %}
 <h3>List of Members</h3>
-{% if members %}
+
+{% if members  %}
 	<table class="table table-bordered small" style="max-width: 500px;">
 		<tr>
 			<th width="15%" ></th>
 			<th>Member Details</th>
 		</tr>
+		{% set index = [1] %}
 		{% for user in members %}
-			<tr>
-				<td>{{ loop.index }}</td>
-				<td>
-					<div class="row">
-						<div class="col-lg-6 col-md-6 col-sm-6">{{ frappe.db.get_value('User', user.user, 'full_name') }}</div>
-						<div class="col-lg-6 col-md-6 col-sm-6 text-right">
-							{% if user.website_url %}
-								<a href="{{ user.website_url }}">{{ user.website_url or '' }}</a>
+			{% if user.enabled == 1 %}
+				<tr>
+					<td>{{ index|length }}</td>
+					<td>
+						<div class="row">
+							<div class="col-lg-6 col-md-6 col-sm-6">{{ frappe.db.get_value('User', user.user, 'full_name') }}</div>
+							<div class="col-lg-6 col-md-6 col-sm-6 text-right">
+								{% if user.website_url %}
+									<a href="{{ user.website_url }}">{{ user.website_url or '' }}</a>
+								{% endif %}
+							</div>
+							<div class="col-lg-12">
+							{% if user.introduction %}
+								{{ user.introduction }}
 							{% endif %}
+							</div>
 						</div>
-						<div class="col-lg-12">
-						{% if user.introduction %}
-							{{ user.introduction }}
-						{% endif %}
-						</div>
-					</div>
-				</td>
-			</tr>
+					</td>
+				</tr>
+				{% set __ = index.append(1) %}
+			{% endif %}
 		{% endfor %}
 	</table>
 {% else %}
diff --git a/erpnext/non_profit/doctype/chapter/templates/chapter_row.html b/erpnext/non_profit/doctype/chapter/templates/chapter_row.html
index 67fb0c5..12176ca 100644
--- a/erpnext/non_profit/doctype/chapter/templates/chapter_row.html
+++ b/erpnext/non_profit/doctype/chapter/templates/chapter_row.html
@@ -1,21 +1,30 @@
 {% if doc.published %}
 	<div style="margin-bottom: 30px; max-width: 600px" class="with-border clickable">
-		<a href="/{{ doc.route }}">
+		<a href={{ route }}>
 			<h3>{{ doc.name }}</h3>
 			<p>
-				<span class="label">{{ frappe.db.get_value('User', chapter_head, 'full_name') }}</span>
+				<span class="label"> Chapter Head : {{ frappe.db.get_value('User', chapter_head, 'full_name') }} </span>
 				<span class="label">
 					{% if members %}
-						Members: {{ members|length }}
+						{% set index = [] %}
+						{% for user in members %}
+							{% if user.enabled == 1 %}
+								{% set __ = index.append(1) %}
+							{% endif %}
+						{% endfor %}
+						Members: {{ index|length }}
 					{% else %}
 						Members: 0
 					{% endif %}
-				</span>
+					</span>
+				<!-- Assignment of value to global variable not working in jinja -->
 			</p>
 			<p>{{ html2text(doc.introduction[:200]) }}{% if introduction|len > 200 %}...{% endif %}</p>
 		</a>
 	</div>
 {% endif %}
+
+<!-- this is a sample default list template -->
 <style type="text/css">
 
 .label {
diff --git a/erpnext/non_profit/doctype/chapter_member/chapter_member.json b/erpnext/non_profit/doctype/chapter_member/chapter_member.json
index ba78a67..0b8f5a7 100644
--- a/erpnext/non_profit/doctype/chapter_member/chapter_member.json
+++ b/erpnext/non_profit/doctype/chapter_member/chapter_member.json
@@ -132,6 +132,36 @@
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "leave_reason", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Leave Reason", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
   }
  ], 
  "has_web_view": 0, 
@@ -144,7 +174,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2017-12-06 11:33:34.300252", 
+ "modified": "2018-01-12 12:16:10.591039", 
  "modified_by": "Administrator", 
  "module": "Non Profit", 
  "name": "Chapter Member", 
diff --git a/erpnext/non_profit/doctype/donor/donor.json b/erpnext/non_profit/doctype/donor/donor.json
index c940bda..d753727 100644
--- a/erpnext/non_profit/doctype/donor/donor.json
+++ b/erpnext/non_profit/doctype/donor/donor.json
@@ -295,7 +295,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2017-12-05 07:02:06.690416", 
+ "modified": "2018-01-15 09:40:41.153561", 
  "modified_by": "Administrator", 
  "module": "Non Profit", 
  "name": "Donor", 
@@ -330,6 +330,7 @@
  "show_name_in_global_search": 0, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
+ "title_field": "donor_name", 
  "track_changes": 1, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/non_profit/doctype/member/member.json b/erpnext/non_profit/doctype/member/member.json
index 1c6b9fc..0eab6ae 100644
--- a/erpnext/non_profit/doctype/member/member.json
+++ b/erpnext/non_profit/doctype/member/member.json
@@ -325,7 +325,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2017-12-05 07:03:21.606732", 
+ "modified": "2018-01-15 09:38:41.878167", 
  "modified_by": "Administrator", 
  "module": "Non Profit", 
  "name": "Member", 
@@ -380,6 +380,7 @@
  "show_name_in_global_search": 0, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
+ "title_field": "member_name", 
  "track_changes": 1, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/non_profit/doctype/volunteer/volunteer.json b/erpnext/non_profit/doctype/volunteer/volunteer.json
index 703230c..0d18bab 100644
--- a/erpnext/non_profit/doctype/volunteer/volunteer.json
+++ b/erpnext/non_profit/doctype/volunteer/volunteer.json
@@ -506,7 +506,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2017-12-06 12:03:08.624579", 
+ "modified": "2018-01-15 09:40:25.229551", 
  "modified_by": "Administrator", 
  "module": "Non Profit", 
  "name": "Volunteer", 
@@ -540,6 +540,7 @@
  "show_name_in_global_search": 0, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
+ "title_field": "volunteer_name", 
  "track_changes": 1, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index b7ad866..e198c7e 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -244,10 +244,11 @@
 				method: "erpnext.controllers.accounts_controller.get_default_taxes_and_charges",
 				args: {
 					"master_doctype": taxes_and_charges_field.options,
+					"tax_template": me.frm.doc.taxes_and_charges,
 					"company": me.frm.doc.company
 				},
 				callback: function(r) {
-					if(!r.exc) {
+					if(!r.exc && r.message) {
 						frappe.run_serially([
 							() => {
 								// directly set in doc, so as not to call triggers
diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py
index fcbb63c..c3deaf2 100644
--- a/erpnext/shopping_cart/cart.py
+++ b/erpnext/shopping_cart/cart.py
@@ -204,7 +204,6 @@
 			"status": "Draft",
 			"docstatus": 0,
 			"__islocal": 1,
-			"payment_terms_template": "_Test Payment Term Template",
 			(party.doctype.lower()): party.name
 		})
 
diff --git a/erpnext/shopping_cart/test_shopping_cart.py b/erpnext/shopping_cart/test_shopping_cart.py
index 5578546..2aeb4a9 100644
--- a/erpnext/shopping_cart/test_shopping_cart.py
+++ b/erpnext/shopping_cart/test_shopping_cart.py
@@ -9,7 +9,7 @@
 from erpnext.tests.utils import create_test_contact_and_address
 
 
-test_dependencies = ['Payment Terms Template']
+# test_dependencies = ['Payment Terms Template']
 
 class TestShoppingCart(unittest.TestCase):
 	"""
diff --git a/erpnext/templates/pages/non_profit/join-chapter.html b/erpnext/templates/pages/non_profit/join-chapter.html
index 284e9c4..029cd77 100644
--- a/erpnext/templates/pages/non_profit/join-chapter.html
+++ b/erpnext/templates/pages/non_profit/join-chapter.html
@@ -11,18 +11,18 @@
 	<p><a href="/login?redirect-to=/{{ chapter.route }}" class='btn btn-primary'>Login</a></p>
 {% else %}
 	{% if already_member %}
-		<p>You are already a member of {{ chapter.title }}!</p>
+		<p>You are already a member of {{ chapter.name }}!</p>
 		{{ chapter_button() }}
 		<p><a href="">Leave Chapter</a></p>
 	{% else %}
 		{% if frappe.local.request.method=='POST' %}
-			<p>Welcome to chapter {{ chapter.title }}!</p>
+			<p>Welcome to chapter {{ chapter.name }}!</p>
 			{{ chapter_button() }}
 		{% else %}
 			<div style="padding: 20px 0;">
 				<div class="row">
 					<div class="col-lg-8 col-md-8">
-						<form name="user-intro" action="/join-chapter" method='POST'>
+						<form name="user-intro" action="/non_profit/join-chapter" method='POST'>
 							<div class="form-group">
 								<input name="name" class="hidden form-control" type="text"
 									value="{{chapter.name}}">
diff --git a/erpnext/templates/pages/non_profit/join_chapter.py b/erpnext/templates/pages/non_profit/join_chapter.py
index 78ef053..121f444 100644
--- a/erpnext/templates/pages/non_profit/join_chapter.py
+++ b/erpnext/templates/pages/non_profit/join_chapter.py
@@ -4,7 +4,7 @@
 	context.no_cache = True
 	chapter = frappe.get_doc('Chapter', frappe.form_dict.name)
 	if frappe.session.user!='Guest':
-		if frappe.session.user in [d.user for d in chapter.members]:
+		if frappe.session.user in [d.user for d in chapter.members if d.enabled == 1]:
 			context.already_member = True
 		else:
 			if frappe.request.method=='GET':
diff --git a/erpnext/templates/pages/non_profit/leave-chapter.html b/erpnext/templates/pages/non_profit/leave-chapter.html
index 2f8452d..009c7af 100644
--- a/erpnext/templates/pages/non_profit/leave-chapter.html
+++ b/erpnext/templates/pages/non_profit/leave-chapter.html
@@ -1,16 +1,42 @@
 {% extends "templates/web.html" %}
-<!-- 
-{% macro chapter_button() %}
-	<p><a href="/{{ chapter.route }}" class='btn btn-primary'>
-		Go to Chapter Page</a></p>
-{% endmacro %}
- -->
 {% block page_content %}
 
 	{% if member_deleted %}
-		<p>You are not a member of {{ chapter.title }}!</p>
+		<p>You are not a member of {{ chapter.name }}!</p>
+		<div>
+			<form>
+				<div class="form-group">
+					<label for="leave">Why do you want to leave this chapter</label>
+					<input type="text" name="leave" class="form-control" id="leave">
+				</div>
+				<button type="button" class="btn btn-default btn-leave" data-title= "{{ chapter.name }}" id="btn-leave">Submit
+				</button>
+			</form>
+		</div>
 		<p>Please signup and login to join this chapter</p>
 
 		<p><a href="/join-chapter?name={{ chapter.name }}" class='btn btn-primary'>Become Member agian</a></p>
 	{% endif %}
+	<script>
+		frappe.ready(function() {
+			$(".btn-leave").on("click", function() {
+				var leave =  $("#leave").val();
+				var user_id = frappe.session.user;
+				var title =  $(this).attr("data-title");
+				frappe.call({
+						method: "erpnext.non_profit.doctype.chapter.chapter.leave",
+						args: {
+							leave_reason: leave,
+							user_id: user_id,
+							title: title
+						},
+						callback: function(r) {
+							if(r.message) {
+								frappe.msgprint(r.message)
+							}
+						}
+				})
+			});
+		})
+	</script>
 {% endblock %}
\ No newline at end of file
diff --git a/erpnext/templates/pages/non_profit/leave_chapter.py b/erpnext/templates/pages/non_profit/leave_chapter.py
index 6dbdeca..da2d819 100644
--- a/erpnext/templates/pages/non_profit/leave_chapter.py
+++ b/erpnext/templates/pages/non_profit/leave_chapter.py
@@ -3,13 +3,5 @@
 def get_context(context):
 	context.no_cache = True
 	chapter = frappe.get_doc('Chapter', frappe.form_dict.name)
-	# if frappe.session.user!='Guest':
-	if frappe.session.user in [d.user for d in chapter.members]:
-		user = frappe.session.user
-		parent = frappe.form_dict.name
-		frappe.db.sql("""delete from `tabChapter Member` where parent = %s and user = %s """, (parent, user))
-		frappe.db.commit()
-
 	context.member_deleted = True
-
 	context.chapter = chapter
diff --git a/erpnext/utilities/transaction_base.py b/erpnext/utilities/transaction_base.py
index 65310aa..01125f9 100644
--- a/erpnext/utilities/transaction_base.py
+++ b/erpnext/utilities/transaction_base.py
@@ -5,7 +5,7 @@
 import frappe
 import frappe.share
 from frappe import _
-from frappe.utils import cstr, now_datetime, cint, flt
+from frappe.utils import cstr, now_datetime, cint, flt, get_time
 from erpnext.controllers.status_updater import StatusUpdater
 
 class UOMMustBeIntegerError(frappe.ValidationError): pass
@@ -26,6 +26,11 @@
 			now = now_datetime()
 			self.posting_date = now.strftime('%Y-%m-%d')
 			self.posting_time = now.strftime('%H:%M:%S.%f')
+		else:
+			try:
+				get_time(self.posting_time)
+			except ValueError:
+				frappe.throw(_('Invalid Posting Time'))
 
 	def add_calendar_event(self, opts, force=False):
 		if cstr(self.contact_by) != cstr(self._prev.contact_by) or \