Merge pull request #12533 from rohitwaghchaure/pos_css_issue

[Fix] POS css
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index d812208..bd400c0 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.9'
+__version__ = '10.0.10'
 
 def get_default_company(user=None):
 	'''Get default company for user'''
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index c457f9a..f6d43c7 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -142,7 +142,7 @@
 
 		self.update_time_sheet(self.name)
 
-		self.update_current_month_sales()
+		update_company_current_month_sales(self.company)
 		self.update_project()
 
 	def validate_pos_paid_amount(self):
@@ -181,16 +181,9 @@
 		self.make_gl_entries_on_cancel()
 		frappe.db.set(self, 'status', 'Cancelled')
 
-		self.update_current_month_sales()
+		update_company_current_month_sales(self.company)
 		self.update_project()
 
-	def update_current_month_sales(self):
-		if frappe.flags.in_test:
-			update_company_current_month_sales(self.company)
-		else:
-			frappe.enqueue('erpnext.setup.doctype.company.company.update_company_current_month_sales',
-				company=self.company)
-
 	def update_status_updater_args(self):
 		if cint(self.update_stock):
 			self.status_updater.extend([{
@@ -675,28 +668,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, is_sale=True)
+					fixed_asset_gl_entries = get_gl_entries_on_asset_disposal(asset, item.base_net_amount)
 					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/report/accounts_receivable_summary/accounts_receivable_summary.js b/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.js
index ceed5e5..96e5d18 100644
--- a/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.js
+++ b/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.js
@@ -23,10 +23,10 @@
 			"options": "Customer Group"
 		},
 		{
-			"fieldname":"credit_days_based_on",
-			"label": __("Credit Days Based On"),
-			"fieldtype": "Select",
-			"options": "\nFixed Days\nLast Day of the Next Month"
+			"fieldname":"payment_terms_template",
+			"label": __("Payment Terms Template"),
+			"fieldtype": "Link",
+			"options": "Payment Terms Template"
 		},
 		{
 			"fieldtype": "Break",
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.html b/erpnext/accounts/report/general_ledger/general_ledger.html
index 91cc3c9..83325aa 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.html
+++ b/erpnext/accounts/report/general_ledger/general_ledger.html
@@ -19,36 +19,66 @@
 		<tr>
 			<th style="width: 15%">{%= __("Date") %}</th>
 			<th style="width: 15%">{%= __("Ref") %}</th>
-			<th style="width: 40%">{%= __("Party") %}</th>
+			<th style="width: 25%">{%= __("Party") %}</th>
 			<th style="width: 15%">{%= __("Debit") %}</th>
 			<th style="width: 15%">{%= __("Credit") %}</th>
+			<th style="width: 15%">{%= __("Balance") %}</th>
 		</tr>
 	</thead>
 	<tbody>
 		{% for(var i=0, l=data.length; i<l; i++) { %}
 			<tr>
-			{% if(data[i][__("Posting Date")]) { %}
-				<td>{%= dateutil.str_to_user(data[i][__("Posting Date")]) %}</td>
-				<td>{%= data[i][__("Voucher Type")] %}
-					<br>{%= data[i][__("Voucher No")] %}</td>
+			{% if(data[i].posting_date) { %}
+				<td>{%= dateutil.str_to_user(data[i].posting_date) %}</td>
+				<td>{%= data[i].voucher_type %}
+					<br>{%= data[i].voucher_no %}</td>
 				<td>
 					{% if(!(filters.party || filters.account)) { %}
-						{%= data[i][__("Party")] || data[i][__("Account")] %}
+						{%= data[i].party || data[i].account %}
 						<br>
 					{% } %}
 
-					{{ __("Against") }}: {%= data[i][__("Against Account")] %}
-					<br>{%= __("Remarks") %}: {%= data[i][__("Remarks")] %}</td>
-				<td style="text-align: right">{%= format_currency(data[i][__("Debit")]) %}</td>
-				<td style="text-align: right">{%= format_currency(data[i][__("Credit")]) %}</td>
+					{{ __("Against") }}: {%= data[i].against %}
+					<br>{%= __("Remarks") %}: {%= data[i].remarks %}
+					{% if(data[i].bill_no) { %}
+						<br>{%= __("Supplier Invoice No") %}: {%= data[i].bill_no %}
+					{% } %}
+					</td>
+				{% if(filters.print_in_account_currency) { %}
+					<td style="text-align: right">
+						{%= format_currency(data[i].debit_in_account_currency, data[i].account_currency) %}
+					</td>
+					<td style="text-align: right">
+						{%= format_currency(data[i].credit_in_account_currency, data[i].account_currency) %}
+					</td>
+				{% } else { %}
+					<td style="text-align: right">
+						{%= format_currency(data[i].debit) %}</td>
+					<td style="text-align: right">
+						{%= format_currency(data[i].credit) %}</td>
+				{% } %}
 			{% } else { %}
 				<td></td>
 				<td></td>
-				<td><b>{%= frappe.format(data[i][__("Account")], {fieldtype: "Link"}) || "&nbsp;" %}</b></td>
-				<td style="text-align: right">
-					{%= data[i][__("Account")] && format_currency(data[i][__("Debit")]) %}</td>
-				<td style="text-align: right">
-					{%= data[i][__("Account")] && format_currency(data[i][__("Credit")]) %}</td>
+				<td><b>{%= frappe.format(data[i].account, {fieldtype: "Link"}) || "&nbsp;" %}</b></td>
+				{% if(filters.print_in_account_currency) { %}
+					<td style="text-align: right">
+						{%= data[i].account && format_currency(data[i].debit_in_account_currency, data[i].account_currency) %}</td>
+					<td style="text-align: right">
+						{%= data[i].account && format_currency(data[i].credit_in_account_currency, data[i].account_currency) %}</td>
+				{% } else { %}
+					<td style="text-align: right">
+						{%= data[i].account && format_currency(data[i].debit) %}
+					</td>
+					<td style="text-align: right">
+						{%= data[i].account && format_currency(data[i].credit) %}
+					</td>
+				{% } %}
+			{% } %}
+			{% if(filters.print_in_account_currency) { %}
+				<td style="text-align: right">{%= data[i].balance_in_account_currency %}</td>
+			{% } else { %}
+				<td style="text-align: right">{%= data[i].balance %}</td>
 			{% } %}
 			</tr>
 		{% } %}
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.js b/erpnext/accounts/report/general_ledger/general_ledger.js
index 282c767..adefadd 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.js
+++ b/erpnext/accounts/report/general_ledger/general_ledger.js
@@ -105,6 +105,11 @@
 			"fieldname":"group_by_account",
 			"label": __("Group by Account"),
 			"fieldtype": "Check",
+		},
+		{
+			"fieldname":"print_in_account_currency",
+			"label": __("Print in Account Currency"),
+			"fieldtype": "Check",
 		}
 	]
 }
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py
index eefb3d1..72fe793 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.py
+++ b/erpnext/accounts/report/general_ledger/general_ledger.py
@@ -3,12 +3,17 @@
 
 from __future__ import unicode_literals
 import frappe
-from frappe.utils import getdate, cstr, flt
+from frappe.utils import getdate, cstr, flt, fmt_money
 from frappe import _, _dict
 from erpnext.accounts.utils import get_account_currency
 
 def execute(filters=None):
 	account_details = {}
+
+	if filters and filters.get('print_in_account_currency') and \
+		not filters.get('account'):
+		frappe.throw(_("Select an account to print in account currency"))
+
 	for acc in frappe.db.sql("""select name, is_group from tabAccount""", as_dict=1):
 		account_details.setdefault(acc.name, acc)
 
@@ -76,28 +81,6 @@
 
 		return filters
 
-def get_columns(filters):
-	columns = [
-		_("Posting Date") + ":Date:90", _("Account") + ":Link/Account:200",
-		_("Debit") + ":Float:100", _("Credit") + ":Float:100"
-	]
-
-	if filters.get("show_in_account_currency"):
-		columns += [
-			_("Debit") + " (" + filters.account_currency + ")" + ":Float:100",
-			_("Credit") + " (" + filters.account_currency + ")" + ":Float:100"
-		]
-
-	columns += [
-		_("Voucher Type") + "::120", _("Voucher No") + ":Dynamic Link/"+_("Voucher Type")+":160",
-		_("Against Account") + "::120", _("Party Type") + "::80", _("Party") + "::150",
-		_("Project") + ":Link/Project:100", _("Cost Center") + ":Link/Cost Center:100",
-		_("Against Voucher Type") + "::120", _("Against Voucher") + ":Dynamic Link/"+_("Against Voucher Type")+":160",
-		_("Remarks") + "::400"
-	]
-
-	return columns
-
 def get_result(filters, account_details):
 	gl_entries = get_gl_entries(filters)
 
@@ -193,24 +176,6 @@
 	# closing
 	data.append(totals.closing)
 
-	#total closing
-	total_closing = totals.total_closing
-	total_debit = totals.closing.get('debit', 0)
-	total_credit = totals.closing.get('credit', 0)
-	debit_in_account_currency = totals.closing.get('debit_in_account_currency', 0)
-	credit_in_account_currency = totals.closing.get('credit_in_account_currency', 0)
-
-	total_amount = total_debit - total_credit
-
-	if total_amount > 0:
-		total_closing['debit'] = total_amount
-		total_closing['debit_in_account_currency'] = debit_in_account_currency - credit_in_account_currency
-	else:
-		total_closing['credit'] = abs(total_amount)
-		total_closing['credit_in_account_currency'] = abs(debit_in_account_currency - credit_in_account_currency)
-
-	data.append(totals.total_closing)
-
 	return data
 
 def get_totals_dict():
@@ -225,8 +190,7 @@
 	return _dict(
 		opening = _get_debit_credit_dict(_('Opening')),
 		total = _get_debit_credit_dict(_('Total')),
-		closing = _get_debit_credit_dict(_('Closing (Opening + Total)')),
-		total_closing = _get_debit_credit_dict(_('Closing Balance (Dr - Cr)'))
+		closing = _get_debit_credit_dict(_('Closing (Opening + Total)'))
 	)
 
 def initialize_gle_map(gl_entries):
@@ -270,17 +234,164 @@
 	return totals, entries
 
 def get_result_as_list(data, filters):
-	result = []
+	balance, balance_in_account_currency = 0, 0
+	inv_details = get_supplier_invoice_details()
+
 	for d in data:
-		row = [d.get("posting_date"), d.get("account"), d.get("debit"), d.get("credit")]
+		if not d.posting_date:
+			balance, balance_in_account_currency = 0, 0
+
+		balance, label = get_balance(d, balance, 'debit', 'credit')
+		d['balance'] = '{0} {1}'.format(fmt_money(abs(balance)), label)
 
 		if filters.get("show_in_account_currency"):
-			row += [d.get("debit_in_account_currency"), d.get("credit_in_account_currency")]
+			balance_in_account_currency, label = get_balance(d, balance_in_account_currency,
+				'debit_in_account_currency', 'credit_in_account_currency')
+			d['balance_in_account_currency'] = '{0} {1}'.format(fmt_money(abs(balance_in_account_currency)), label)
+		else:
+			d['debit_in_account_currency'] = d.get('debit', 0)
+			d['credit_in_account_currency'] = d.get('credit', 0)
+			d['balance_in_account_currency'] = d.get('balance')
 
-		row += [d.get("voucher_type"), d.get("voucher_no"), d.get("against"),
-			d.get("party_type"), d.get("party"), d.get("project"), d.get("cost_center"), d.get("against_voucher_type"), d.get("against_voucher"), d.get("remarks")
-		]
+		d['account_currency'] = filters.account_currency
+		d['bill_no'] = inv_details.get(d.against_voucher, '')
 
-		result.append(row)
+	return data
 
-	return result
+def get_supplier_invoice_details():
+	inv_details = {}
+	for d in frappe.db.sql(""" select name, bill_no from `tabPurchase Invoice`
+		where docstatus = 1 and bill_no is not null and bill_no != '' """, as_dict=1):
+		inv_details[d.name] = d.bill_no
+
+	return inv_details
+
+def get_balance(row, balance, debit_field, credit_field):
+	balance += (row.get(debit_field, 0) -  row.get(credit_field, 0))
+	label = 'DR' if balance > 0 else 'CR'
+
+	return balance, label
+
+def get_columns(filters):
+	columns = [
+		{
+			"label": _("Posting Date"),
+			"fieldname": "posting_date",
+			"fieldtype": "Date",
+			"width": 90
+		},
+		{
+			"label": _("Account"),
+			"fieldname": "account",
+			"fieldtype": "Link",
+			"options": "Account",
+			"width": 180
+		},
+		{
+			"label": _("Debit"),
+			"fieldname": "debit",
+			"fieldtype": "Float",
+			"width": 100
+		},
+		{
+			"label": _("Credit"),
+			"fieldname": "credit",
+			"fieldtype": "Float",
+			"width": 100
+		},
+		{
+			"label": _("Balance"),
+			"fieldname": "balance",
+			"fieldtype": "Data",
+			"width": 100
+		}
+	]
+
+	if filters.get("show_in_account_currency"):
+		columns.extend([
+			{
+				"label": _("Debit") + " (" + filters.account_currency + ")",
+				"fieldname": "debit_in_account_currency",
+				"fieldtype": "Float",
+				"width": 100
+			},
+			{
+				"label": _("Credit") + " (" + filters.account_currency + ")",
+				"fieldname": "credit_in_account_currency",
+				"fieldtype": "Float",
+				"width": 100
+			},
+			{
+				"label": _("Balance") + " (" + filters.account_currency + ")",
+				"fieldname": "balance_in_account_currency",
+				"fieldtype": "Data",
+				"width": 100
+			}
+		])
+
+	columns.extend([
+		{
+			"label": _("Voucher Type"),
+			"fieldname": "voucher_type",
+			"width": 120
+		},
+		{
+			"label": _("Voucher No"),
+			"fieldname": "voucher_no",
+			"fieldtype": "Dynamic Link",
+			"options": "voucher_type",
+			"width": 180
+		},
+		{
+			"label": _("Against Account"),
+			"fieldname": "against",
+			"width": 120
+		},
+		{
+			"label": _("Party Type"),
+			"fieldname": "party_type",
+			"width": 100
+		},
+		{
+			"label": _("Party"),
+			"fieldname": "party",
+			"width": 100
+		},
+		{
+			"label": _("Project"),
+			"options": "Project",
+			"fieldname": "project",
+			"width": 100
+		},
+		{
+			"label": _("Cost Center"),
+			"options": "Cost Center",
+			"fieldname": "cost_center",
+			"width": 100
+		},
+		{
+			"label": _("Against Voucher Type"),
+			"fieldname": "against_voucher_type",
+			"width": 100
+		},
+		{
+			"label": _("Against Voucher"),
+			"fieldname": "against_voucher",
+			"fieldtype": "Dynamic Link",
+			"options": "against_voucher_type",
+			"width": 100
+		},
+		{
+			"label": _("Supplier Invoice No"),
+			"fieldname": "bill_no",
+			"fieldtype": "Data",
+			"width": 100
+		},
+		{
+			"label": _("Remarks"),
+			"fieldname": "remarks",
+			"width": 400
+		}
+	])
+
+	return columns
diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py
index 2bd5cc5..fe3bb8c 100644
--- a/erpnext/accounts/report/gross_profit/gross_profit.py
+++ b/erpnext/accounts/report/gross_profit/gross_profit.py
@@ -6,7 +6,6 @@
 from frappe import _, scrub
 from erpnext.stock.utils import get_incoming_rate
 from erpnext.controllers.queries import get_match_cond
-from erpnext.stock.stock_ledger import get_valuation_rate
 from frappe.utils import flt
 
 
@@ -248,6 +247,7 @@
 		return 0.0
 
 	def get_average_buying_rate(self, row, item_code):
+		args = row
 		if not item_code in self.average_buying_rate:
 			if item_code in self.non_stock_items:
 				self.average_buying_rate[item_code] = flt(frappe.db.sql("""
@@ -255,14 +255,14 @@
 					from `tabPurchase Invoice Item`
 					where item_code = %s and docstatus=1""", item_code)[0][0])
 			else:
-				row.voucher_type = row.parenttype
-				row.voucher_no = row.parent
-				average_buying_rate = get_incoming_rate(row)
-				if not average_buying_rate:
-					average_buying_rate = get_valuation_rate(item_code, row.warehouse,
-						row.parenttype, row.parent, allow_zero_rate=row.allow_zero_valuation,
-						currency=self.filters.currency, company=self.filters.company)
+				args.update({
+					'voucher_type': row.parenttype,
+					'voucher_no': row.parent,
+					'allow_zero_valuation': True,
+					'company': self.filters.company
+				})
 
+				average_buying_rate = get_incoming_rate(args)
 				self.average_buying_rate[item_code] =  flt(average_buying_rate)
 
 		return self.average_buying_rate[item_code]
@@ -311,8 +311,7 @@
 				`tabSales Invoice Item`.brand, `tabSales Invoice Item`.dn_detail,
 				`tabSales Invoice Item`.delivery_note, `tabSales Invoice Item`.stock_qty as qty,
 				`tabSales Invoice Item`.base_net_rate, `tabSales Invoice Item`.base_net_amount,
-				`tabSales Invoice Item`.name as "item_row", `tabSales Invoice`.is_return,
-				`tabSales Invoice Item`.allow_zero_valuation_rate as "allow_zero_valuation"
+				`tabSales Invoice Item`.name as "item_row", `tabSales Invoice`.is_return
 				{sales_person_cols}
 			from
 				`tabSales Invoice` inner join `tabSales Invoice Item`
diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py
index 857aade..8bba0b6 100644
--- a/erpnext/assets/doctype/asset/asset.py
+++ b/erpnext/assets/doctype/asset/asset.py
@@ -51,9 +51,6 @@
 				if not self.get(field):
 					self.set(field, value)
 
-		self.value_after_depreciation = (flt(self.gross_purchase_amount) -
-			flt(self.opening_accumulated_depreciation))
-
 	def validate_asset_values(self):
 		if flt(self.expected_value_after_useful_life) >= flt(self.gross_purchase_amount):
 			frappe.throw(_("Expected Value After Useful Life must be less than Gross Purchase Amount"))
@@ -61,7 +58,10 @@
 		if not flt(self.gross_purchase_amount):
 			frappe.throw(_("Gross Purchase Amount is mandatory"), frappe.MandatoryError)
 
-		if not self.is_existing_asset and self.calculate_depreciation:
+		if not self.calculate_depreciation:
+			return
+
+		if not self.is_existing_asset:
 			self.opening_accumulated_depreciation = 0
 			self.number_of_depreciations_booked = 0
 			if not self.next_depreciation_date:
@@ -81,6 +81,9 @@
 			if cint(self.number_of_depreciations_booked) > cint(self.total_number_of_depreciations):
 				frappe.throw(_("Number of Depreciations Booked cannot be greater than Total Number of Depreciations"))
 
+		self.value_after_depreciation = (flt(self.gross_purchase_amount) -
+			flt(self.opening_accumulated_depreciation))
+
 		if self.next_depreciation_date and getdate(self.next_depreciation_date) < getdate(nowdate()):
 			frappe.msgprint(_("Next Depreciation Date is entered as past date"), title=_('Warning'), indicator='red')
 
@@ -106,12 +109,13 @@
 						n * cint(self.frequency_of_depreciation))
 
 					depreciation_amount = self.get_depreciation_amount(value_after_depreciation)
-					value_after_depreciation -= flt(depreciation_amount)
+					if depreciation_amount:
+						value_after_depreciation -= flt(depreciation_amount)
 
-					self.append("schedules", {
-						"schedule_date": schedule_date,
-						"depreciation_amount": depreciation_amount
-					})
+						self.append("schedules", {
+							"schedule_date": schedule_date,
+							"depreciation_amount": depreciation_amount
+						})
 
 	def set_accumulated_depreciation(self):
 		accumulated_depreciation = flt(self.opening_accumulated_depreciation)
diff --git a/erpnext/assets/doctype/asset/depreciation.py b/erpnext/assets/doctype/asset/depreciation.py
index c72cb96..92a251e 100644
--- a/erpnext/assets/doctype/asset/depreciation.py
+++ b/erpnext/assets/doctype/asset/depreciation.py
@@ -151,13 +151,11 @@
 	asset.set_status()
 
 @frappe.whitelist()
-def get_gl_entries_on_asset_disposal(asset, is_sale=False):
+def get_gl_entries_on_asset_disposal(asset, selling_amount=0):
 	fixed_asset_account, accumulated_depr_account, depr_expense_account = get_depreciation_accounts(asset)
-	accumulated_depr_amount = flt(asset.gross_purchase_amount) - flt(asset.value_after_depreciation)
+	disposal_account, depreciation_cost_center = get_disposal_account_and_cost_center(asset.company)
 
-	expense_account, cost_center = get_disposal_account_and_cost_center(asset.company)
-	if is_sale:
-		expense_account = depr_expense_account
+	accumulated_depr_amount = flt(asset.gross_purchase_amount) - flt(asset.value_after_depreciation)
 
 	gl_entries = [
 		{
@@ -172,12 +170,14 @@
 		}
 	]
 
-	if flt(asset.value_after_depreciation):
+	profit_amount = flt(selling_amount) - flt(asset.value_after_depreciation)
+	if profit_amount:
+		debit_or_credit = "debit" if profit_amount < 0 else "credit"
 		gl_entries.append({
-			"account": expense_account,
-			"cost_center": cost_center,
-			"debit": flt(asset.value_after_depreciation),
-			"debit_in_account_currency": flt(asset.value_after_depreciation)
+			"account": disposal_account,
+			"cost_center": depreciation_cost_center,
+			debit_or_credit: abs(profit_amount),
+			debit_or_credit + "_in_account_currency": abs(profit_amount)
 		})
 
 	return gl_entries
diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py
index 107ffec..76c46cf 100644
--- a/erpnext/assets/doctype/asset/test_asset.py
+++ b/erpnext/assets/doctype/asset/test_asset.py
@@ -234,9 +234,8 @@
 
 		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", 0.0, 25000.0),
+			("_Test Gain/Loss on Asset Disposal - _TC", 45000.0, 0.0),
 			("Debtors - _TC", 25000.0, 0.0)
 		)
 
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 81d2786..8de1a12 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -666,7 +666,7 @@
 			self.remove(item)
 
 	def set_payment_schedule(self):
-		posting_date = self.get("posting_date") or self.get("transaction_date")
+		posting_date = self.get("bill_date") or self.get("posting_date") or self.get("transaction_date")
 		date = self.get("due_date")
 		due_date = date or posting_date
 		grand_total = self.get("rounded_total") or self.grand_total
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index e198c7e..9ee82d2 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -549,7 +549,7 @@
 					final_message = final_message + message1;
 				}
 
-				if (this.frm.doc.payment_schedule.length) {
+				if ((this.frm.doc.payment_schedule || []).length) {
 					message2 = "Payment Schedule Table";
 					if (message1.length !== 0) message2 = " and " + message2;
 					final_message = final_message + message2;
@@ -1261,11 +1261,14 @@
 	payment_terms_template: function() {
 		var me = this;
 		if(this.frm.doc.payment_terms_template) {
+			var posting_date = this.frm.doc.bill_date ||
+				this.frm.doc.posting_date || this.frm.doc.transaction_date;
+
 			frappe.call({
 				method: "erpnext.controllers.accounts_controller.get_payment_terms",
 				args: {
 					terms_template: this.frm.doc.payment_terms_template,
-					posting_date: this.frm.doc.posting_date || this.frm.doc.transaction_date,
+					posting_date: posting_date,
 					grand_total: this.frm.doc.rounded_total || this.frm.doc.grand_total
 				},
 				callback: function(r) {
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index 6c9e450..eaa82b3 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -146,7 +146,8 @@
 			frappe.throw(_("A Customer Group exists with same name please change the Customer name or rename the Customer Group"), frappe.NameError)
 
 	def validate_credit_limit_on_change(self):
-		if self.get("__islocal") or self.credit_limit == frappe.db.get_value("Customer", self.name, "credit_limit"):
+		if self.get("__islocal") or not self.credit_limit \
+			or self.credit_limit == frappe.db.get_value("Customer", self.name, "credit_limit"):
 			return
 
 		for company in frappe.get_all("Company"):
diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js
index 1863fb2..8417642 100644
--- a/erpnext/selling/doctype/quotation/quotation.js
+++ b/erpnext/selling/doctype/quotation/quotation.js
@@ -82,8 +82,8 @@
 						get_query_filters: {
 							status: ["not in", ["Lost", "Closed"]],
 							company: me.frm.doc.company,
-							// cannot set enquiry_type as setter, as the fieldname is order_type
-							enquiry_type: me.frm.doc.order_type,
+							// cannot set opportunity_type as setter, as the fieldname is order_type
+							opportunity_type: me.frm.doc.order_type,
 						}
 					})
 				}, __("Get items from"), "btn-default");
diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py
index cbb747e..ac7c830 100644
--- a/erpnext/setup/doctype/company/company.py
+++ b/erpnext/setup/doctype/company/company.py
@@ -358,7 +358,6 @@
 	monthly_total = results[0]['total'] if len(results) > 0 else 0
 
 	frappe.db.set_value("Company", company, "total_monthly_sales", monthly_total)
-	frappe.db.commit()
 
 def update_company_monthly_sales(company):
 	'''Cache past year monthly sales of every company based on sales invoices'''
@@ -369,7 +368,6 @@
 		"posting_date", filter_str, "sum")
 
 	frappe.db.set_value("Company", company, "sales_monthly_history", json.dumps(month_to_value_dict))
-	frappe.db.commit()
 
 def cache_companies_monthly_sales_history():
 	companies = [d['name'] for d in frappe.get_list("Company")]
diff --git a/erpnext/stock/doctype/material_request/material_request.js b/erpnext/stock/doctype/material_request/material_request.js
index 9eb2313..ed0597c 100644
--- a/erpnext/stock/doctype/material_request/material_request.js
+++ b/erpnext/stock/doctype/material_request/material_request.js
@@ -170,6 +170,8 @@
 							d.description = item.description;
 							d.warehouse = values.warehouse;
 							d.uom = item.stock_uom;
+							d.stock_uom = item.stock_uom;
+							d.conversion_factor = 1;
 							d.qty = item.qty;
 						});
 					}
@@ -282,4 +284,4 @@
 	if(frm.doc.schedule_date){
 		erpnext.utils.copy_value_in_all_row(frm.doc, frm.doc.doctype, frm.doc.name, "items", "schedule_date");
 	}
-}
\ No newline at end of file
+}
diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py
index ae71f35..9b2fcb7 100644
--- a/erpnext/stock/utils.py
+++ b/erpnext/stock/utils.py
@@ -144,10 +144,9 @@
 
 	if not in_rate:
 		voucher_no = args.get('voucher_no') or args.get('name')
-
 		in_rate = get_valuation_rate(args.get('item_code'), args.get('warehouse'),
 			args.get('voucher_type'), voucher_no, args.get('allow_zero_valuation'),
-			currency=erpnext.get_company_currency(args.get('company')))
+			currency=erpnext.get_company_currency(args.get('company')), company=args.get('company'))
 
 	return in_rate
 
diff --git a/erpnext/templates/print_formats/includes/total.html b/erpnext/templates/print_formats/includes/total.html
index df3f49e..c13bf92 100644
--- a/erpnext/templates/print_formats/includes/total.html
+++ b/erpnext/templates/print_formats/includes/total.html
@@ -1,7 +1,7 @@
 <div class="row">
 	{% if doc.flags.show_inclusive_tax_in_print %}
 		<div class="col-xs-5 {%- if doc._align_labels_right %} text-right{%- endif -%}">
-			<label>{{ _("Total Excl. Tax") }}</label></div>
+			<label>{{ _("Total (Without Tax)") }}</label></div>
 		<div class="col-xs-7 text-right">
 			{{ doc.get_formatted("net_total", doc) }}
 		</div>
@@ -12,4 +12,4 @@
 			{{ doc.get_formatted("total", doc) }}
 		</div>
 	{% endif %}
-</div>
\ No newline at end of file
+</div>
diff --git a/erpnext/utilities/user_progress_utils.py b/erpnext/utilities/user_progress_utils.py
index 9d5c258..18d38c0 100644
--- a/erpnext/utilities/user_progress_utils.py
+++ b/erpnext/utilities/user_progress_utils.py
@@ -40,7 +40,7 @@
 @frappe.whitelist()
 def create_letterhead(args_data):
 	args = json.loads(args_data)
-	letterhead = args.get("letterhead")
+	letterhead = args.get("letterhead").encode('utf-8')
 	if letterhead:
 		try:
 			frappe.get_doc({