Merge branch 'master' into edge
diff --git a/accounts/doctype/purchase_invoice_item/purchase_invoice_item.txt b/accounts/doctype/purchase_invoice_item/purchase_invoice_item.txt
index e33ab7c..8df4306 100755
--- a/accounts/doctype/purchase_invoice_item/purchase_invoice_item.txt
+++ b/accounts/doctype/purchase_invoice_item/purchase_invoice_item.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-04-10 08:35:38", 
+  "creation": "2013-04-19 11:00:07", 
   "docstatus": 0, 
-  "modified": "2013-04-17 14:05:20", 
+  "modified": "2013-05-22 12:01:56", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -224,6 +224,7 @@
   "fieldtype": "Link", 
   "in_filter": 1, 
   "label": "Pur Order", 
+  "no_copy": 1, 
   "oldfieldname": "purchase_order", 
   "oldfieldtype": "Link", 
   "options": "Purchase Order", 
@@ -238,6 +239,7 @@
   "hidden": 1, 
   "in_filter": 1, 
   "label": "Purchase Order Item", 
+  "no_copy": 1, 
   "oldfieldname": "po_detail", 
   "oldfieldtype": "Data", 
   "print_hide": 1, 
@@ -250,6 +252,7 @@
   "fieldtype": "Link", 
   "in_filter": 1, 
   "label": "Pur Receipt", 
+  "no_copy": 1, 
   "oldfieldname": "purchase_receipt", 
   "oldfieldtype": "Link", 
   "options": "Purchase Receipt", 
@@ -264,6 +267,7 @@
   "hidden": 1, 
   "in_filter": 1, 
   "label": "PR Detail", 
+  "no_copy": 1, 
   "oldfieldname": "pr_detail", 
   "oldfieldtype": "Data", 
   "print_hide": 1, 
diff --git a/accounts/doctype/sales_invoice_item/sales_invoice_item.txt b/accounts/doctype/sales_invoice_item/sales_invoice_item.txt
index 2a6384d..89c86f8 100644
--- a/accounts/doctype/sales_invoice_item/sales_invoice_item.txt
+++ b/accounts/doctype/sales_invoice_item/sales_invoice_item.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-04-10 08:35:44", 
+  "creation": "2013-04-19 11:00:07", 
   "docstatus": 0, 
-  "modified": "2013-04-17 14:05:20", 
+  "modified": "2013-05-22 12:06:15", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -305,6 +305,7 @@
   "fieldtype": "Link", 
   "in_filter": 1, 
   "label": "Sales Order", 
+  "no_copy": 1, 
   "oldfieldname": "sales_order", 
   "oldfieldtype": "Link", 
   "options": "Sales Order", 
@@ -319,6 +320,7 @@
   "hidden": 1, 
   "in_filter": 1, 
   "label": "SO Detail ", 
+  "no_copy": 1, 
   "oldfieldname": "so_detail", 
   "oldfieldtype": "Data", 
   "print_hide": 1, 
@@ -331,6 +333,7 @@
   "fieldtype": "Link", 
   "in_filter": 1, 
   "label": "Delivery Note", 
+  "no_copy": 1, 
   "oldfieldname": "delivery_note", 
   "oldfieldtype": "Link", 
   "options": "Delivery Note", 
@@ -345,6 +348,7 @@
   "hidden": 1, 
   "in_filter": 1, 
   "label": "DN Detail", 
+  "no_copy": 1, 
   "oldfieldname": "dn_detail", 
   "oldfieldtype": "Data", 
   "print_hide": 1, 
diff --git a/buying/doctype/purchase_order_item/purchase_order_item.txt b/buying/doctype/purchase_order_item/purchase_order_item.txt
index cd00f87..01a144a 100755
--- a/buying/doctype/purchase_order_item/purchase_order_item.txt
+++ b/buying/doctype/purchase_order_item/purchase_order_item.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-02-22 01:27:42", 
+  "creation": "2013-03-07 11:42:55", 
   "docstatus": 0, 
-  "modified": "2013-03-07 07:03:27", 
+  "modified": "2013-05-22 11:59:52", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -36,6 +36,7 @@
   "oldfieldname": "schedule_date", 
   "oldfieldtype": "Date", 
   "print_hide": 1, 
+  "read_only": 0, 
   "reqd": 1, 
   "search_index": 1
  }, 
@@ -49,6 +50,7 @@
   "oldfieldtype": "Link", 
   "options": "Item", 
   "print_hide": 0, 
+  "read_only": 0, 
   "reqd": 1, 
   "search_index": 1
  }, 
@@ -72,6 +74,7 @@
   "oldfieldname": "item_name", 
   "oldfieldtype": "Data", 
   "print_hide": 1, 
+  "read_only": 0, 
   "reqd": 1, 
   "search_index": 1
  }, 
@@ -83,6 +86,7 @@
   "oldfieldname": "description", 
   "oldfieldtype": "Small Text", 
   "print_width": "300px", 
+  "read_only": 0, 
   "reqd": 1, 
   "width": "300px"
  }, 
@@ -95,6 +99,7 @@
   "oldfieldname": "qty", 
   "oldfieldtype": "Currency", 
   "print_width": "60px", 
+  "read_only": 0, 
   "reqd": 1, 
   "width": "60px"
  }, 
@@ -108,6 +113,7 @@
   "options": "UOM", 
   "print_hide": 0, 
   "print_width": "100px", 
+  "read_only": 0, 
   "reqd": 1, 
   "width": "100px"
  }, 
@@ -117,14 +123,16 @@
   "fieldtype": "Currency", 
   "label": "Ref Rate ", 
   "options": "currency", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
   "fieldname": "discount_rate", 
   "fieldtype": "Float", 
   "label": "Discount %", 
-  "print_hide": 0
+  "print_hide": 0, 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -135,7 +143,8 @@
   "oldfieldname": "import_rate", 
   "oldfieldtype": "Currency", 
   "options": "currency", 
-  "print_hide": 0
+  "print_hide": 0, 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -153,7 +162,8 @@
   "fieldtype": "Currency", 
   "label": "Ref Rate*", 
   "options": "Company:company:default_currency", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 0
  }, 
  {
   "default": "0.00", 
@@ -166,6 +176,7 @@
   "options": "Company:company:default_currency", 
   "print_hide": 1, 
   "print_width": "100px", 
+  "read_only": 0, 
   "reqd": 1, 
   "width": "100px"
  }, 
@@ -192,6 +203,7 @@
   "oldfieldtype": "Link", 
   "options": "Warehouse", 
   "print_hide": 1, 
+  "read_only": 0, 
   "reqd": 0
  }, 
  {
@@ -202,6 +214,7 @@
   "label": "Project Name", 
   "options": "Project", 
   "print_hide": 1, 
+  "read_only": 0, 
   "report_hide": 0
  }, 
  {
@@ -214,6 +227,7 @@
   "oldfieldtype": "Currency", 
   "print_hide": 1, 
   "print_width": "100px", 
+  "read_only": 0, 
   "reqd": 1, 
   "width": "100px"
  }, 
@@ -237,7 +251,7 @@
   "fieldtype": "Data", 
   "hidden": 1, 
   "label": "Prevdoc DocType", 
-  "no_copy": 0, 
+  "no_copy": 1, 
   "oldfieldname": "prevdoc_doctype", 
   "oldfieldtype": "Data", 
   "print_hide": 1, 
@@ -250,7 +264,7 @@
   "hidden": 0, 
   "in_filter": 1, 
   "label": "Material Request No", 
-  "no_copy": 0, 
+  "no_copy": 1, 
   "oldfieldname": "prevdoc_docname", 
   "oldfieldtype": "Link", 
   "options": "Material Request", 
@@ -267,6 +281,7 @@
   "hidden": 1, 
   "in_filter": 1, 
   "label": "Material Request Date", 
+  "no_copy": 1, 
   "oldfieldname": "prevdoc_date", 
   "oldfieldtype": "Date", 
   "print_hide": 1, 
@@ -280,7 +295,7 @@
   "hidden": 1, 
   "in_filter": 1, 
   "label": "Material Request Detail No", 
-  "no_copy": 0, 
+  "no_copy": 1, 
   "oldfieldname": "prevdoc_detail_docname", 
   "oldfieldtype": "Data", 
   "print_hide": 1, 
@@ -294,6 +309,7 @@
   "hidden": 1, 
   "in_filter": 0, 
   "label": "Supplier Quotation", 
+  "no_copy": 1, 
   "options": "Supplier Quotation", 
   "read_only": 1, 
   "search_index": 0
@@ -304,6 +320,7 @@
   "fieldtype": "Link", 
   "hidden": 1, 
   "label": "Supplier Quotation Item", 
+  "no_copy": 1, 
   "options": "Supplier Quotation Item", 
   "read_only": 1
  }, 
@@ -395,6 +412,7 @@
   "no_copy": 1, 
   "oldfieldname": "page_break", 
   "oldfieldtype": "Check", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 0
  }
 ]
\ No newline at end of file
diff --git a/buying/doctype/supplier_quotation_item/supplier_quotation_item.txt b/buying/doctype/supplier_quotation_item/supplier_quotation_item.txt
index 53fa9f8..6b24d2f 100644
--- a/buying/doctype/supplier_quotation_item/supplier_quotation_item.txt
+++ b/buying/doctype/supplier_quotation_item/supplier_quotation_item.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-02-22 01:27:43", 
+  "creation": "2013-03-07 11:42:56", 
   "docstatus": 0, 
-  "modified": "2013-03-07 07:03:32", 
+  "modified": "2013-05-22 12:02:28", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -35,6 +35,7 @@
   "oldfieldtype": "Link", 
   "options": "Item", 
   "print_hide": 0, 
+  "read_only": 0, 
   "reqd": 1, 
   "search_index": 1
  }, 
@@ -58,6 +59,7 @@
   "oldfieldname": "item_name", 
   "oldfieldtype": "Data", 
   "print_hide": 1, 
+  "read_only": 0, 
   "reqd": 1, 
   "search_index": 1
  }, 
@@ -69,6 +71,7 @@
   "oldfieldname": "description", 
   "oldfieldtype": "Small Text", 
   "print_width": "300px", 
+  "read_only": 0, 
   "reqd": 1, 
   "width": "300px"
  }, 
@@ -81,6 +84,7 @@
   "oldfieldname": "qty", 
   "oldfieldtype": "Currency", 
   "print_width": "60px", 
+  "read_only": 0, 
   "reqd": 1, 
   "width": "60px"
  }, 
@@ -94,6 +98,7 @@
   "options": "UOM", 
   "print_hide": 0, 
   "print_width": "100px", 
+  "read_only": 0, 
   "reqd": 1, 
   "width": "100px"
  }, 
@@ -103,14 +108,16 @@
   "fieldtype": "Currency", 
   "label": "Ref Rate ", 
   "options": "currency", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
   "fieldname": "discount_rate", 
   "fieldtype": "Float", 
   "label": "Discount %", 
-  "print_hide": 0
+  "print_hide": 0, 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -121,7 +128,8 @@
   "oldfieldname": "import_rate", 
   "oldfieldtype": "Currency", 
   "options": "currency", 
-  "print_hide": 0
+  "print_hide": 0, 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -139,7 +147,8 @@
   "fieldtype": "Currency", 
   "label": "Ref Rate*", 
   "options": "Company:company:default_currency", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 0
  }, 
  {
   "default": "0.00", 
@@ -152,6 +161,7 @@
   "options": "Company:company:default_currency", 
   "print_hide": 1, 
   "print_width": "100px", 
+  "read_only": 0, 
   "reqd": 1, 
   "width": "100px"
  }, 
@@ -178,6 +188,7 @@
   "oldfieldtype": "Link", 
   "options": "Warehouse", 
   "print_hide": 1, 
+  "read_only": 0, 
   "reqd": 0
  }, 
  {
@@ -188,6 +199,7 @@
   "label": "Project Name", 
   "options": "Project", 
   "print_hide": 1, 
+  "read_only": 0, 
   "report_hide": 0
  }, 
  {
@@ -196,7 +208,7 @@
   "fieldtype": "Data", 
   "hidden": 1, 
   "label": "Prevdoc DocType", 
-  "no_copy": 0, 
+  "no_copy": 1, 
   "oldfieldname": "prevdoc_doctype", 
   "oldfieldtype": "Data", 
   "print_hide": 1, 
@@ -209,7 +221,7 @@
   "hidden": 0, 
   "in_filter": 1, 
   "label": "Material Request No", 
-  "no_copy": 0, 
+  "no_copy": 1, 
   "oldfieldname": "prevdoc_docname", 
   "oldfieldtype": "Link", 
   "options": "Material Request", 
@@ -226,6 +238,7 @@
   "hidden": 1, 
   "in_filter": 1, 
   "label": "Material Request Date", 
+  "no_copy": 1, 
   "oldfieldname": "prevdoc_date", 
   "oldfieldtype": "Date", 
   "print_hide": 1, 
@@ -239,7 +252,7 @@
   "hidden": 1, 
   "in_filter": 1, 
   "label": "Material Request Detail No", 
-  "no_copy": 0, 
+  "no_copy": 1, 
   "oldfieldname": "prevdoc_detail_docname", 
   "oldfieldtype": "Data", 
   "print_hide": 1, 
@@ -295,6 +308,7 @@
   "no_copy": 1, 
   "oldfieldname": "page_break", 
   "oldfieldtype": "Check", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 0
  }
 ]
\ No newline at end of file
diff --git a/hr/doctype/leave_application/leave_application.py b/hr/doctype/leave_application/leave_application.py
index 6e39751..7c47d6a 100755
--- a/hr/doctype/leave_application/leave_application.py
+++ b/hr/doctype/leave_application/leave_application.py
@@ -335,15 +335,22 @@
 def query_for_permitted_employees(doctype, txt, searchfield, start, page_len, filters):
 	txt = "%" + cstr(txt) + "%"
 	
-	return webnotes.conn.sql("""select name, employee_name from `tabEmployee` emp
+	if "Leave Approver" in webnotes.user.get_roles():
+		condition = """and (exists(select ela.name from `tabEmployee Leave Approver` ela
+				where ela.parent=`tabEmployee`.name and ela.leave_approver= "%s") or 
+			not exists(select ela.name from `tabEmployee Leave Approver` ela 
+				where ela.parent=`tabEmployee`.name)
+			or user_id = "%s")""" % (webnotes.session.user, webnotes.session.user)
+	else:
+		from webnotes.widgets.reportview import build_match_conditions
+		condition = build_match_conditions("Employee")
+		condition = ("and " + condition) if condition else ""
+	
+	return webnotes.conn.sql("""select name, employee_name from `tabEmployee`
 		where status = 'Active' and docstatus < 2 and
-		(`%s` like %s or employee_name like %s) and
-		(exists(select ela.name from `tabEmployee Leave Approver` ela
-				where ela.parent=emp.name and ela.leave_approver=%s) or 
-			not exists(select ela.name from `tabEmployee Leave Approver` ela where ela.parent=emp.name)
-			or user_id = %s)
+		(`%s` like %s or employee_name like %s) %s
 		order by
 		case when name like %s then 0 else 1 end,
 		case when employee_name like %s then 0 else 1 end,
-		name limit %s, %s""" % tuple([searchfield] + ["%s"]*8), 
-		(txt, txt, webnotes.session.user, webnotes.session.user, txt, txt, start, page_len))
+		name limit %s, %s""" % tuple([searchfield] + ["%s"]*2 + [condition] + ["%s"]*4), 
+		(txt, txt, txt, txt, start, page_len))
diff --git a/patches/may_2013/p03_update_support_ticket.py b/patches/may_2013/p03_update_support_ticket.py
new file mode 100644
index 0000000..7dc5854
--- /dev/null
+++ b/patches/may_2013/p03_update_support_ticket.py
@@ -0,0 +1,27 @@
+# ERPNext - web based ERP (http://erpnext.com)
+# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
+# 
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from __future__ import unicode_literals
+import webnotes
+def execute():
+	webnotes.reload_doc("support", "doctype", "support_ticket")
+	webnotes.reload_doc("core", "doctype", "communication")
+	for d in webnotes.conn.sql("""select name, raised_by from `tabSupport Ticket` 
+			where docstatus < 2""", as_dict=True):
+		tic = webnotes.get_obj("Support Ticket", d.name)
+		tic.set_lead_contact(d.raised_by)
+		webnotes.conn.sql("""update `tabSupport Ticket` set lead = %s, contact = %s, company = %s 
+			where name = %s""", (tic.doc.lead, tic.doc.contact, tic.doc.company, d.name))
\ No newline at end of file
diff --git a/patches/patch_list.py b/patches/patch_list.py
index bd7acb2..f28751c 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -249,4 +249,5 @@
 	"patches.may_2013.repost_stock_for_no_posting_time",
 	"patches.may_2013.p01_conversion_factor_and_aii",
 	"patches.may_2013.p02_update_valuation_rate",
+	"patches.may_2013.p03_update_support_ticket",
 ]
\ No newline at end of file
diff --git a/selling/doctype/quotation_item/quotation_item.txt b/selling/doctype/quotation_item/quotation_item.txt
index dccc503..bcb9281 100644
--- a/selling/doctype/quotation_item/quotation_item.txt
+++ b/selling/doctype/quotation_item/quotation_item.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-02-22 01:27:52", 
+  "creation": "2013-03-07 11:42:57", 
   "docstatus": 0, 
-  "modified": "2013-03-07 07:03:29", 
+  "modified": "2013-05-22 12:08:32", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -37,6 +37,7 @@
   "options": "Item", 
   "print_hide": 0, 
   "print_width": "150px", 
+  "read_only": 0, 
   "reqd": 1, 
   "search_index": 1, 
   "width": "150px"
@@ -60,6 +61,7 @@
   "oldfieldtype": "Data", 
   "print_hide": 1, 
   "print_width": "150px", 
+  "read_only": 0, 
   "reqd": 1, 
   "search_index": 1, 
   "width": "150px"
@@ -73,6 +75,7 @@
   "oldfieldtype": "Small Text", 
   "print_hide": 0, 
   "print_width": "300px", 
+  "read_only": 0, 
   "reqd": 1, 
   "width": "300px"
  }, 
@@ -87,6 +90,7 @@
   "oldfieldtype": "Currency", 
   "print_hide": 0, 
   "print_width": "100px", 
+  "read_only": 0, 
   "reqd": 1, 
   "search_index": 0, 
   "width": "100px"
@@ -115,6 +119,7 @@
   "options": "currency", 
   "print_hide": 1, 
   "print_width": "100px", 
+  "read_only": 0, 
   "reqd": 0, 
   "width": "100px"
  }, 
@@ -128,6 +133,7 @@
   "oldfieldtype": "Float", 
   "print_hide": 1, 
   "print_width": "100px", 
+  "read_only": 0, 
   "width": "100px"
  }, 
  {
@@ -142,6 +148,7 @@
   "options": "currency", 
   "print_hide": 0, 
   "print_width": "100px", 
+  "read_only": 0, 
   "reqd": 0, 
   "search_index": 0, 
   "width": "100px"
@@ -188,6 +195,7 @@
   "options": "Company:company:default_currency", 
   "print_hide": 1, 
   "print_width": "100px", 
+  "read_only": 0, 
   "reqd": 0, 
   "search_index": 0, 
   "width": "100px"
@@ -291,6 +299,7 @@
   "oldfieldname": "page_break", 
   "oldfieldtype": "Check", 
   "print_hide": 1, 
+  "read_only": 0, 
   "report_hide": 1
  }
 ]
\ No newline at end of file
diff --git a/selling/doctype/sales_order_item/sales_order_item.txt b/selling/doctype/sales_order_item/sales_order_item.txt
index fff2d08..c65ac0d 100644
--- a/selling/doctype/sales_order_item/sales_order_item.txt
+++ b/selling/doctype/sales_order_item/sales_order_item.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-02-22 01:27:52", 
+  "creation": "2013-03-07 11:42:58", 
   "docstatus": 0, 
-  "modified": "2013-03-07 07:03:30", 
+  "modified": "2013-05-22 12:09:03", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -35,6 +35,7 @@
   "oldfieldtype": "Link", 
   "options": "Item", 
   "print_width": "150px", 
+  "read_only": 0, 
   "reqd": 1, 
   "search_index": 1, 
   "width": "150px"
@@ -57,6 +58,7 @@
   "oldfieldtype": "Data", 
   "print_hide": 1, 
   "print_width": "150", 
+  "read_only": 0, 
   "reqd": 1, 
   "width": "150"
  }, 
@@ -69,6 +71,7 @@
   "oldfieldname": "description", 
   "oldfieldtype": "Small Text", 
   "print_width": "300px", 
+  "read_only": 0, 
   "reqd": 1, 
   "search_index": 1, 
   "width": "300px"
@@ -82,6 +85,7 @@
   "oldfieldname": "qty", 
   "oldfieldtype": "Currency", 
   "print_width": "100px", 
+  "read_only": 0, 
   "reqd": 1, 
   "width": "100px"
  }, 
@@ -109,6 +113,7 @@
   "options": "currency", 
   "print_hide": 1, 
   "print_width": "70px", 
+  "read_only": 0, 
   "reqd": 0, 
   "width": "70px"
  }, 
@@ -122,6 +127,7 @@
   "oldfieldtype": "Float", 
   "print_hide": 1, 
   "print_width": "70px", 
+  "read_only": 0, 
   "width": "70px"
  }, 
  {
@@ -134,6 +140,7 @@
   "oldfieldtype": "Currency", 
   "options": "currency", 
   "print_width": "100px", 
+  "read_only": 0, 
   "reqd": 0, 
   "width": "100px"
  }, 
@@ -176,6 +183,7 @@
   "options": "Company:company:default_currency", 
   "print_hide": 1, 
   "print_width": "100px", 
+  "read_only": 0, 
   "reqd": 0, 
   "width": "100px"
  }, 
@@ -206,6 +214,7 @@
   "options": "Warehouse", 
   "print_hide": 1, 
   "print_width": "150px", 
+  "read_only": 0, 
   "reqd": 0, 
   "width": "150px"
  }, 
@@ -329,6 +338,7 @@
   "hidden": 0, 
   "in_filter": 1, 
   "label": "Quotation No.", 
+  "no_copy": 1, 
   "oldfieldname": "prevdoc_docname", 
   "oldfieldtype": "Link", 
   "options": "Quotation", 
@@ -345,6 +355,7 @@
   "oldfieldname": "page_break", 
   "oldfieldtype": "Check", 
   "print_hide": 1, 
+  "read_only": 0, 
   "report_hide": 1
  }, 
  {
diff --git a/setup/doctype/item_group/item_group.py b/setup/doctype/item_group/item_group.py
index 1445f39..1ff3d4a 100644
--- a/setup/doctype/item_group/item_group.py
+++ b/setup/doctype/item_group/item_group.py
@@ -81,3 +81,4 @@
 		if self.doc.slideshow:
 			from website.helpers.slideshow import get_slideshow
 			get_slideshow(self)
+		
\ No newline at end of file
diff --git a/stock/doctype/delivery_note_item/delivery_note_item.txt b/stock/doctype/delivery_note_item/delivery_note_item.txt
index 1073f0c..f90ba69 100644
--- a/stock/doctype/delivery_note_item/delivery_note_item.txt
+++ b/stock/doctype/delivery_note_item/delivery_note_item.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-04-01 10:49:21", 
+  "creation": "2013-04-22 13:15:44", 
   "docstatus": 0, 
-  "modified": "2013-04-17 17:20:58", 
+  "modified": "2013-05-22 12:05:32", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -340,6 +340,7 @@
   "hidden": 1, 
   "in_filter": 1, 
   "label": "Document Type", 
+  "no_copy": 1, 
   "oldfieldname": "prevdoc_doctype", 
   "oldfieldtype": "Data", 
   "print_hide": 1, 
@@ -371,6 +372,7 @@
   "hidden": 1, 
   "in_filter": 1, 
   "label": "Against Document Date", 
+  "no_copy": 1, 
   "oldfieldname": "prevdoc_date", 
   "oldfieldtype": "Date", 
   "print_hide": 1, 
@@ -383,6 +385,7 @@
   "hidden": 1, 
   "in_filter": 1, 
   "label": "Against Document Detail No", 
+  "no_copy": 1, 
   "oldfieldname": "prevdoc_detail_docname", 
   "oldfieldtype": "Data", 
   "print_hide": 1, 
diff --git a/stock/doctype/purchase_receipt_item/purchase_receipt_item.txt b/stock/doctype/purchase_receipt_item/purchase_receipt_item.txt
index 7f4e827..8cef6a3 100755
--- a/stock/doctype/purchase_receipt_item/purchase_receipt_item.txt
+++ b/stock/doctype/purchase_receipt_item/purchase_receipt_item.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-02-22 01:28:03", 
+  "creation": "2013-03-07 11:42:59", 
   "docstatus": 0, 
-  "modified": "2013-03-07 07:03:28", 
+  "modified": "2013-05-22 12:01:08", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -35,6 +35,7 @@
   "oldfieldtype": "Link", 
   "options": "Item", 
   "print_width": "100px", 
+  "read_only": 0, 
   "reqd": 1, 
   "search_index": 1, 
   "width": "100px"
@@ -48,6 +49,7 @@
   "oldfieldname": "item_name", 
   "oldfieldtype": "Data", 
   "print_hide": 1, 
+  "read_only": 0, 
   "reqd": 1, 
   "search_index": 0
  }, 
@@ -59,6 +61,7 @@
   "oldfieldname": "description", 
   "oldfieldtype": "Text", 
   "print_width": "300px", 
+  "read_only": 0, 
   "reqd": 1, 
   "width": "300px"
  }, 
@@ -72,6 +75,7 @@
   "oldfieldtype": "Currency", 
   "print_hide": 1, 
   "print_width": "100px", 
+  "read_only": 0, 
   "reqd": 1, 
   "width": "100px"
  }, 
@@ -84,6 +88,7 @@
   "oldfieldname": "qty", 
   "oldfieldtype": "Currency", 
   "print_width": "100px", 
+  "read_only": 0, 
   "width": "100px"
  }, 
  {
@@ -97,6 +102,7 @@
   "oldfieldtype": "Currency", 
   "print_hide": 1, 
   "print_width": "100px", 
+  "read_only": 0, 
   "search_index": 0, 
   "width": "100px"
  }, 
@@ -110,6 +116,7 @@
   "options": "UOM", 
   "print_hide": 1, 
   "print_width": "100px", 
+  "read_only": 0, 
   "reqd": 1, 
   "width": "100px"
  }, 
@@ -119,14 +126,16 @@
   "fieldtype": "Currency", 
   "label": "Ref Rate ", 
   "options": "currency", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
   "fieldname": "discount_rate", 
   "fieldtype": "Float", 
   "label": "Discount  %", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 0
  }, 
  {
   "default": "0.00", 
@@ -139,6 +148,7 @@
   "options": "currency", 
   "print_hide": 0, 
   "print_width": "100px", 
+  "read_only": 0, 
   "width": "100px"
  }, 
  {
@@ -157,7 +167,8 @@
   "fieldtype": "Currency", 
   "label": "Ref Rate*", 
   "options": "Company:company:default_currency", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 0
  }, 
  {
   "default": "0.00", 
@@ -170,6 +181,7 @@
   "options": "Company:company:default_currency", 
   "print_hide": 1, 
   "print_width": "100px", 
+  "read_only": 0, 
   "reqd": 1, 
   "width": "100px"
  }, 
@@ -184,6 +196,7 @@
   "options": "Company:company:default_currency", 
   "print_hide": 1, 
   "print_width": "100px", 
+  "read_only": 0, 
   "reqd": 0, 
   "width": "100px"
  }, 
@@ -198,6 +211,7 @@
   "options": "Warehouse", 
   "print_hide": 1, 
   "print_width": "100px", 
+  "read_only": 0, 
   "width": "100px"
  }, 
  {
@@ -209,6 +223,7 @@
   "oldfieldtype": "Currency", 
   "print_hide": 1, 
   "print_width": "100px", 
+  "read_only": 0, 
   "reqd": 1, 
   "width": "100px"
  }, 
@@ -235,6 +250,7 @@
   "oldfieldname": "serial_no", 
   "oldfieldtype": "Text", 
   "print_hide": 0, 
+  "read_only": 0, 
   "report_hide": 0
  }, 
  {
@@ -242,7 +258,8 @@
   "fieldname": "rejected_serial_no", 
   "fieldtype": "Text", 
   "label": "Rejected Serial No", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -252,7 +269,8 @@
   "oldfieldname": "batch_no", 
   "oldfieldtype": "Link", 
   "options": "Batch", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -278,6 +296,7 @@
   "oldfieldname": "schedule_date", 
   "oldfieldtype": "Date", 
   "print_hide": 1, 
+  "read_only": 0, 
   "report_hide": 0, 
   "reqd": 0
  }, 
@@ -288,7 +307,8 @@
   "in_filter": 1, 
   "label": "Project Name", 
   "options": "Project", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -299,7 +319,8 @@
   "oldfieldname": "qa_no", 
   "oldfieldtype": "Link", 
   "options": "Quality Inspection", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -336,6 +357,7 @@
   "oldfieldtype": "Currency", 
   "print_hide": 1, 
   "print_width": "100px", 
+  "read_only": 0, 
   "width": "100px"
  }, 
  {
@@ -344,9 +366,11 @@
   "fieldtype": "Data", 
   "hidden": 1, 
   "label": "Prevdoc Doctype", 
+  "no_copy": 1, 
   "oldfieldname": "prevdoc_doctype", 
   "oldfieldtype": "Data", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -355,7 +379,7 @@
   "hidden": 0, 
   "in_filter": 1, 
   "label": "PO No", 
-  "no_copy": 0, 
+  "no_copy": 1, 
   "oldfieldname": "prevdoc_docname", 
   "oldfieldtype": "Link", 
   "options": "Purchase Order", 
@@ -373,6 +397,7 @@
   "hidden": 1, 
   "in_filter": 1, 
   "label": "PO Date", 
+  "no_copy": 1, 
   "oldfieldname": "prevdoc_date", 
   "oldfieldtype": "Date", 
   "print_hide": 1, 
@@ -418,7 +443,7 @@
   "hidden": 1, 
   "in_filter": 1, 
   "label": "Purchase Order Item No", 
-  "no_copy": 0, 
+  "no_copy": 1, 
   "oldfieldname": "prevdoc_detail_docname", 
   "oldfieldtype": "Data", 
   "print_hide": 1, 
@@ -479,6 +504,7 @@
   "label": "Page Break", 
   "oldfieldname": "page_break", 
   "oldfieldtype": "Check", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 0
  }
 ]
\ No newline at end of file
diff --git a/support/doctype/support_ticket/get_support_mails.py b/support/doctype/support_ticket/get_support_mails.py
index d1fe0dc..82ae9a3 100644
--- a/support/doctype/support_ticket/get_support_mails.py
+++ b/support/doctype/support_ticket/get_support_mails.py
@@ -50,7 +50,7 @@
 				"subject": mail.mail["Subject"],
 				"raised_by": mail.from_email,
 				"content_type": mail.content_type,
-				"status": "Open"
+				"status": "Open",
 			}])
 			ticket.insert()
 			new_ticket = True
@@ -58,7 +58,7 @@
 		mail.save_attachments_in_doc(ticket.doc)
 				
 		make(content=mail.content, sender=mail.from_email, subject = ticket.doc.subject,
-			doctype="Support Ticket", name=ticket.doc.name, 
+			doctype="Support Ticket", name=ticket.doc.name,
 			lead = ticket.doc.lead, contact=ticket.doc.contact, date=mail.date)
 			
 		if new_ticket and cint(self.email_settings.send_autoreply) and \
diff --git a/support/doctype/support_ticket/support_ticket.py b/support/doctype/support_ticket/support_ticket.py
index ca46a8e..63548d3 100644
--- a/support/doctype/support_ticket/support_ticket.py
+++ b/support/doctype/support_ticket/support_ticket.py
@@ -18,7 +18,6 @@
 import webnotes
 
 from utilities.transaction_base import TransactionBase
-from home import update_feed
 from webnotes.utils import now
 
 class DocType(TransactionBase):
@@ -44,6 +43,7 @@
 	
 	def validate(self):
 		self.update_status()
+		self.set_lead_contact(self.doc.raised_by)
 		
 		if self.doc.status == "Closed":
 			from webnotes.widgets.form.assign_to import clear
@@ -51,10 +51,20 @@
 		
 	def on_communication_sent(self, comm):
 		webnotes.conn.set(self.doc, 'status', 'Waiting for Customer')
-		if comm.lead and not self.doc.lead:
-			webnotes.conn.set(self.doc, 'lead', comm.lead)
-		if comm.contact and not self.doc.contact:
-			webnotes.conn.set(self.doc, 'contact', comm.contact)
+		
+		
+	def set_lead_contact(self, email_id):
+		import email.utils
+		email_id = email.utils.parseaddr(email_id)
+		if email_id:
+			if not self.doc.lead:
+				self.doc.lead = webnotes.conn.get_value("Lead", {"email_id": email_id})
+			if not self.doc.contact:
+				self.doc.contact = webnotes.conn.get_value("Contact", {"email_id": email_id})
+				
+			if not self.doc.company:		
+				self.doc.company = webnotes.conn.get_value("Lead", self.doc.lead, "company") or \
+					webnotes.conn.get_default("company")
 			
 	def on_trash(self):
 		webnotes.conn.sql("""update `tabCommunication` set support_ticket=NULL 
diff --git a/support/doctype/support_ticket/support_ticket.txt b/support/doctype/support_ticket/support_ticket.txt
index 769bb9d..50e547e 100644
--- a/support/doctype/support_ticket/support_ticket.txt
+++ b/support/doctype/support_ticket/support_ticket.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-01-31 22:22:27", 
+  "creation": "2013-02-01 10:36:25", 
   "docstatus": 0, 
-  "modified": "2013-01-31 22:17:24", 
+  "modified": "2013-05-21 16:27:46", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -23,13 +23,18 @@
   "permlevel": 0
  }, 
  {
+  "amend": 0, 
+  "create": 1, 
   "doctype": "DocPerm", 
   "name": "__common__", 
   "parent": "Support Ticket", 
   "parentfield": "permissions", 
   "parenttype": "DocType", 
+  "permlevel": 0, 
   "read": 1, 
-  "submit": 0
+  "report": 1, 
+  "submit": 0, 
+  "write": 1
  }, 
  {
   "doctype": "DocType", 
@@ -192,6 +197,15 @@
   "read_only": 1
  }, 
  {
+  "doctype": "DocField", 
+  "fieldname": "company", 
+  "fieldtype": "Link", 
+  "label": "Company", 
+  "options": "Company", 
+  "print_hide": 1, 
+  "reqd": 0
+ }, 
+ {
   "depends_on": "eval:!doc.__islocal", 
   "doctype": "DocField", 
   "fieldname": "column_break1", 
@@ -237,51 +251,18 @@
   "label": "Content Type"
  }, 
  {
-  "amend": 0, 
   "cancel": 0, 
-  "create": 1, 
   "doctype": "DocPerm", 
-  "permlevel": 0, 
-  "report": 1, 
-  "role": "Guest", 
-  "write": 1
+  "role": "Guest"
  }, 
  {
-  "create": 1, 
+  "cancel": 0, 
   "doctype": "DocPerm", 
-  "match": "customer", 
-  "permlevel": 0, 
-  "report": 1, 
-  "role": "Customer", 
-  "write": 1
+  "role": "Customer"
  }, 
  {
   "cancel": 1, 
-  "create": 1, 
   "doctype": "DocPerm", 
-  "permlevel": 0, 
-  "report": 1, 
-  "role": "Support Team", 
-  "write": 1
- }, 
- {
-  "amend": 0, 
-  "cancel": 0, 
-  "create": 0, 
-  "doctype": "DocPerm", 
-  "match": "", 
-  "permlevel": 1, 
-  "report": 1, 
-  "role": "Support Team", 
-  "write": 1
- }, 
- {
-  "amend": 0, 
-  "cancel": 0, 
-  "create": 0, 
-  "doctype": "DocPerm", 
-  "match": "", 
-  "permlevel": 2, 
   "role": "Support Team"
  }
 ]
\ No newline at end of file
diff --git a/website/doctype/blog_post/blog_post.py b/website/doctype/blog_post/blog_post.py
index 05236a1..62cc910 100644
--- a/website/doctype/blog_post/blog_post.py
+++ b/website/doctype/blog_post/blog_post.py
@@ -76,10 +76,12 @@
 		self.doc.full_name = get_fullname(self.doc.owner)
 		self.doc.updated = global_date_format(self.doc.published_on)
 		self.doc.content_html = self.doc.content
+		
 		if self.doc.blogger:
 			self.doc.blogger_info = webnotes.doc("Blogger", self.doc.blogger).fields
 		
 		self.doc.description = self.doc.blog_intro or self.doc.content[:140]
+		self.doc.meta_description = self.doc.description
 		
 		self.doc.categories = webnotes.conn.sql_list("select name from `tabBlog Category` order by name")
 		
diff --git a/website/doctype/web_page/web_page.py b/website/doctype/web_page/web_page.py
index d43bcb4..6d0cafa 100644
--- a/website/doctype/web_page/web_page.py
+++ b/website/doctype/web_page/web_page.py
@@ -44,3 +44,5 @@
 		if self.doc.slideshow:
 			from website.helpers.slideshow import get_slideshow
 			get_slideshow(self)
+			
+		self.doc.meta_description = self.doc.description