Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/accounts/doctype/purchase_invoice_item/purchase_invoice_item.txt b/accounts/doctype/purchase_invoice_item/purchase_invoice_item.txt
index db1ebb6..93668b6 100755
--- a/accounts/doctype/purchase_invoice_item/purchase_invoice_item.txt
+++ b/accounts/doctype/purchase_invoice_item/purchase_invoice_item.txt
@@ -2,9 +2,9 @@
  {
   "owner": "Administrator", 
   "docstatus": 0, 
-  "creation": "2012-07-03 13:29:48", 
+  "creation": "2012-12-19 22:38:53", 
   "modified_by": "Administrator", 
-  "modified": "2012-12-19 11:57:47"
+  "modified": "2013-01-04 13:15:09"
  }, 
  {
   "istable": 1, 
@@ -40,17 +40,18 @@
  }, 
  {
   "oldfieldtype": "Data", 
-  "search_index": 0, 
   "doctype": "DocField", 
   "label": "Item Name", 
   "oldfieldname": "item_name", 
   "fieldname": "item_name", 
   "fieldtype": "Data", 
+  "search_index": 0, 
   "reqd": 1, 
   "permlevel": 0, 
   "in_filter": 0
  }, 
  {
+  "print_width": "300px", 
   "oldfieldtype": "Text", 
   "doctype": "DocField", 
   "label": "Description", 
@@ -74,6 +75,15 @@
  {
   "print_hide": 1, 
   "doctype": "DocField", 
+  "label": "UOM", 
+  "options": "UOM", 
+  "fieldname": "uom", 
+  "fieldtype": "Link", 
+  "permlevel": 0
+ }, 
+ {
+  "print_hide": 1, 
+  "doctype": "DocField", 
   "label": "Ref Rate ", 
   "fieldname": "import_ref_rate", 
   "fieldtype": "Currency", 
@@ -140,19 +150,21 @@
  }, 
  {
   "print_hide": 1, 
+  "print_width": "120px", 
   "permlevel": 0, 
   "oldfieldtype": "Link", 
   "doctype": "DocField", 
   "label": "Expense Head", 
   "oldfieldname": "expense_head", 
   "width": "120px", 
-  "options": "Account", 
   "fieldname": "expense_head", 
   "fieldtype": "Link", 
-  "reqd": 1
+  "reqd": 1, 
+  "options": "Account"
  }, 
  {
   "print_hide": 1, 
+  "print_width": "120px", 
   "oldfieldtype": "Link", 
   "doctype": "DocField", 
   "label": "Cost Center", 
@@ -175,15 +187,6 @@
  }, 
  {
   "print_hide": 1, 
-  "doctype": "DocField", 
-  "label": "UOM", 
-  "options": "UOM", 
-  "fieldname": "uom", 
-  "fieldtype": "Link", 
-  "permlevel": 0
- }, 
- {
-  "print_hide": 1, 
   "oldfieldtype": "Data", 
   "doctype": "DocField", 
   "label": "Brand", 
@@ -200,35 +203,35 @@
   "label": "Item Group", 
   "oldfieldname": "item_group", 
   "permlevel": 1, 
-  "options": "Item Group", 
   "fieldname": "item_group", 
   "fieldtype": "Link", 
   "search_index": 1, 
   "hidden": 1, 
+  "options": "Item Group", 
   "in_filter": 1
  }, 
  {
   "print_hide": 1, 
   "oldfieldtype": "Link", 
-  "search_index": 1, 
   "doctype": "DocField", 
   "label": "Pur Order", 
   "oldfieldname": "purchase_order", 
   "options": "Purchase Order", 
   "fieldname": "purchase_order", 
   "fieldtype": "Link", 
+  "search_index": 1, 
   "permlevel": 1, 
   "in_filter": 1
  }, 
  {
   "print_hide": 1, 
   "oldfieldtype": "Data", 
-  "search_index": 1, 
   "doctype": "DocField", 
   "label": "Purchase Order Item", 
   "oldfieldname": "po_detail", 
   "fieldname": "po_detail", 
   "fieldtype": "Data", 
+  "search_index": 1, 
   "hidden": 1, 
   "permlevel": 1, 
   "in_filter": 1
@@ -236,25 +239,25 @@
  {
   "print_hide": 1, 
   "oldfieldtype": "Link", 
-  "search_index": 1, 
   "doctype": "DocField", 
   "label": "Pur Receipt", 
   "oldfieldname": "purchase_receipt", 
   "options": "Purchase Receipt", 
   "fieldname": "purchase_receipt", 
   "fieldtype": "Link", 
+  "search_index": 1, 
   "permlevel": 1, 
   "in_filter": 1
  }, 
  {
   "print_hide": 1, 
   "oldfieldtype": "Data", 
-  "search_index": 1, 
   "doctype": "DocField", 
   "label": "PR Detail", 
   "oldfieldname": "pr_detail", 
   "fieldname": "pr_detail", 
   "fieldtype": "Data", 
+  "search_index": 1, 
   "hidden": 1, 
   "permlevel": 1, 
   "in_filter": 1
diff --git a/accounts/utils/__init__.py b/accounts/utils/__init__.py
index c4a0042..8ad1899 100644
--- a/accounts/utils/__init__.py
+++ b/accounts/utils/__init__.py
@@ -28,8 +28,8 @@
 		subdate(adddate(year_start_date, interval 1 year), interval 1 day) 
 			as year_end_date
 		from `tabFiscal Year`
-		where %s >= year_start_date and %s < adddate(year_start_date, interval 1 year)""",
-		(date, date))
+		where %s >= year_start_date and %s < adddate(year_start_date, interval 1 year)
+		order by year_start_date desc""", (date, date))
 	
 	if not fy:
 		error_msg = """%s not in any Fiscal Year""" % formatdate(date)