Merge branch 'master' into develop
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index aa52b83..eb3d0a7 100644
--- a/erpnext/__init__.py
+++ b/erpnext/__init__.py
@@ -4,7 +4,7 @@
 import frappe
 from erpnext.hooks import regional_overrides
 
-__version__ = '9.2.9'
+__version__ = '9.2.10'
 
 def get_default_company(user=None):
 	'''Get default company for user'''
diff --git a/erpnext/accounts/doctype/asset/depreciation.py b/erpnext/accounts/doctype/asset/depreciation.py
index 495433a..c72cb96 100644
--- a/erpnext/accounts/doctype/asset/depreciation.py
+++ b/erpnext/accounts/doctype/asset/depreciation.py
@@ -151,11 +151,14 @@
 	asset.set_status()
 
 @frappe.whitelist()
-def get_gl_entries_on_asset_disposal(asset, selling_amount=0):
+def get_gl_entries_on_asset_disposal(asset, is_sale=False):
 	fixed_asset_account, accumulated_depr_account, depr_expense_account = get_depreciation_accounts(asset)
-	disposal_account, depreciation_cost_center = get_disposal_account_and_cost_center(asset.company)
 	accumulated_depr_amount = flt(asset.gross_purchase_amount) - flt(asset.value_after_depreciation)
 
+	expense_account, cost_center = get_disposal_account_and_cost_center(asset.company)
+	if is_sale:
+		expense_account = depr_expense_account
+
 	gl_entries = [
 		{
 			"account": fixed_asset_account,
@@ -169,14 +172,12 @@
 		}
 	]
 
-	profit_amount = flt(selling_amount) - flt(asset.value_after_depreciation)
-	if flt(asset.value_after_depreciation) and profit_amount:
-		debit_or_credit = "debit" if profit_amount < 0 else "credit"
+	if flt(asset.value_after_depreciation):
 		gl_entries.append({
-			"account": disposal_account,
-			"cost_center": depreciation_cost_center,
-			debit_or_credit: abs(profit_amount),
-			debit_or_credit + "_in_account_currency": abs(profit_amount)
+			"account": expense_account,
+			"cost_center": cost_center,
+			"debit": flt(asset.value_after_depreciation),
+			"debit_in_account_currency": flt(asset.value_after_depreciation)
 		})
 
 	return gl_entries
diff --git a/erpnext/accounts/doctype/asset/test_asset.py b/erpnext/accounts/doctype/asset/test_asset.py
index 831373a..fd66d1f 100644
--- a/erpnext/accounts/doctype/asset/test_asset.py
+++ b/erpnext/accounts/doctype/asset/test_asset.py
@@ -188,7 +188,6 @@
 		asset.load_from_db()
 		depr_entry = asset.get("schedules")[0].journal_entry
 		self.assertFalse(depr_entry)
-		
 
 	def test_scrap_asset(self):
 		asset = frappe.get_doc("Asset", "Macbook Pro 1")
@@ -234,8 +233,9 @@
 
 		expected_gle = (
 			("_Test Accumulated Depreciations - _TC", 30000.0, 0.0),
+			("_Test Depreciations - _TC", 70000.0, 0.0),
 			("_Test Fixed Asset - _TC", 0.0, 100000.0),
-			("_Test Gain/Loss on Asset Disposal - _TC", 45000.0, 0.0),
+			("_Test Gain/Loss on Asset Disposal - _TC", 0.0, 25000.0),
 			("Debtors - _TC", 25000.0, 0.0)
 		)
 
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js
index 52d8a2d..c5e0306 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.js
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js
@@ -252,7 +252,6 @@
 					date: frm.doc.posting_date
 				},
 				callback: function(r, rt) {
-					console.log(r, rt);
 					if(r.message) {
 						if(frm.doc.payment_type == "Receive") {
 							frm.set_value("paid_from", r.message.party_account);
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index 995a333..db9969d 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -670,28 +670,28 @@
 		# income account gl entries
 		for item in self.get("items"):
 			if flt(item.base_net_amount):
+				account_currency = get_account_currency(item.income_account)
+				gl_entries.append(
+					self.get_gl_dict({
+						"account": item.income_account,
+						"against": self.customer,
+						"credit": item.base_net_amount,
+						"credit_in_account_currency": item.base_net_amount \
+							if account_currency==self.company_currency else item.net_amount,
+						"cost_center": item.cost_center
+					}, account_currency)
+				)
+
 				if item.is_fixed_asset:
 					asset = frappe.get_doc("Asset", item.asset)
 
-					fixed_asset_gl_entries = get_gl_entries_on_asset_disposal(asset, item.base_net_amount)
+					fixed_asset_gl_entries = get_gl_entries_on_asset_disposal(asset, is_sale=True)
 					for gle in fixed_asset_gl_entries:
 						gle["against"] = self.customer
 						gl_entries.append(self.get_gl_dict(gle))
 
 					asset.db_set("disposal_date", self.posting_date)
 					asset.set_status("Sold" if self.docstatus==1 else None)
-				else:
-					account_currency = get_account_currency(item.income_account)
-					gl_entries.append(
-						self.get_gl_dict({
-							"account": item.income_account,
-							"against": self.customer,
-							"credit": item.base_net_amount,
-							"credit_in_account_currency": item.base_net_amount \
-								if account_currency==self.company_currency else item.net_amount,
-							"cost_center": item.cost_center
-						}, account_currency)
-					)
 
 		# expense account gl entries
 		if cint(self.update_stock) and \
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index ce049f5..f655830 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -176,29 +176,34 @@
 	if not company:
 		frappe.throw(_("Please select a Company"))
 
-	if party:
+	if not party:
+		return
+
+	account = frappe.db.get_value("Party Account",
+		{"parenttype": party_type, "parent": party, "company": company}, "account")
+
+	if not account and party_type in ['Customer', 'Supplier']:
+		party_group_doctype = "Customer Group" if party_type=="Customer" else "Supplier Type"
+		group = frappe.db.get_value(party_type, party, scrub(party_group_doctype))
 		account = frappe.db.get_value("Party Account",
-			{"parenttype": party_type, "parent": party, "company": company}, "account")
+			{"parenttype": party_group_doctype, "parent": group, "company": company}, "account")
 
-		if not account and party_type in ['Customer', 'Supplier']:
-			party_group_doctype = "Customer Group" if party_type=="Customer" else "Supplier Type"
-			group = frappe.db.get_value(party_type, party, scrub(party_group_doctype))
-			account = frappe.db.get_value("Party Account",
-				{"parenttype": party_group_doctype, "parent": group, "company": company}, "account")
+	if not account and party_type in ['Customer', 'Supplier']:
+		default_account_name = "default_receivable_account" \
+			if party_type=="Customer" else "default_payable_account"
+		account = frappe.db.get_value("Company", company, default_account_name)
 
-		if not account and party_type in ['Customer', 'Supplier']:
-			default_account_name = "default_receivable_account" \
-				if party_type=="Customer" else "default_payable_account"
-			account = frappe.db.get_value("Company", company, default_account_name)
+	existing_gle_currency = get_party_gle_currency(party_type, party, company)
+	if existing_gle_currency:
+		if account:
+			account_currency = frappe.db.get_value("Account", account, "account_currency")
+		if (account and account_currency != existing_gle_currency) or not account:
+				account = get_party_gle_account(party_type, party, company)
 
-		existing_gle_currency = get_party_gle_currency(party_type, party, company)
-		if existing_gle_currency:
-			if account:
-				account_currency = frappe.db.get_value("Account", account, "account_currency")
-			if (account and account_currency != existing_gle_currency) or not account:
-					account = get_party_gle_account(party_type, party, company)
+	if not account:
+		frappe.throw(_("Party account not specified, please setup default party account in company"))
 
-		return account
+	return account
 
 def get_party_account_currency(party_type, party, company):
 	def generator():
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 0003990..a8fd5e9 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -593,7 +593,7 @@
 				select ifnull(sum({payment_dr_or_cr}), 0)
 				from `tabGL Entry` payment_gl_entry
 				where payment_gl_entry.against_voucher_type = invoice_gl_entry.voucher_type
-					and payment_gl_entry.against_voucher = invoice_gl_entry.voucher_no
+					and payment_gl_entry.against_voucher = invoice_gl_entry.against_voucher
 					and payment_gl_entry.party_type = invoice_gl_entry.party_type
 					and payment_gl_entry.party = invoice_gl_entry.party
 					and payment_gl_entry.account = invoice_gl_entry.account
diff --git a/erpnext/schools/doctype/fee_schedule/fee_schedule.py b/erpnext/schools/doctype/fee_schedule/fee_schedule.py
index fc2907a..3e1dd0c 100644
--- a/erpnext/schools/doctype/fee_schedule/fee_schedule.py
+++ b/erpnext/schools/doctype/fee_schedule/fee_schedule.py
@@ -9,6 +9,7 @@
 from frappe.utils import money_in_words
 from frappe.utils import cint, flt, cstr
 from frappe.utils.background_jobs import enqueue
+from frappe import _
 
 
 class FeeSchedule(Document):
@@ -57,6 +58,10 @@
 	error = False
 	total_records = sum([int(d.total_students) for d in doc.student_groups])
 	created_records = 0
+
+	if not total_records:
+		frappe.throw(_("Please setup Students under Student Groups"))
+
 	for d in doc.student_groups:
 		students = frappe.db.sql(""" select sg.program, sg.batch, sgs.student, sgs.student_name
 			from `tabStudent Group` sg, `tabStudent Group Student` sgs