Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py
index f4ac6b0..17ae216 100644
--- a/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/accounts/doctype/sales_invoice/sales_invoice.py
@@ -549,9 +549,7 @@
 		self.values = []
 		items = get_obj('Sales Common').get_item_list(self)
 		for d in items:
-			stock_item = webnotes.conn.sql("SELECT is_stock_item, is_sample_item \
-				FROM tabItem where name = '%s'"%(d['item_code']), as_dict = 1)
-			if stock_item[0]['is_stock_item'] == "Yes":
+			if webnotes.conn.get_value("Item", d['item_code'], "is_stock_item") == "Yes":
 				if not d['warehouse']:
 					msgprint("Message: Please enter Warehouse for item %s as it is stock item." \
 						% d['item_code'], raise_exception=1)
diff --git a/patches/august_2013/fix_fiscal_year.py b/patches/august_2013/fix_fiscal_year.py
new file mode 100644
index 0000000..67988c4
--- /dev/null
+++ b/patches/august_2013/fix_fiscal_year.py
@@ -0,0 +1,49 @@
+import webnotes
+
+def execute():
+	create_fiscal_years()
+	
+	doctypes = webnotes.conn.sql_list("""select parent from tabDocField
+		where (fieldtype="Link" and options='Fiscal Year')
+		or (fieldtype="Select" and options='link:Fiscal Year')""")
+		
+	for dt in doctypes:
+		date_fields = webnotes.conn.sql_list("""select fieldname from tabDocField
+			where parent=%s and fieldtype='Date'""", dt)
+		
+		date_field = get_date_field(date_fields, dt)
+
+		if not date_field:
+			print dt, date_field
+		else:
+			webnotes.conn.sql("""update `tab%s` set fiscal_year = 
+				if(%s<='2013-06-30', '2012-2013', '2013-2014')""" % (dt, date_field))
+			
+def create_fiscal_years():
+	fiscal_years = {
+		"2012-2013": ["2012-07-01", "2013-06-30"],
+		"2013-2014": ["2013-07-01", "2014-06-30"]
+	}
+	
+	for d in fiscal_years:
+		webnotes.bean({
+			"doctype": "Fiscal Year",
+			"year": d,
+			"year_start_date": fiscal_years[d][0],
+			"is_fiscal_year_closed": "No"
+		}).insert()
+	
+		
+def get_date_field(date_fields, dt):
+	date_field = None
+	if date_fields:
+		if "posting_date" in date_fields:
+			date_field = "posting_date"
+		elif "transaction_date" in date_fields:
+			date_field = 'transaction_date'
+		else:
+			date_field = date_fields[0]
+			# print dt, date_fields
+			
+	return date_field
+		
\ No newline at end of file
diff --git a/stock/doctype/item/item.txt b/stock/doctype/item/item.txt
index 8b17aee..eb05503 100644
--- a/stock/doctype/item/item.txt
+++ b/stock/doctype/item/item.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-05-03 10:45:46", 
   "docstatus": 0, 
-  "modified": "2013-08-14 11:46:49", 
+  "modified": "2013-08-30 16:21:38", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -35,7 +35,9 @@
   "parentfield": "permissions", 
   "parenttype": "DocType", 
   "permlevel": 0, 
-  "read": 1
+  "read": 1, 
+  "report": 1, 
+  "submit": 0
  }, 
  {
   "doctype": "DocType", 
@@ -558,20 +560,6 @@
   "reqd": 1
  }, 
  {
-  "default": "No", 
-  "depends_on": "eval:doc.is_sales_item==\"Yes\"", 
-  "description": "Select \"Yes\" if this item is to be sent to a customer or received from a supplier as a sample. Delivery notes and Purchase Receipts will update stock levels but there will be no invoice against this item.", 
-  "doctype": "DocField", 
-  "fieldname": "is_sample_item", 
-  "fieldtype": "Select", 
-  "label": "Allow Samples", 
-  "oldfieldname": "is_sample_item", 
-  "oldfieldtype": "Select", 
-  "options": "Yes\nNo", 
-  "read_only": 0, 
-  "reqd": 1
- }, 
- {
   "depends_on": "eval:doc.is_sales_item==\"Yes\"", 
   "doctype": "DocField", 
   "fieldname": "max_discount", 
@@ -878,9 +866,7 @@
   "cancel": 1, 
   "create": 1, 
   "doctype": "DocPerm", 
-  "report": 1, 
   "role": "Material Master Manager", 
-  "submit": 0, 
   "write": 1
  }, 
  {
@@ -888,9 +874,7 @@
   "cancel": 0, 
   "create": 0, 
   "doctype": "DocPerm", 
-  "report": 1, 
   "role": "Material Manager", 
-  "submit": 0, 
   "write": 0
  }, 
  {
@@ -898,21 +882,7 @@
   "cancel": 0, 
   "create": 0, 
   "doctype": "DocPerm", 
-  "report": 1, 
   "role": "Material User", 
-  "submit": 0, 
   "write": 0
- }, 
- {
-  "doctype": "DocPerm", 
-  "role": "Sales User"
- }, 
- {
-  "doctype": "DocPerm", 
-  "role": "Purchase User"
- }, 
- {
-  "doctype": "DocPerm", 
-  "role": "Accounts User"
  }
 ]
\ No newline at end of file
diff --git a/stock/doctype/item/test_item.py b/stock/doctype/item/test_item.py
index b9b67e2..7be6ea5 100644
--- a/stock/doctype/item/test_item.py
+++ b/stock/doctype/item/test_item.py
@@ -44,7 +44,6 @@
 		"is_purchase_item": "Yes",
 		"is_sales_item": "Yes",
 		"is_service_item": "No",
-		"is_sample_item": "No",
 		"inspection_required": "No",
 		"is_pro_applicable": "No",
 		"is_sub_contracted_item": "No",
@@ -82,7 +81,6 @@
 		"is_purchase_item": "Yes",
 		"is_sales_item": "Yes",
 		"is_service_item": "No",
-		"is_sample_item": "No",
 		"inspection_required": "No",
 		"is_pro_applicable": "No",
 		"is_sub_contracted_item": "No",
@@ -108,7 +106,6 @@
 		"is_purchase_item": "Yes",
 		"is_sales_item": "Yes",
 		"is_service_item": "No",
-		"is_sample_item": "No",
 		"inspection_required": "No",
 		"is_pro_applicable": "No",
 		"is_sub_contracted_item": "No",
@@ -128,7 +125,6 @@
 		"is_purchase_item": "Yes",
 		"is_sales_item": "Yes",
 		"is_service_item": "No",
-		"is_sample_item": "No",
 		"inspection_required": "No",
 		"is_pro_applicable": "No",
 		"is_sub_contracted_item": "No",
@@ -149,7 +145,6 @@
 		"is_purchase_item": "Yes",
 		"is_sales_item": "Yes",
 		"is_service_item": "No",
-		"is_sample_item": "No",
 		"inspection_required": "No",
 		"is_pro_applicable": "Yes",
 		"is_sub_contracted_item": "Yes",
@@ -168,7 +163,6 @@
 		"is_purchase_item": "Yes",
 		"is_sales_item": "Yes",
 		"is_service_item": "No",
-		"is_sample_item": "No",
 		"inspection_required": "No",
 		"is_pro_applicable": "No",
 		"is_sub_contracted_item": "No",
@@ -188,7 +182,6 @@
 		"is_purchase_item": "Yes",
 		"is_sales_item": "Yes",
 		"is_service_item": "No",
-		"is_sample_item": "No",
 		"inspection_required": "No",
 		"is_pro_applicable": "No",
 		"is_sub_contracted_item": "No",
@@ -209,7 +202,6 @@
 		"is_purchase_item": "Yes",
 		"is_sales_item": "Yes",
 		"is_service_item": "No",
-		"is_sample_item": "No",
 		"inspection_required": "No",
 		"is_pro_applicable": "No",
 		"is_sub_contracted_item": "No",