Merge branch '4.0.0-wip' of github.com:webnotes/erpnext into 4.0.0-cleanup
diff --git a/erpnext/accounts/doctype/journal_voucher/journal_voucher.py b/erpnext/accounts/doctype/journal_voucher/journal_voucher.py
index 4d00dfd..c9ca0c2 100644
--- a/erpnext/accounts/doctype/journal_voucher/journal_voucher.py
+++ b/erpnext/accounts/doctype/journal_voucher/journal_voucher.py
@@ -42,7 +42,6 @@
 	def on_submit(self):
 		if self.doc.voucher_type in ['Bank Voucher', 'Contra Voucher', 'Journal Entry']:
 			self.check_credit_days()
-		self.check_account_against_entries()
 		self.make_gl_entries()
 		self.check_credit_limit()
 
@@ -232,14 +231,20 @@
 		for d in self.doclist.get({"parentfield": "entries"}):
 			if d.against_invoice and webnotes.conn.get_value("Sales Invoice", 
 					d.against_invoice, "debit_to") != d.account:
-				webnotes.throw(_("Credited account (Customer) is not matching with Sales Invoice"))
+				webnotes.throw(_("Row #") + cstr(d.idx) +  ": " +
+					_("Account is not matching with Debit To account of Sales Invoice"))
 			
 			if d.against_voucher and webnotes.conn.get_value("Purchase Invoice", 
-						d.against_voucher, "credit_to") != d.account:
-				webnotes.throw(_("Debited account (Supplier) is not matching with Purchase Invoice"))
+					d.against_voucher, "credit_to") != d.account:
+				webnotes.throw(_("Row #") + cstr(d.idx) + ": " +
+					_("Account is not matching with Credit To account of Purchase Invoice"))
 
 	def make_gl_entries(self, cancel=0, adv_adj=0):
 		from erpnext.accounts.general_ledger import make_gl_entries
+		
+		if not cancel:
+			self.check_account_against_entries()
+		
 		gl_map = []
 		for d in self.doclist.get({"parentfield": "entries"}):
 			if d.debit or d.credit:
diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
index 478ed3c..c68b97a 100644
--- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
@@ -364,7 +364,6 @@
 			from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
 			order by account asc, debit asc""", si.doc.name, as_dict=1)
 		self.assertTrue(gl_entries)
-		# print gl_entries
 		
 		stock_in_hand = webnotes.conn.get_value("Account", {"master_name": "_Test Warehouse - _TC"})
 				
diff --git a/erpnext/accounts/doctype/sales_invoice_advance/sales_invoice_advance.txt b/erpnext/accounts/doctype/sales_invoice_advance/sales_invoice_advance.txt
index ad1a9eb..9ae37cf 100644
--- a/erpnext/accounts/doctype/sales_invoice_advance/sales_invoice_advance.txt
+++ b/erpnext/accounts/doctype/sales_invoice_advance/sales_invoice_advance.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-02-22 01:27:41", 
   "docstatus": 0, 
-  "modified": "2013-12-20 19:21:40", 
+  "modified": "2013-12-31 18:29:19", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -15,7 +15,6 @@
  {
   "doctype": "DocField", 
   "name": "__common__", 
-  "no_copy": 1, 
   "parent": "Sales Invoice Advance", 
   "parentfield": "fields", 
   "parenttype": "DocType", 
@@ -31,6 +30,7 @@
   "fieldtype": "Link", 
   "in_list_view": 1, 
   "label": "Journal Voucher", 
+  "no_copy": 1, 
   "oldfieldname": "journal_voucher", 
   "oldfieldtype": "Link", 
   "options": "Journal Voucher", 
@@ -40,24 +40,11 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "jv_detail_no", 
-  "fieldtype": "Data", 
-  "hidden": 1, 
-  "in_list_view": 0, 
-  "label": "Journal Voucher Detail No", 
-  "oldfieldname": "jv_detail_no", 
-  "oldfieldtype": "Data", 
-  "print_hide": 1, 
-  "print_width": "120px", 
-  "read_only": 1, 
-  "width": "120px"
- }, 
- {
-  "doctype": "DocField", 
   "fieldname": "advance_amount", 
   "fieldtype": "Currency", 
   "in_list_view": 1, 
   "label": "Advance amount", 
+  "no_copy": 1, 
   "oldfieldname": "advance_amount", 
   "oldfieldtype": "Currency", 
   "options": "Company:company:default_currency", 
@@ -71,6 +58,7 @@
   "fieldtype": "Currency", 
   "in_list_view": 1, 
   "label": "Allocated amount", 
+  "no_copy": 1, 
   "oldfieldname": "allocated_amount", 
   "oldfieldtype": "Currency", 
   "options": "Company:company:default_currency", 
@@ -79,14 +67,35 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "col_break1", 
+  "fieldtype": "Column Break"
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "remarks", 
   "fieldtype": "Small Text", 
   "in_list_view": 1, 
   "label": "Remarks", 
+  "no_copy": 1, 
   "oldfieldname": "remarks", 
   "oldfieldtype": "Small Text", 
   "print_width": "150px", 
   "read_only": 1, 
   "width": "150px"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "jv_detail_no", 
+  "fieldtype": "Data", 
+  "hidden": 1, 
+  "in_list_view": 0, 
+  "label": "Journal Voucher Detail No", 
+  "no_copy": 1, 
+  "oldfieldname": "jv_detail_no", 
+  "oldfieldtype": "Data", 
+  "print_hide": 1, 
+  "print_width": "120px", 
+  "read_only": 1, 
+  "width": "120px"
  }
 ]
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.txt b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.txt
index 339115d..4d7ae0c 100644
--- a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.txt
+++ b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-06-04 11:02:19", 
   "docstatus": 0, 
-  "modified": "2013-12-20 19:21:40", 
+  "modified": "2013-12-31 18:27:41", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -51,16 +51,6 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "customer_item_code", 
-  "fieldtype": "Data", 
-  "hidden": 1, 
-  "in_list_view": 0, 
-  "label": "Customer's Item Code", 
-  "print_hide": 1, 
-  "read_only": 1
- }, 
- {
-  "doctype": "DocField", 
   "fieldname": "item_name", 
   "fieldtype": "Data", 
   "in_filter": 0, 
@@ -75,6 +65,21 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "col_break1", 
+  "fieldtype": "Column Break"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "customer_item_code", 
+  "fieldtype": "Data", 
+  "hidden": 1, 
+  "in_list_view": 0, 
+  "label": "Customer's Item Code", 
+  "print_hide": 1, 
+  "read_only": 1
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "description", 
   "fieldtype": "Text", 
   "in_list_view": 1, 
@@ -106,15 +111,6 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "stock_uom", 
-  "fieldtype": "Link", 
-  "in_list_view": 0, 
-  "label": "UOM", 
-  "options": "UOM", 
-  "read_only": 1
- }, 
- {
-  "doctype": "DocField", 
   "fieldname": "ref_rate", 
   "fieldtype": "Currency", 
   "in_list_view": 0, 
@@ -139,6 +135,37 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "col_break2", 
+  "fieldtype": "Column Break"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "stock_uom", 
+  "fieldtype": "Link", 
+  "in_list_view": 0, 
+  "label": "UOM", 
+  "options": "UOM", 
+  "read_only": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "base_ref_rate", 
+  "fieldtype": "Currency", 
+  "in_list_view": 0, 
+  "label": "Price List Rate (Company Currency)", 
+  "oldfieldname": "base_ref_rate", 
+  "oldfieldtype": "Currency", 
+  "options": "Company:company:default_currency", 
+  "print_hide": 1, 
+  "read_only": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "section_break1", 
+  "fieldtype": "Section Break"
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "export_rate", 
   "fieldtype": "Currency", 
   "in_list_view": 1, 
@@ -163,15 +190,8 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "base_ref_rate", 
-  "fieldtype": "Currency", 
-  "in_list_view": 0, 
-  "label": "Price List Rate (Company Currency)", 
-  "oldfieldname": "base_ref_rate", 
-  "oldfieldtype": "Currency", 
-  "options": "Company:company:default_currency", 
-  "print_hide": 1, 
-  "read_only": 1
+  "fieldname": "col_break3", 
+  "fieldtype": "Column Break"
  }, 
  {
   "doctype": "DocField", 
@@ -238,6 +258,11 @@
   "width": "120px"
  }, 
  {
+  "doctype": "DocField", 
+  "fieldname": "col_break4", 
+  "fieldtype": "Column Break"
+ }, 
+ {
   "default": ":Company", 
   "doctype": "DocField", 
   "fieldname": "cost_center", 
@@ -324,6 +349,22 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "item_tax_rate", 
+  "fieldtype": "Small Text", 
+  "hidden": 1, 
+  "label": "Item Tax Rate", 
+  "oldfieldname": "item_tax_rate", 
+  "oldfieldtype": "Small Text", 
+  "print_hide": 1, 
+  "read_only": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "col_break5", 
+  "fieldtype": "Column Break"
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "actual_qty", 
   "fieldtype": "Float", 
   "label": "Available Qty at Warehouse", 
@@ -334,13 +375,11 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "delivered_qty", 
-  "fieldtype": "Float", 
-  "label": "Delivered Qty", 
-  "oldfieldname": "delivered_qty", 
-  "oldfieldtype": "Currency", 
-  "print_hide": 1, 
-  "read_only": 1
+  "fieldname": "time_log_batch", 
+  "fieldtype": "Link", 
+  "label": "Time Log Batch", 
+  "options": "Time Log Batch", 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -400,20 +439,11 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "time_log_batch", 
-  "fieldtype": "Link", 
-  "label": "Time Log Batch", 
-  "options": "Time Log Batch", 
-  "read_only": 0
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "item_tax_rate", 
-  "fieldtype": "Small Text", 
-  "hidden": 1, 
-  "label": "Item Tax Rate", 
-  "oldfieldname": "item_tax_rate", 
-  "oldfieldtype": "Small Text", 
+  "fieldname": "delivered_qty", 
+  "fieldtype": "Float", 
+  "label": "Delivered Qty", 
+  "oldfieldname": "delivered_qty", 
+  "oldfieldtype": "Currency", 
   "print_hide": 1, 
   "read_only": 1
  }, 
diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.txt b/erpnext/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.txt
index ab4da2a..49df5f7 100644
--- a/erpnext/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.txt
+++ b/erpnext/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-04-24 11:39:32", 
   "docstatus": 0, 
-  "modified": "2013-12-20 19:21:45", 
+  "modified": "2013-12-31 17:51:47", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -48,6 +48,24 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "description", 
+  "fieldtype": "Small Text", 
+  "in_list_view": 1, 
+  "label": "Description", 
+  "oldfieldname": "description", 
+  "oldfieldtype": "Small Text", 
+  "print_width": "300px", 
+  "reqd": 1, 
+  "width": "300px"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "col_break_1", 
+  "fieldtype": "Column Break", 
+  "width": "50%"
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "account_head", 
   "fieldtype": "Link", 
   "in_list_view": 0, 
@@ -71,36 +89,6 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "description", 
-  "fieldtype": "Small Text", 
-  "in_list_view": 1, 
-  "label": "Description", 
-  "oldfieldname": "description", 
-  "oldfieldtype": "Small Text", 
-  "print_width": "300px", 
-  "reqd": 1, 
-  "width": "300px"
- }, 
- {
-  "allow_on_submit": 0, 
-  "description": "If checked, the tax amount will be considered as already included in the Print Rate / Print Amount", 
-  "doctype": "DocField", 
-  "fieldname": "included_in_print_rate", 
-  "fieldtype": "Check", 
-  "label": "Is this Tax included in Basic Rate?", 
-  "no_copy": 0, 
-  "print_hide": 1, 
-  "print_width": "150px", 
-  "report_hide": 1, 
-  "width": "150px"
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "section_break_6", 
-  "fieldtype": "Section Break"
- }, 
- {
-  "doctype": "DocField", 
   "fieldname": "rate", 
   "fieldtype": "Float", 
   "in_list_view": 1, 
@@ -132,6 +120,19 @@
   "read_only": 1
  }, 
  {
+  "allow_on_submit": 0, 
+  "description": "If checked, the tax amount will be considered as already included in the Print Rate / Print Amount", 
+  "doctype": "DocField", 
+  "fieldname": "included_in_print_rate", 
+  "fieldtype": "Check", 
+  "label": "Is this Tax included in Basic Rate?", 
+  "no_copy": 0, 
+  "print_hide": 1, 
+  "print_width": "150px", 
+  "report_hide": 1, 
+  "width": "150px"
+ }, 
+ {
   "doctype": "DocField", 
   "fieldname": "item_wise_tax_detail", 
   "fieldtype": "Small Text", 
diff --git a/erpnext/accounts/report/accounts_payable/accounts_payable.py b/erpnext/accounts/report/accounts_payable/accounts_payable.py
index 070148b..adb126b 100644
--- a/erpnext/accounts/report/accounts_payable/accounts_payable.py
+++ b/erpnext/accounts/report/accounts_payable/accounts_payable.py
@@ -19,8 +19,8 @@
 		for gle in get_gl_entries(filters, before_report_date=False)]
 	
 	account_supplier_type_map = get_account_supplier_type_map()
-	pi_map = get_pi_map()
-
+	voucher_detail_map = get_voucher_details()
+	
 	# Age of the invoice on this date
 	age_on = getdate(filters.get("report_date")) > getdate(nowdate()) \
 		and nowdate() or filters.get("report_date")
@@ -29,14 +29,8 @@
 	for gle in entries:
 		if cstr(gle.against_voucher) == gle.voucher_no or not gle.against_voucher \
 				or [gle.against_voucher_type, gle.against_voucher] in entries_after_report_date:
-			if gle.voucher_type == "Purchase Invoice":
-				pi_info = pi_map.get(gle.voucher_no)
-				due_date = pi_info.get("due_date")
-				bill_no = pi_info.get("bill_no")
-				bill_date = pi_info.get("bill_date")
-			else:
-				due_date = bill_no = bill_date = ""
-		
+			voucher_details = voucher_detail_map.get(gle.voucher_type, {}).get(gle.voucher_no, {})
+			
 			invoiced_amount = gle.credit > 0 and gle.credit or 0
 			outstanding_amount = get_outstanding_amount(gle, 
 				filters.get("report_date") or nowdate())
@@ -44,13 +38,15 @@
 			if abs(flt(outstanding_amount)) > 0.01:
 				paid_amount = invoiced_amount - outstanding_amount
 				row = [gle.posting_date, gle.account, account_supplier.get(gle.account, ""),
-					gle.voucher_type, gle.voucher_no, 
-					gle.remarks, account_supplier_type_map.get(gle.account), due_date, bill_no, 
-					bill_date, invoiced_amount, paid_amount, outstanding_amount]
+					gle.voucher_type, gle.voucher_no, gle.remarks, 
+					account_supplier_type_map.get(gle.account), 
+					voucher_details.get("due_date", ""), voucher_details.get("bill_no", ""), 
+					voucher_details.get("bill_date", ""), invoiced_amount, 
+					paid_amount, outstanding_amount]
 				
 				# Ageing
 				if filters.get("ageing_based_on") == "Due Date":
-					ageing_based_on_date = due_date
+					ageing_based_on_date = voucher_details.get("due_date", "")
 				else:
 					ageing_based_on_date = gle.posting_date
 					
@@ -111,14 +107,15 @@
 		
 	return account_supplier_type_map
 	
-def get_pi_map():
-	""" get due_date from sales invoice """
-	pi_map = {}
-	for t in webnotes.conn.sql("""select name, due_date, bill_no, bill_date 
-			from `tabPurchase Invoice`""", as_dict=1):
-		pi_map[t.name] = t
+def get_voucher_details():
+	voucher_details = {}
+	for dt in ["Purchase Invoice", "Journal Voucher"]:
+		voucher_details.setdefault(dt, webnotes._dict())
+		for t in webnotes.conn.sql("""select name, due_date, bill_no, bill_date 
+				from `tab%s`""" % dt, as_dict=1):
+			voucher_details[dt].setdefault(t.name, t)
 		
-	return pi_map
+	return voucher_details
 
 def get_outstanding_amount(gle, report_date):
 	payment_amount = webnotes.conn.sql("""
diff --git a/erpnext/accounts/report/accounts_payable/general_ledger/general_ledger.py b/erpnext/accounts/report/accounts_payable/general_ledger/general_ledger.py
deleted file mode 100644
index 575ccda..0000000
--- a/erpnext/accounts/report/accounts_payable/general_ledger/general_ledger.py
+++ /dev/null
@@ -1,111 +0,0 @@
-# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
-# License: GNU General Public License v3. See license.txt
-
-from __future__ import unicode_literals
-import webnotes
-from webnotes.utils import flt, add_days
-from webnotes import _
-from erpnext.accounts.utils import get_balance_on
-
-def execute(filters=None):
-	account_details = webnotes.conn.get_value("Account", filters["account"], 
-		["debit_or_credit", "group_or_ledger"], as_dict=True) if filters.get("account") else None
-	validate_filters(filters, account_details)
-	
-	columns = get_columns()
-	data = []
-	if filters.get("group_by"):
-		data += get_grouped_gle(filters)
-	else:
-		data += get_gl_entries(filters)
-		if data:
-			data.append(get_total_row(data))
-
-	if account_details:
-		data = [get_opening_balance_row(filters, account_details.debit_or_credit)] + data + \
-			[get_closing_balance_row(filters, account_details.debit_or_credit)]
-
-	return columns, data
-	
-def validate_filters(filters, account_details):
-	if account_details and account_details.group_or_ledger == "Ledger" \
-			and filters.get("group_by") == "Group by Account":
-		webnotes.throw(_("Can not filter based on Account, if grouped by Account"))
-		
-	if filters.get("voucher_no") and filters.get("group_by") == "Group by Voucher":
-		webnotes.throw(_("Can not filter based on Voucher No, if grouped by Voucher"))
-	
-def get_columns():
-	return ["Posting Date:Date:100", "Account:Link/Account:200", "Debit:Float:100", 
-		"Credit:Float:100", "Voucher Type::120", "Voucher No::160", "Link::20", 
-		"Cost Center:Link/Cost Center:100", "Remarks::200"]
-		
-def get_opening_balance_row(filters, debit_or_credit):
-	opening_balance = get_balance_on(filters["account"], add_days(filters["from_date"], -1))
-	return get_balance_row(opening_balance, debit_or_credit, "Opening Balance")
-	
-def get_closing_balance_row(filters, debit_or_credit):
-	closing_balance = get_balance_on(filters["account"], filters["to_date"])
-	return get_balance_row(closing_balance, debit_or_credit, "Closing Balance")
-	
-def get_balance_row(balance, debit_or_credit, balance_label):
-	if debit_or_credit == "Debit":
-		return ["", balance_label, balance, 0.0, "", "", ""]
-	else:
-		return ["", balance_label, 0.0, balance, "", "", ""]
-		
-def get_gl_entries(filters):
-	gl_entries = webnotes.conn.sql("""select 
-			posting_date, account, debit, credit, voucher_type, voucher_no, cost_center, remarks 
-		from `tabGL Entry`
-		where company=%(company)s 
-			and posting_date between %(from_date)s and %(to_date)s
-			{conditions}
-		order by posting_date, account"""\
-		.format(conditions=get_conditions(filters)), filters, as_list=1)
-		
-	for d in gl_entries:
-		icon = """<a href="%s"><i class="icon icon-share" style="cursor: pointer;"></i></a>""" \
-			% ("/".join(["#Form", d[4], d[5]]),)
-		d.insert(6, icon)
-		
-	return gl_entries
-			
-def get_conditions(filters):
-	conditions = []
-	if filters.get("account"):
-		lft, rgt = webnotes.conn.get_value("Account", filters["account"], ["lft", "rgt"])
-		conditions.append("""account in (select name from tabAccount 
-			where lft>=%s and rgt<=%s and docstatus<2)""" % (lft, rgt))
-	if filters.get("voucher_no"):
-		conditions.append("voucher_no=%(voucher_no)s")
-	
-	return "and {}".format(" and ".join(conditions)) if conditions else ""
-		
-def get_grouped_gle(filters):
-	gle_map = {}
-	gle = get_gl_entries(filters)
-	for d in gle:
-		gle_map.setdefault(d[1 if filters["group_by"]=="Group by Account" else 5], []).append(d)
-		
-	data = []
-	for entries in gle_map.values():
-		subtotal_debit = subtotal_credit = 0.0
-		for entry in entries:
-			data.append(entry)
-			subtotal_debit += flt(entry[2])
-			subtotal_credit += flt(entry[3])
-		
-		data.append(["", "Total", subtotal_debit, subtotal_credit, "", "", ""])
-	
-	if data:
-		data.append(get_total_row(gle))
-	return data
-	
-def get_total_row(gle):
-	total_debit = total_credit = 0.0
-	for d in gle:
-		total_debit += flt(d[2])
-		total_credit += flt(d[3])
-		
-	return ["", "Total Debit/Credit", total_debit, total_credit, "", "", ""]
\ No newline at end of file
diff --git a/erpnext/accounts/report/accounts_payable/general_ledger/__init__.py b/erpnext/accounts/report/general_ledger/__init__.py
similarity index 100%
rename from erpnext/accounts/report/accounts_payable/general_ledger/__init__.py
rename to erpnext/accounts/report/general_ledger/__init__.py
diff --git a/erpnext/accounts/report/accounts_payable/general_ledger/general_ledger.js b/erpnext/accounts/report/general_ledger/general_ledger.js
similarity index 67%
rename from erpnext/accounts/report/accounts_payable/general_ledger/general_ledger.js
rename to erpnext/accounts/report/general_ledger/general_ledger.js
index 7985277..96682f9 100644
--- a/erpnext/accounts/report/accounts_payable/general_ledger/general_ledger.js
+++ b/erpnext/accounts/report/general_ledger/general_ledger.js
@@ -12,26 +12,6 @@
 			"reqd": 1
 		},
 		{
-			"fieldname":"account",
-			"label": wn._("Account"),
-			"fieldtype": "Link",
-			"options": "Account"
-		},
-		{
-			"fieldname":"voucher_no",
-			"label": wn._("Voucher No"),
-			"fieldtype": "Data",
-		},
-		{
-			"fieldname":"group_by",
-			"label": wn._("Group by"),
-			"fieldtype": "Select",
-			"options": "\nGroup by Account\nGroup by Voucher"
-		},
-		{
-			"fieldtype": "Break",
-		},
-		{
 			"fieldname":"from_date",
 			"label": wn._("From Date"),
 			"fieldtype": "Date",
@@ -46,6 +26,40 @@
 			"default": wn.datetime.get_today(),
 			"reqd": 1,
 			"width": "60px"
+		},
+		{
+			"fieldtype": "Break",
+		},
+		{
+			"fieldname":"account",
+			"label": wn._("Account"),
+			"fieldtype": "Link",
+			"options": "Account",
+			"get_query": function() {
+				var company = wn.query_report.filters_by_name.company.get_value();
+				return {
+					"doctype": "Account", 
+					"filters": {
+						"company": company,
+					}
+				}
+			}
+		},
+		{
+			"fieldname":"voucher_no",
+			"label": wn._("Voucher No"),
+			"fieldtype": "Data",
+		},
+		{
+			"fieldname":"group_by_voucher",
+			"label": wn._("Group by Voucher"),
+			"fieldtype": "Check",
+			"default": 1
+		},
+		{
+			"fieldname":"group_by_account",
+			"label": wn._("Group by Account"),
+			"fieldtype": "Check",
 		}
 	]
 }
\ No newline at end of file
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py
new file mode 100644
index 0000000..acfe6a0
--- /dev/null
+++ b/erpnext/accounts/report/general_ledger/general_ledger.py
@@ -0,0 +1,172 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import webnotes
+from webnotes.utils import cstr, flt
+from webnotes import _
+
+def execute(filters=None):
+	account_details = {}
+	for acc in webnotes.conn.sql("""select name, debit_or_credit, group_or_ledger 
+		from tabAccount""", as_dict=1):
+			account_details.setdefault(acc.name, acc)
+	
+	validate_filters(filters, account_details)
+	
+	columns = get_columns()
+	
+	res = get_result(filters, account_details)
+
+	return columns, res
+	
+def validate_filters(filters, account_details):
+	if filters.get("account") and filters.get("group_by_account") \
+			and account_details[filters.account].group_or_ledger == "Ledger":
+		webnotes.throw(_("Can not filter based on Account, if grouped by Account"))
+		
+	if filters.get("voucher_no") and filters.get("group_by_voucher"):
+		webnotes.throw(_("Can not filter based on Voucher No, if grouped by Voucher"))
+		
+	if filters.from_date > filters.to_date:
+		webnotes.throw(_("From Date must be before To Date"))
+	
+def get_columns():
+	return ["Posting Date:Date:100", "Account:Link/Account:200", "Debit:Float:100", 
+		"Credit:Float:100", "Voucher Type::120", "Voucher No::160", "Link::20", 
+		"Against Account::120", "Cost Center:Link/Cost Center:100", "Remarks::200"]
+		
+def get_result(filters, account_details):	
+	gl_entries = get_gl_entries(filters)
+
+	data = get_data_with_opening_closing(filters, account_details, gl_entries)
+		
+	result = get_result_as_list(data)
+
+	return result
+	
+def get_gl_entries(filters):
+	group_by_condition = "group by voucher_type, voucher_no, account" \
+		if filters.get("group_by_voucher") else "group by name"
+		
+	gl_entries = webnotes.conn.sql("""select posting_date, account, 
+			sum(ifnull(debit, 0)) as debit, sum(ifnull(credit, 0)) as credit, 
+			voucher_type, voucher_no, cost_center, remarks, is_advance, against 
+		from `tabGL Entry`
+		where company=%(company)s {conditions}
+		{group_by_condition}
+		order by posting_date, account"""\
+		.format(conditions=get_conditions(filters), group_by_condition=group_by_condition), 
+		filters, as_dict=1)
+		
+	return gl_entries
+	
+def get_conditions(filters):
+	conditions = []
+	if filters.get("account"):
+		lft, rgt = webnotes.conn.get_value("Account", filters["account"], ["lft", "rgt"])
+		conditions.append("""account in (select name from tabAccount 
+			where lft>=%s and rgt<=%s and docstatus<2)""" % (lft, rgt))
+	else:
+		conditions.append("posting_date between %(from_date)s and %(to_date)s")
+		
+	if filters.get("voucher_no"):
+		conditions.append("voucher_no=%(voucher_no)s")
+	
+	return "and {}".format(" and ".join(conditions)) if conditions else ""
+
+def get_data_with_opening_closing(filters, account_details, gl_entries):
+	data = []
+	gle_map = initialize_gle_map(gl_entries)
+	
+	opening, total_debit, total_credit, gle_map = get_accountwise_gle(filters, gl_entries, gle_map)
+	
+	# Opening for filtered account
+	if filters.get("account"):
+		data += [get_balance_row("Opening", account_details[filters.account].debit_or_credit, 
+			opening), {}]
+
+	for acc, acc_dict in gle_map.items():
+		if acc_dict.entries:
+			# Opening for individual ledger, if grouped by account
+			if filters.get("group_by_account"):
+				data.append(get_balance_row("Opening", account_details[acc].debit_or_credit, 
+					acc_dict.opening))
+
+			data += acc_dict.entries
+			
+			# Totals and closing for individual ledger, if grouped by account
+			if filters.get("group_by_account"):
+				data += [{"account": "Totals", "debit": acc_dict.total_debit, 
+					"credit": acc_dict.total_credit}, 
+					get_balance_row("Closing (Opening + Totals)", 
+						account_details[acc].debit_or_credit, (acc_dict.opening 
+						+ acc_dict.total_debit - acc_dict.total_credit)), {}]
+						
+	# Total debit and credit between from and to date	
+	if total_debit or total_credit:
+		data.append({"account": "Totals", "debit": total_debit, "credit": total_credit})
+	
+	# Closing for filtered account
+	if filters.get("account"):
+		data.append(get_balance_row("Closing (Opening + Totals)", 
+			account_details[filters.account].debit_or_credit, 
+			(opening + total_debit - total_credit)))
+	
+	return data
+
+def initialize_gle_map(gl_entries):
+	gle_map = webnotes._dict()
+	for gle in gl_entries:
+		gle_map.setdefault(gle.account, webnotes._dict({
+			"opening": 0,
+			"entries": [],
+			"total_debit": 0,
+			"total_credit": 0,
+			"closing": 0
+		}))
+	return gle_map
+
+def get_accountwise_gle(filters, gl_entries, gle_map):
+	opening, total_debit, total_credit = 0, 0, 0
+	
+	for gle in gl_entries:
+		amount = flt(gle.debit) - flt(gle.credit)
+		if filters.get("account") and (gle.posting_date < filters.from_date 
+				or cstr(gle.is_advance) == "Yes"):
+			gle_map[gle.account].opening += amount
+			opening += amount
+		elif gle.posting_date < filters.to_date:
+			gle_map[gle.account].entries.append(gle)
+			gle_map[gle.account].total_debit += flt(gle.debit)
+			gle_map[gle.account].total_credit += flt(gle.credit)
+			
+			total_debit += flt(gle.debit)
+			total_credit += flt(gle.credit)
+			
+	return opening, total_debit, total_credit, gle_map
+
+def get_balance_row(label, debit_or_credit, balance):
+	return {
+		"account": label,
+		"debit": balance if debit_or_credit=="Debit" else 0,
+		"credit": -1*balance if debit_or_credit=="Credit" else 0,
+	}
+	
+def get_result_as_list(data):
+	result = []
+	for d in data:
+		result.append([d.get("posting_date"), d.get("account"), d.get("debit"), 
+			d.get("credit"), d.get("voucher_type"), d.get("voucher_no"), 
+			get_voucher_link(d.get("voucher_type"), d.get("voucher_no")), 
+			d.get("against"), d.get("cost_center"), d.get("remarks")])
+	
+	return result
+	
+def get_voucher_link(voucher_type, voucher_no):
+	icon = ""
+	if voucher_type and voucher_no:
+		icon = """<a href="%s"><i class="icon icon-share" style="cursor: pointer;">
+			</i></a>""" % ("/".join(["#Form", voucher_type, voucher_no]))
+		
+	return icon
diff --git a/erpnext/accounts/report/accounts_payable/general_ledger/general_ledger.txt b/erpnext/accounts/report/general_ledger/general_ledger.txt
similarity index 100%
rename from erpnext/accounts/report/accounts_payable/general_ledger/general_ledger.txt
rename to erpnext/accounts/report/general_ledger/general_ledger.txt
diff --git a/erpnext/projects/doctype/time_log_batch/time_log_batch.py b/erpnext/projects/doctype/time_log_batch/time_log_batch.py
index ccb0a25..593dc22 100644
--- a/erpnext/projects/doctype/time_log_batch/time_log_batch.py
+++ b/erpnext/projects/doctype/time_log_batch/time_log_batch.py
@@ -28,7 +28,7 @@
 		})
 
 	def validate_time_log_is_submitted(self, tl):
-		if tl.status != "Submitted":
+		if tl.status != "Submitted" and self.doc.docstatus == 0:
 			webnotes.msgprint(_("Time Log must have status 'Submitted'") + \
 				" :" + tl.name + " (" + _(tl.status) + ")", raise_exception=True)
 	
@@ -57,7 +57,4 @@
 			tl = webnotes.bean("Time Log", d.time_log)
 			tl.doc.time_log_batch = time_log_batch
 			tl.doc.sales_invoice = self.doc.sales_invoice
-			tl.update_after_submit()
-		
-
-		
\ No newline at end of file
+			tl.update_after_submit()
\ No newline at end of file
diff --git a/erpnext/selling/doctype/quotation_item/quotation_item.txt b/erpnext/selling/doctype/quotation_item/quotation_item.txt
index e669937..531f005 100644
--- a/erpnext/selling/doctype/quotation_item/quotation_item.txt
+++ b/erpnext/selling/doctype/quotation_item/quotation_item.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-03-07 11:42:57", 
   "docstatus": 0, 
-  "modified": "2013-12-20 19:23:41", 
+  "modified": "2013-12-31 18:12:09", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -71,6 +71,11 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "col_break1", 
+  "fieldtype": "Column Break"
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "description", 
   "fieldtype": "Small Text", 
   "in_list_view": 1, 
@@ -108,21 +113,6 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "stock_uom", 
-  "fieldtype": "Link", 
-  "in_list_view": 0, 
-  "label": "UOM", 
-  "oldfieldname": "stock_uom", 
-  "oldfieldtype": "Data", 
-  "options": "UOM", 
-  "print_hide": 0, 
-  "print_width": "100px", 
-  "read_only": 1, 
-  "reqd": 0, 
-  "width": "100px"
- }, 
- {
-  "doctype": "DocField", 
   "fieldname": "ref_rate", 
   "fieldtype": "Currency", 
   "in_list_view": 0, 
@@ -151,6 +141,45 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "col_break2", 
+  "fieldtype": "Column Break"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "stock_uom", 
+  "fieldtype": "Link", 
+  "in_list_view": 0, 
+  "label": "UOM", 
+  "oldfieldname": "stock_uom", 
+  "oldfieldtype": "Data", 
+  "options": "UOM", 
+  "print_hide": 0, 
+  "print_width": "100px", 
+  "read_only": 1, 
+  "reqd": 0, 
+  "width": "100px"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "base_ref_rate", 
+  "fieldtype": "Currency", 
+  "in_list_view": 0, 
+  "label": "Price List Rate (Company Currency)", 
+  "oldfieldname": "base_ref_rate", 
+  "oldfieldtype": "Currency", 
+  "options": "Company:company:default_currency", 
+  "print_hide": 1, 
+  "print_width": "100px", 
+  "read_only": 1, 
+  "width": "100px"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "Section_break1", 
+  "fieldtype": "Section Break"
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "export_rate", 
   "fieldtype": "Currency", 
   "in_filter": 0, 
@@ -185,17 +214,8 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "base_ref_rate", 
-  "fieldtype": "Currency", 
-  "in_list_view": 0, 
-  "label": "Price List Rate (Company Currency)", 
-  "oldfieldname": "base_ref_rate", 
-  "oldfieldtype": "Currency", 
-  "options": "Company:company:default_currency", 
-  "print_hide": 1, 
-  "print_width": "100px", 
-  "read_only": 1, 
-  "width": "100px"
+  "fieldname": "col_break3", 
+  "fieldtype": "Column Break"
  }, 
  {
   "doctype": "DocField", 
@@ -239,6 +259,70 @@
   "label": "Reference"
  }, 
  {
+  "doctype": "DocField", 
+  "fieldname": "prevdoc_doctype", 
+  "fieldtype": "Data", 
+  "hidden": 1, 
+  "in_list_view": 0, 
+  "label": "Against Doctype", 
+  "no_copy": 1, 
+  "oldfieldname": "prevdoc_doctype", 
+  "oldfieldtype": "Data", 
+  "print_hide": 1, 
+  "print_width": "150px", 
+  "read_only": 1, 
+  "report_hide": 0, 
+  "width": "150px"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "prevdoc_docname", 
+  "fieldtype": "Data", 
+  "in_list_view": 0, 
+  "label": "Against Docname", 
+  "no_copy": 1, 
+  "oldfieldname": "prevdoc_docname", 
+  "oldfieldtype": "Data", 
+  "print_hide": 1, 
+  "print_width": "150px", 
+  "read_only": 1, 
+  "report_hide": 0, 
+  "width": "150px"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "item_tax_rate", 
+  "fieldtype": "Small Text", 
+  "hidden": 1, 
+  "in_list_view": 0, 
+  "label": "Item Tax Rate", 
+  "oldfieldname": "item_tax_rate", 
+  "oldfieldtype": "Small Text", 
+  "print_hide": 1, 
+  "read_only": 1, 
+  "report_hide": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "col_break4", 
+  "fieldtype": "Column Break"
+ }, 
+ {
+  "allow_on_submit": 1, 
+  "doctype": "DocField", 
+  "fieldname": "page_break", 
+  "fieldtype": "Check", 
+  "hidden": 0, 
+  "in_list_view": 0, 
+  "label": "Page Break", 
+  "no_copy": 1, 
+  "oldfieldname": "page_break", 
+  "oldfieldtype": "Check", 
+  "print_hide": 1, 
+  "read_only": 0, 
+  "report_hide": 1
+ }, 
+ {
   "description": "<a href=\"#Sales Browser/Item Group\">Add / Edit</a>", 
   "doctype": "DocField", 
   "fieldname": "item_group", 
@@ -270,64 +354,5 @@
   "read_only": 1, 
   "search_index": 1, 
   "width": "150px"
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "item_tax_rate", 
-  "fieldtype": "Small Text", 
-  "hidden": 1, 
-  "in_list_view": 0, 
-  "label": "Item Tax Rate", 
-  "oldfieldname": "item_tax_rate", 
-  "oldfieldtype": "Small Text", 
-  "print_hide": 1, 
-  "read_only": 1, 
-  "report_hide": 1
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "prevdoc_docname", 
-  "fieldtype": "Data", 
-  "in_list_view": 0, 
-  "label": "Against Docname", 
-  "no_copy": 1, 
-  "oldfieldname": "prevdoc_docname", 
-  "oldfieldtype": "Data", 
-  "print_hide": 1, 
-  "print_width": "150px", 
-  "read_only": 1, 
-  "report_hide": 0, 
-  "width": "150px"
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "prevdoc_doctype", 
-  "fieldtype": "Data", 
-  "hidden": 1, 
-  "in_list_view": 0, 
-  "label": "Against Doctype", 
-  "no_copy": 1, 
-  "oldfieldname": "prevdoc_doctype", 
-  "oldfieldtype": "Data", 
-  "print_hide": 1, 
-  "print_width": "150px", 
-  "read_only": 1, 
-  "report_hide": 0, 
-  "width": "150px"
- }, 
- {
-  "allow_on_submit": 1, 
-  "doctype": "DocField", 
-  "fieldname": "page_break", 
-  "fieldtype": "Check", 
-  "hidden": 0, 
-  "in_list_view": 0, 
-  "label": "Page Break", 
-  "no_copy": 1, 
-  "oldfieldname": "page_break", 
-  "oldfieldtype": "Check", 
-  "print_hide": 1, 
-  "read_only": 0, 
-  "report_hide": 1
  }
 ]
\ No newline at end of file
diff --git a/erpnext/selling/doctype/sales_order_item/sales_order_item.txt b/erpnext/selling/doctype/sales_order_item/sales_order_item.txt
index eb656a6..38fb01c 100644
--- a/erpnext/selling/doctype/sales_order_item/sales_order_item.txt
+++ b/erpnext/selling/doctype/sales_order_item/sales_order_item.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-03-07 11:42:58", 
   "docstatus": 0, 
-  "modified": "2013-12-20 19:21:43", 
+  "modified": "2013-12-31 18:07:50", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -67,6 +67,11 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "col_break1", 
+  "fieldtype": "Column Break"
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "description", 
   "fieldtype": "Small Text", 
   "in_filter": 1, 
@@ -102,21 +107,6 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "stock_uom", 
-  "fieldtype": "Link", 
-  "hidden": 0, 
-  "in_list_view": 0, 
-  "label": "UOM", 
-  "oldfieldname": "stock_uom", 
-  "oldfieldtype": "Data", 
-  "options": "UOM", 
-  "print_width": "70px", 
-  "read_only": 1, 
-  "reqd": 0, 
-  "width": "70px"
- }, 
- {
-  "doctype": "DocField", 
   "fieldname": "ref_rate", 
   "fieldtype": "Currency", 
   "in_list_view": 0, 
@@ -145,6 +135,45 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "col_break2", 
+  "fieldtype": "Column Break"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "stock_uom", 
+  "fieldtype": "Link", 
+  "hidden": 0, 
+  "in_list_view": 0, 
+  "label": "UOM", 
+  "oldfieldname": "stock_uom", 
+  "oldfieldtype": "Data", 
+  "options": "UOM", 
+  "print_width": "70px", 
+  "read_only": 1, 
+  "reqd": 0, 
+  "width": "70px"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "base_ref_rate", 
+  "fieldtype": "Currency", 
+  "in_list_view": 0, 
+  "label": "Price List Rate (Company Currency)", 
+  "oldfieldname": "base_ref_rate", 
+  "oldfieldtype": "Currency", 
+  "options": "Company:company:default_currency", 
+  "print_hide": 1, 
+  "print_width": "100px", 
+  "read_only": 1, 
+  "width": "100px"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "section_break_simple1", 
+  "fieldtype": "Section Break"
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "export_rate", 
   "fieldtype": "Currency", 
   "in_list_view": 1, 
@@ -174,17 +203,8 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "base_ref_rate", 
-  "fieldtype": "Currency", 
-  "in_list_view": 0, 
-  "label": "Price List Rate (Company Currency)", 
-  "oldfieldname": "base_ref_rate", 
-  "oldfieldtype": "Currency", 
-  "options": "Company:company:default_currency", 
-  "print_hide": 1, 
-  "print_width": "100px", 
-  "read_only": 1, 
-  "width": "100px"
+  "fieldname": "col_break3", 
+  "fieldtype": "Column Break"
  }, 
  {
   "doctype": "DocField", 
@@ -242,6 +262,71 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "prevdoc_docname", 
+  "fieldtype": "Link", 
+  "hidden": 0, 
+  "in_filter": 1, 
+  "in_list_view": 0, 
+  "label": "Quotation", 
+  "no_copy": 1, 
+  "oldfieldname": "prevdoc_docname", 
+  "oldfieldtype": "Link", 
+  "options": "Quotation", 
+  "print_hide": 1, 
+  "read_only": 1, 
+  "search_index": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "brand", 
+  "fieldtype": "Link", 
+  "hidden": 1, 
+  "in_filter": 1, 
+  "in_list_view": 0, 
+  "label": "Brand Name", 
+  "oldfieldname": "brand", 
+  "oldfieldtype": "Link", 
+  "options": "Brand", 
+  "print_hide": 1, 
+  "read_only": 1, 
+  "search_index": 1
+ }, 
+ {
+  "description": "<a href=\"#Sales Browser/Item Group\">Add / Edit</a>", 
+  "doctype": "DocField", 
+  "fieldname": "item_group", 
+  "fieldtype": "Link", 
+  "hidden": 1, 
+  "in_filter": 1, 
+  "in_list_view": 0, 
+  "label": "Item Group", 
+  "oldfieldname": "item_group", 
+  "oldfieldtype": "Link", 
+  "options": "Item Group", 
+  "print_hide": 1, 
+  "read_only": 1, 
+  "search_index": 1
+ }, 
+ {
+  "allow_on_submit": 1, 
+  "doctype": "DocField", 
+  "fieldname": "page_break", 
+  "fieldtype": "Check", 
+  "in_list_view": 0, 
+  "label": "Page Break", 
+  "oldfieldname": "page_break", 
+  "oldfieldtype": "Check", 
+  "print_hide": 1, 
+  "read_only": 0, 
+  "report_hide": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "col_break4", 
+  "fieldtype": "Column Break"
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "projected_qty", 
   "fieldtype": "Float", 
   "hidden": 1, 
@@ -330,66 +415,6 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "brand", 
-  "fieldtype": "Link", 
-  "hidden": 1, 
-  "in_filter": 1, 
-  "in_list_view": 0, 
-  "label": "Brand Name", 
-  "oldfieldname": "brand", 
-  "oldfieldtype": "Link", 
-  "options": "Brand", 
-  "print_hide": 1, 
-  "read_only": 1, 
-  "search_index": 1
- }, 
- {
-  "description": "<a href=\"#Sales Browser/Item Group\">Add / Edit</a>", 
-  "doctype": "DocField", 
-  "fieldname": "item_group", 
-  "fieldtype": "Link", 
-  "hidden": 1, 
-  "in_filter": 1, 
-  "in_list_view": 0, 
-  "label": "Item Group", 
-  "oldfieldname": "item_group", 
-  "oldfieldtype": "Link", 
-  "options": "Item Group", 
-  "print_hide": 1, 
-  "read_only": 1, 
-  "search_index": 1
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "prevdoc_docname", 
-  "fieldtype": "Link", 
-  "hidden": 0, 
-  "in_filter": 1, 
-  "in_list_view": 0, 
-  "label": "Quotation", 
-  "no_copy": 1, 
-  "oldfieldname": "prevdoc_docname", 
-  "oldfieldtype": "Link", 
-  "options": "Quotation", 
-  "print_hide": 1, 
-  "read_only": 1, 
-  "search_index": 1
- }, 
- {
-  "allow_on_submit": 1, 
-  "doctype": "DocField", 
-  "fieldname": "page_break", 
-  "fieldtype": "Check", 
-  "in_list_view": 0, 
-  "label": "Page Break", 
-  "oldfieldname": "page_break", 
-  "oldfieldtype": "Check", 
-  "print_hide": 1, 
-  "read_only": 0, 
-  "report_hide": 1
- }, 
- {
-  "doctype": "DocField", 
   "fieldname": "item_tax_rate", 
   "fieldtype": "Small Text", 
   "hidden": 1, 
diff --git a/erpnext/selling/doctype/sales_team/sales_team.txt b/erpnext/selling/doctype/sales_team/sales_team.txt
index 9b58429..d012cb4 100644
--- a/erpnext/selling/doctype/sales_team/sales_team.txt
+++ b/erpnext/selling/doctype/sales_team/sales_team.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-04-19 13:30:51", 
   "docstatus": 0, 
-  "modified": "2013-12-20 19:21:46", 
+  "modified": "2013-12-31 19:00:14", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -65,6 +65,11 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "col_break1", 
+  "fieldtype": "Column Break"
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "allocated_percentage", 
   "fieldtype": "Float", 
   "in_list_view": 1, 
@@ -91,6 +96,16 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "incentives", 
+  "fieldtype": "Currency", 
+  "in_list_view": 1, 
+  "label": "Incentives", 
+  "oldfieldname": "incentives", 
+  "oldfieldtype": "Currency", 
+  "options": "Company:company:default_currency"
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "parenttype", 
   "fieldtype": "Data", 
   "hidden": 1, 
@@ -101,15 +116,5 @@
   "oldfieldtype": "Data", 
   "print_hide": 1, 
   "search_index": 1
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "incentives", 
-  "fieldtype": "Currency", 
-  "in_list_view": 1, 
-  "label": "Incentives", 
-  "oldfieldname": "incentives", 
-  "oldfieldtype": "Currency", 
-  "options": "Company:company:default_currency"
  }
 ]
\ No newline at end of file
diff --git a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.txt b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.txt
index 96c01f6..7caa89d 100644
--- a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.txt
+++ b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-04-22 13:15:44", 
   "docstatus": 0, 
-  "modified": "2013-12-20 19:23:08", 
+  "modified": "2013-12-31 18:23:03", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -52,16 +52,6 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "customer_item_code", 
-  "fieldtype": "Data", 
-  "hidden": 1, 
-  "in_list_view": 0, 
-  "label": "Customer's Item Code", 
-  "print_hide": 1, 
-  "read_only": 1
- }, 
- {
-  "doctype": "DocField", 
   "fieldname": "item_name", 
   "fieldtype": "Data", 
   "in_list_view": 0, 
@@ -76,6 +66,21 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "col_break1", 
+  "fieldtype": "Column Break"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "customer_item_code", 
+  "fieldtype": "Data", 
+  "hidden": 1, 
+  "in_list_view": 0, 
+  "label": "Customer's Item Code", 
+  "print_hide": 1, 
+  "read_only": 1
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "description", 
   "fieldtype": "Small Text", 
   "in_list_view": 1, 
@@ -109,21 +114,6 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "stock_uom", 
-  "fieldtype": "Link", 
-  "in_list_view": 0, 
-  "label": "UOM", 
-  "oldfieldname": "stock_uom", 
-  "oldfieldtype": "Data", 
-  "options": "UOM", 
-  "print_hide": 0, 
-  "print_width": "50px", 
-  "read_only": 1, 
-  "reqd": 1, 
-  "width": "50px"
- }, 
- {
-  "doctype": "DocField", 
   "fieldname": "ref_rate", 
   "fieldtype": "Currency", 
   "in_list_view": 0, 
@@ -153,6 +143,45 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "col_break2", 
+  "fieldtype": "Column Break"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "stock_uom", 
+  "fieldtype": "Link", 
+  "in_list_view": 0, 
+  "label": "UOM", 
+  "oldfieldname": "stock_uom", 
+  "oldfieldtype": "Data", 
+  "options": "UOM", 
+  "print_hide": 0, 
+  "print_width": "50px", 
+  "read_only": 1, 
+  "reqd": 1, 
+  "width": "50px"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "base_ref_rate", 
+  "fieldtype": "Currency", 
+  "in_list_view": 0, 
+  "label": "Price List Rate (Company Currency)", 
+  "oldfieldname": "base_ref_rate", 
+  "oldfieldtype": "Currency", 
+  "options": "Company:company:default_currency", 
+  "print_hide": 1, 
+  "print_width": "100px", 
+  "read_only": 1, 
+  "width": "100px"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "section_break_1", 
+  "fieldtype": "Section Break"
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "export_rate", 
   "fieldtype": "Currency", 
   "in_list_view": 1, 
@@ -183,17 +212,8 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "base_ref_rate", 
-  "fieldtype": "Currency", 
-  "in_list_view": 0, 
-  "label": "Price List Rate (Company Currency)", 
-  "oldfieldname": "base_ref_rate", 
-  "oldfieldtype": "Currency", 
-  "options": "Company:company:default_currency", 
-  "print_hide": 1, 
-  "print_width": "100px", 
-  "read_only": 1, 
-  "width": "100px"
+  "fieldname": "col_break3", 
+  "fieldtype": "Column Break"
  }, 
  {
   "doctype": "DocField", 
@@ -272,31 +292,6 @@
   "read_only": 0
  }, 
  {
-  "doctype": "DocField", 
-  "fieldname": "expense_account", 
-  "fieldtype": "Link", 
-  "hidden": 0, 
-  "label": "Expense Account", 
-  "no_copy": 1, 
-  "options": "Account", 
-  "print_hide": 1, 
-  "read_only": 0, 
-  "width": "120px"
- }, 
- {
-  "default": ":Company", 
-  "doctype": "DocField", 
-  "fieldname": "cost_center", 
-  "fieldtype": "Link", 
-  "hidden": 0, 
-  "label": "Cost Center", 
-  "no_copy": 1, 
-  "options": "Cost Center", 
-  "print_hide": 1, 
-  "read_only": 0, 
-  "width": "120px"
- }, 
- {
   "description": "<a href=\"#Sales Browser/Item Group\">Add / Edit</a>", 
   "doctype": "DocField", 
   "fieldname": "item_group", 
@@ -325,6 +320,22 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "item_tax_rate", 
+  "fieldtype": "Small Text", 
+  "hidden": 1, 
+  "label": "Item Tax Rate", 
+  "oldfieldname": "item_tax_rate", 
+  "oldfieldtype": "Small Text", 
+  "print_hide": 1, 
+  "read_only": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "col_break4", 
+  "fieldtype": "Column Break"
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "actual_qty", 
   "fieldtype": "Float", 
   "label": "Available Qty at Warehouse", 
@@ -338,30 +349,44 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "installed_qty", 
-  "fieldtype": "Float", 
-  "label": "Installed Qty", 
+  "fieldname": "expense_account", 
+  "fieldtype": "Link", 
+  "hidden": 0, 
+  "label": "Expense Account", 
   "no_copy": 1, 
-  "oldfieldname": "installed_qty", 
-  "oldfieldtype": "Currency", 
+  "options": "Account", 
   "print_hide": 1, 
-  "print_width": "150px", 
-  "read_only": 1, 
-  "width": "150px"
+  "read_only": 0, 
+  "width": "120px"
+ }, 
+ {
+  "default": ":Company", 
+  "doctype": "DocField", 
+  "fieldname": "cost_center", 
+  "fieldtype": "Link", 
+  "hidden": 0, 
+  "label": "Cost Center", 
+  "no_copy": 1, 
+  "options": "Cost Center", 
+  "print_hide": 1, 
+  "read_only": 0, 
+  "width": "120px"
  }, 
  {
   "doctype": "DocField", 
   "fieldname": "against_sales_order", 
   "fieldtype": "Link", 
   "label": "Against Sales Order", 
-  "options": "Sales Order"
+  "options": "Sales Order", 
+  "read_only": 1
  }, 
  {
   "doctype": "DocField", 
   "fieldname": "against_sales_invoice", 
   "fieldtype": "Link", 
   "label": "Against Sales Invoice", 
-  "options": "Sales Invoice"
+  "options": "Sales Invoice", 
+  "read_only": 1
  }, 
  {
   "doctype": "DocField", 
@@ -381,14 +406,16 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "item_tax_rate", 
-  "fieldtype": "Small Text", 
-  "hidden": 1, 
-  "label": "Item Tax Rate", 
-  "oldfieldname": "item_tax_rate", 
-  "oldfieldtype": "Small Text", 
+  "fieldname": "installed_qty", 
+  "fieldtype": "Float", 
+  "label": "Installed Qty", 
+  "no_copy": 1, 
+  "oldfieldname": "installed_qty", 
+  "oldfieldtype": "Currency", 
   "print_hide": 1, 
-  "read_only": 1
+  "print_width": "150px", 
+  "read_only": 1, 
+  "width": "150px"
  }, 
  {
   "doctype": "DocField", 
diff --git a/erpnext/stock/doctype/packing_slip/packing_slip.js b/erpnext/stock/doctype/packing_slip/packing_slip.js
index a0e82e7..992b00d 100644
--- a/erpnext/stock/doctype/packing_slip/packing_slip.js
+++ b/erpnext/stock/doctype/packing_slip/packing_slip.js
@@ -11,7 +11,7 @@
 cur_frm.fields_dict['item_details'].grid.get_field('item_code').get_query = 
 		function(doc, cdt, cdn) {
 			return {
-				query: "stock.doctype.packing_slip.packing_slip.item_details",
+				query: "erpnext.stock.doctype.packing_slip.packing_slip.item_details",
 				filters:{ 'delivery_note': doc.delivery_note}
 			}
 }
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js
index ec46685..6bd9564 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.js
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.js
@@ -12,7 +12,7 @@
 		var me = this;
 		
 		this.frm.fields_dict.delivery_note_no.get_query = function() {
-			return { query: "stock.doctype.stock_entry.stock_entry.query_sales_return_doc" };
+			return { query: "erpnext.stock.doctype.stock_entry.stock_entry.query_sales_return_doc" };
 		};
 		
 		this.frm.fields_dict.sales_invoice_no.get_query = 
@@ -28,7 +28,7 @@
 			if(in_list(["Sales Return", "Purchase Return"], me.frm.doc.purpose) && 
 				me.get_doctype_docname()) {
 					return {
-						query: "stock.doctype.stock_entry.stock_entry.query_return_item",
+						query: "erpnext.stock.doctype.stock_entry.stock_entry.query_return_item",
 						filters: {
 							purpose: me.frm.doc.purpose,
 							delivery_note_no: me.frm.doc.delivery_note_no,
@@ -309,7 +309,7 @@
 	var d = locals[cdt][cdn];		
 	if(d.item_code) {
 		return{
-			query: "stock.doctype.stock_entry.stock_entry.get_batch_no",
+			query: "erpnext.stock.doctype.stock_entry.stock_entry.get_batch_no",
 			filters:{
 				'item_code': d.item_code,
 				's_warehouse': d.s_warehouse,
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 078b8f5..f1485f3 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -288,11 +288,12 @@
 				if not returnable_qty:
 					webnotes.throw("{item}: {item_code} {returned}".format(
 						item=_("Item"), item_code=item.item_code, 
-						returned=_("already returned though some other documents")), StockOverReturnError)
+						returned=_("already returned though some other documents")), 
+						StockOverReturnError)
 				elif item.transfer_qty > returnable_qty:
 					webnotes.throw("{item}: {item_code}, {returned}: {qty}".format(
 						item=_("Item"), item_code=item.item_code,
-						returned=_("Max Returnable Qty"), qty=returnable_qty))
+						returned=_("Max Returnable Qty"), qty=returnable_qty), StockOverReturnError)
 						
 	def get_already_returned_item_qty(self, ref_fieldname):
 		return dict(webnotes.conn.sql("""select item_code, sum(transfer_qty) as qty