Merge pull request #831 from fogueri/master

[docs] updated toc and added projects docs
diff --git a/accounts/Print Format/POS Invoice/POS Invoice.txt b/accounts/Print Format/POS Invoice/POS Invoice.txt
index ebf25e4..aab8e18 100644
--- a/accounts/Print Format/POS Invoice/POS Invoice.txt
+++ b/accounts/Print Format/POS Invoice/POS Invoice.txt
@@ -2,14 +2,14 @@
  {
   "creation": "2011-12-21 11:08:55", 
   "docstatus": 0, 
-  "modified": "2013-08-30 12:46:21", 
+  "modified": "2013-09-13 17:17:47", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
  {
   "doc_type": "Sales Invoice", 
   "doctype": "Print Format", 
-  "html": "<html>\n<head>\n<!--Item Table, Totals and Other Charges-->\n<script>\nfunction get_print_format() {\n\tvar oc = getchildren('Sales Invoice Item', doc.name, 'entries');\n\tvar rows = '<table width=\"100%\" cellpadding=\"0\" class=\"cart\">\\\n                <tr>\\\n                    <td colspan=\"3\"><hr></td>\\\n                </tr>\\\n                <tr>\\\n                    <td width=\"60%\" align=\"left\">ITEM CODE/DESC.</td>\\\n                    <td width=\"10%\" align=\"right\">QTY</td>\\\n                    <td width=\"30%\" align=\"right\">RATE</td>\\\n                </tr>\\\n                <tr>\\\n                    <td colspan=\"3\"><hr></td>\\\n                </tr>';\n\tfor (var x=0; x<oc.length; x++) {\n\t\trows += '<tr>\\\n                    <td align=\"left\">' + oc[x].item_code + '<br>' + oc[x].item_name + '</td>\\\n                    <td align=\"right\" style=\"vertical-align:top;\">' + oc[x].qty + '</td>\\\n                    <td align=\"right\" valign=\"top\">' + format_currency(oc[x].export_amount) + '</td>\\\n                </tr>';\n\t}\n    rows += '<tr>\\\n                <td colspan=\"3\"><hr></td>\\\n            </tr>\\\n            <tr>\\\n                <td colspan=\"2\" align=\"right\">Net Total</td>\\\n                <td align=\"right\">' + format_currency(doc.net_total_export) + '</td>\\\n            </tr>';\n    if (doc.other_charges_total_export != 0) {\n        var taxes = wn.model.get_children(\"Sales Taxes and Charges\", doc.name, \"other_charges\", \"Sales Invoice\");\n\t\t$.each(taxes, function(i, d) {\n\t\t\trows += '<tr>\\\n        \t\t\t\t<td colspan=\"2\" align=\"right\">' + d.description + '</td>\\\n        \t\t\t\t<td style=\"text-align: right;\">' + format_currency(d.tax_amount) + '</td>\\\n        \t\t\t<tr>';\n\t\t});\n    }\n    rows += '<tr>\\\n                <td colspan=\"2\" align=\"right\" style=\"vertical-align:middle;\">Grand Total</td>\\\n                <td align=\"right\"><hr width=\"90%\" align=\"right\">' + format_currency(doc.grand_total_export) + '<br>\\\n                    <hr width=\"90%\" align=\"right\"></td>\\\n            </tr>\\\n            <tr>\\\n                <td align=\"center\" colspan=\"3\">Thank You. Please visit again.</td>\\\n            </tr>\\\n            </table>';\n\treturn rows;\n}\n</script>\n<style>\n    table, tr, td, div, p {\n        font-family: Monospace;\n        line-height: 200%;\n    }\n    h1, h2, h3, h4, h5, h6 {\n        text-align: center;\n    }\n\t@media screen {\n\t\tbody {\n\t\t\twidth: 4in;\n\t\t}\n\t}\n</style>\n</head>\n\n<body>\n<table width=\"100%\" cellpadding=\"4\">\n    <tr>\n        <td align=\"left\">RECEIPT NO: <script>doc.name</script></td>\n        <td align=\"right\">DATE: <script>date.str_to_user(doc.posting_date)</script></td>\n    </tr>\n    <tr>\n        <td>M/s <script>doc.customer</script></td>\n    </tr>\n</table>\n<!--Item Table & Totals-->\n<div><script>get_print_format();</script></div>\n</body>\n</html>\n", 
+  "html": "<html>\n<head>\n<!--Item Table, Totals and Other Charges-->\n<script>\nfunction get_print_format() {\n    var oc = getchildren('Sales Invoice Item', doc.name, 'entries');\n\tvar rows = '<table width=\"100%\" cellpadding=\"0\" class=\"cart\">\\\n                <tr>\\\n                    <td colspan=\"3\"><hr></td>\\\n                </tr>\\\n                <tr>\\\n                    <td width=\"60%\" align=\"left\">ITEM NAME.</td>\\\n                    <td width=\"10%\" align=\"right\">QTY</td>\\\n                    <td width=\"30%\" align=\"right\">AMOUNT</td>\\\n                </tr>\\\n                <tr>\\\n                    <td colspan=\"3\"><hr></td>\\\n                </tr>';\n\tfor (var x=0; x<oc.length; x++) {\n        console.log(oc[x].item_code!=oc[x].item_name);\n\t\trows += '<tr>\\\n                    <td align=\"left\">' + oc[x].item_code + \n                        (oc[x].item_code!=oc[x].item_name ? ('<br>' + oc[x].item_name) : '') + '</td>\\\n                    <td align=\"right\" style=\"vertical-align:top;\">' + oc[x].qty + '</td>\\\n                    <td align=\"right\" valign=\"top\">' + format_currency(oc[x].export_amount, doc.currency) + '</td>\\\n                </tr>';\n\t}\n    rows += '<tr>\\\n                <td colspan=\"3\"><hr></td>\\\n            </tr>\\\n            <tr>\\\n                <td colspan=\"2\" align=\"right\">Net Total</td>\\\n                <td align=\"right\">' + format_currency(doc.net_total_export, doc.currency) + '</td>\\\n            </tr>';\n    if (doc.other_charges_total_export != 0) {\n        var taxes = wn.model.get_children(\"Sales Taxes and Charges\", doc.name, \"other_charges\", \"Sales Invoice\");\n\t\t$.each(taxes, function(i, d) {\n\t\t\trows += '<tr>\\\n        \t\t\t\t<td colspan=\"2\" align=\"right\">' + d.description + '</td>\\\n        \t\t\t\t<td style=\"text-align: right;\">' + format_currency(d.tax_amount / doc.conversion_rate, doc.currency) + '</td>\\\n        \t\t\t<tr>';\n\t\t});\n    }\n    rows += '<tr>\\\n                <td colspan=\"2\" align=\"right\" style=\"vertical-align:middle;\">Grand Total</td>\\\n                <td align=\"right\"><hr width=\"90%\" align=\"right\">' + format_currency(doc.grand_total_export, doc.currency) + '<br>\\\n                    <hr width=\"90%\" align=\"right\"></td>\\\n            </tr>\\\n            <tr>\\\n                <td align=\"center\" colspan=\"3\">Thank You. Please visit again.</td>\\\n            </tr>\\\n            </table>';\n\treturn rows;\n}\n</script>\n<style>\n    table, tr, td, div, p {\n        font-family: Monospace;\n        line-height: 200%;\n    }\n    h1, h2, h3, h4, h5, h6 {\n        text-align: center;\n    }\n\t@media screen {\n\t\tbody {\n\t\t\twidth: 4in;\n\t\t}\n\t}\n</style>\n</head>\n\n<body>\n<table width=\"100%\" cellpadding=\"4\">\n    <tr>\n        <td align=\"left\">RECEIPT NO: <script>doc.name</script></td>\n        <td align=\"right\">DATE: <script>date.str_to_user(doc.posting_date)</script></td>\n    </tr>\n    <tr>\n        <td>M/s <script>doc.customer</script></td>\n    </tr>\n</table>\n<!--Item Table & Totals-->\n<div><script>get_print_format();</script></div>\n</body>\n</html>\n", 
   "module": "Accounts", 
   "name": "__common__", 
   "print_format_type": "Client", 
diff --git a/buying/doctype/purchase_order/purchase_order.txt b/buying/doctype/purchase_order/purchase_order.txt
index 1134d95..d3c1620 100644
--- a/buying/doctype/purchase_order/purchase_order.txt
+++ b/buying/doctype/purchase_order/purchase_order.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-05-21 16:16:39", 
   "docstatus": 0, 
-  "modified": "2013-08-09 14:45:51", 
+  "modified": "2013-09-12 18:34:54", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -132,6 +132,7 @@
   "fieldtype": "Date", 
   "in_filter": 1, 
   "label": "Purchase Order Date", 
+  "no_copy": 1, 
   "oldfieldname": "transaction_date", 
   "oldfieldtype": "Date", 
   "reqd": 1, 
diff --git a/buying/doctype/supplier/supplier.py b/buying/doctype/supplier/supplier.py
index 75b2e03..ccdeae9 100644
--- a/buying/doctype/supplier/supplier.py
+++ b/buying/doctype/supplier/supplier.py
@@ -132,14 +132,10 @@
 			sql("delete from `tabAddress` where name=%s",(rec['name']))
 	
 	def delete_supplier_contact(self):
-		for rec in sql("select * from `tabContact` where supplier=%s", (self.doc.name,), as_dict=1):
-			sql("delete from `tabContact` where name=%s",(rec['name']))
-			
-	def delete_supplier_communication(self):
-		webnotes.conn.sql("""\
-			delete from `tabCommunication`
-			where supplier = %s and customer is null""", self.doc.name)
-			
+		for contact in webnotes.conn.sql_list("""select name from `tabContact` 
+			where supplier=%s""", self.doc.name):
+				webnotes.delete_doc("Contact", contact)
+	
 	def delete_supplier_account(self):
 		"""delete supplier's ledger if exist and check balance before deletion"""
 		acc = sql("select name from `tabAccount` where master_type = 'Supplier' \
diff --git a/hr/doctype/job_applicant/job_applicant.py b/hr/doctype/job_applicant/job_applicant.py
index 9927230..9bf1b96 100644
--- a/hr/doctype/job_applicant/job_applicant.py
+++ b/hr/doctype/job_applicant/job_applicant.py
@@ -21,9 +21,4 @@
 		else:
 			status = "Open"
 			
-		webnotes.conn.set(self.doc, 'status', status)
-
-	def on_trash(self):
-		webnotes.conn.sql("""delete from `tabCommunication` 
-			where job_applicant=%s""", self.doc.name)
-		
\ No newline at end of file
+		webnotes.conn.set(self.doc, 'status', status)
\ No newline at end of file
diff --git a/install_erpnext.py b/install_erpnext.py
index c57a9e2..70cc2aa 100644
--- a/install_erpnext.py
+++ b/install_erpnext.py
@@ -149,6 +149,7 @@
 		exec_in_shell("easy_install pip")
 	
 	exec_in_shell("pip install --upgrade pip")
+	exec_in_shell("pip install --upgrade setuptools")
 	exec_in_shell("pip install --upgrade virtualenv")
 	exec_in_shell("pip install -q %s" % python_modules)
 	
diff --git a/patches/december_2012/address_title.py b/patches/december_2012/address_title.py
index fc7d2ba..13dd74d 100644
--- a/patches/december_2012/address_title.py
+++ b/patches/december_2012/address_title.py
@@ -9,9 +9,6 @@
 	webnotes.conn.sql("""update tabAddress set address_title = customer_name where ifnull(customer_name,'')!=''""")
 	webnotes.conn.sql("""update tabAddress set address_title = supplier_name where ifnull(supplier_name,'')!=''""")
 	webnotes.conn.sql("""update tabAddress set address_title = sales_partner where ifnull(sales_partner,'')!=''""")
-
-	webnotes.reload_doc("website", "doctype", "product_settings")
-	webnotes.reset_perms("Product Settings")
 	
 	# move code to new doctype
 	webnotes.conn.set_value("Website Script", None, "javascript", 
diff --git a/patches/june_2013/p03_buying_selling_for_price_list.py b/patches/june_2013/p03_buying_selling_for_price_list.py
index c71646a..931517e 100644
--- a/patches/june_2013/p03_buying_selling_for_price_list.py
+++ b/patches/june_2013/p03_buying_selling_for_price_list.py
@@ -1,21 +1,29 @@
 # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
 # License: GNU General Public License v3. See license.txt
 
+from __future__ import unicode_literals
 import webnotes
 from webnotes.utils import cint
+import MySQLdb
 
 def execute():
 	webnotes.reload_doc("setup", "doctype", "price_list")
 	webnotes.reload_doc("stock", "doctype", "item_price")
 	
-	for price_list in webnotes.conn.sql_list("""select name from `tabPrice List`"""):
-		buying, selling = False, False
-		for b, s in webnotes.conn.sql("""select distinct buying, selling 
-			from `tabItem Price` where price_list_name=%s""", price_list):
-				buying = buying or cint(b)
-				selling = selling or cint(s)
+	try:
+		for price_list in webnotes.conn.sql_list("""select name from `tabPrice List`"""):
+			buying, selling = False, False
+			for b, s in webnotes.conn.sql("""select distinct buying, selling 
+				from `tabItem Price` where price_list_name=%s""", price_list):
+					buying = buying or cint(b)
+					selling = selling or cint(s)
 		
-		buying_or_selling = "Selling" if selling else "Buying"
-		webnotes.conn.set_value("Price List", price_list, "buying_or_selling", buying_or_selling)
-		webnotes.conn.sql("""update `tabItem Price` set buying_or_selling=%s 
-			where price_list_name=%s""", (buying_or_selling, price_list))
+			buying_or_selling = "Selling" if selling else "Buying"
+			webnotes.conn.set_value("Price List", price_list, "buying_or_selling", buying_or_selling)
+			webnotes.conn.sql("""update `tabItem Price` set buying_or_selling=%s 
+				where price_list_name=%s""", (buying_or_selling, price_list))
+	except MySQLdb.OperationalError, e:
+		if e.args[0] == 1054:
+			webnotes.conn.sql("""update `tabItem Price` set buying_or_selling="Selling" """)
+		else:
+			raise e
diff --git a/patches/september_2013/p01_update_communication.py b/patches/september_2013/p01_update_communication.py
index d840c80..3131738 100644
--- a/patches/september_2013/p01_update_communication.py
+++ b/patches/september_2013/p01_update_communication.py
@@ -1,15 +1,22 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
 import webnotes
+import MySQLdb
 
 def execute():
+	webnotes.reload_doc("core", "doctype", "communication")
+	webnotes.conn.sql("""update tabCommunication set communication_date = creation where 
+		ifnull(communication_date, '')='' """)
+	
 	for doctype in ("Contact", "Lead", "Job Applicant", "Supplier", "Customer", "Quotation", "Sales Person", "Support Ticket"):
-		fieldname = doctype.replace(" ", '_').lower()
-		webnotes.conn.sql("""update tabCommunication
-			set parenttype=%s, parentfield='communications', 
-			parent=`%s` 
-			where ifnull(`%s`, '')!=''""" % ("%s", fieldname, fieldname), doctype)
-			
-		webnotes.reload_doc("core", "doctype", "communication")
-			
-		webnotes.conn.sql("""update tabCommunication set communication_date = creation where 
-			ifnull(communication_date, '')='' """)
-	
\ No newline at end of file
+		try:
+			fieldname = doctype.replace(" ", '_').lower()
+			webnotes.conn.sql("""update tabCommunication
+				set parenttype=%s, parentfield='communications', 
+				parent=`%s` 
+				where ifnull(`%s`, '')!=''""" % ("%s", fieldname, fieldname), doctype)
+		except MySQLdb.OperationalError, e:
+			if e.args[0] != 1054:
+				raise e
diff --git a/selling/doctype/customer/customer.py b/selling/doctype/customer/customer.py
index fb3c006..d3a263f 100644
--- a/selling/doctype/customer/customer.py
+++ b/selling/doctype/customer/customer.py
@@ -126,14 +126,10 @@
 				webnotes.conn.sql("""delete from `tabAddress` where name=%s""", name)
 	
 	def delete_customer_contact(self):
-		for rec in sql("select * from `tabContact` where customer=%s", (self.doc.name,), as_dict=1):
-			sql("delete from `tabContact` where name=%s",(rec['name']))
+		for contact in webnotes.conn.sql_list("""select name from `tabContact` 
+			where customer=%s""", self.doc.name):
+				webnotes.delete_doc("Contact", contact)
 	
-	def delete_customer_communication(self):
-		webnotes.conn.sql("""\
-			delete from `tabCommunication`
-			where customer = %s and supplier is null""", self.doc.name)
-			
 	def delete_customer_account(self):
 		"""delete customer's ledger if exist and check balance before deletion"""
 		acc = sql("select name from `tabAccount` where master_type = 'Customer' \
@@ -145,7 +141,6 @@
 	def on_trash(self):
 		self.delete_customer_address()
 		self.delete_customer_contact()
-		self.delete_customer_communication()
 		self.delete_customer_account()
 		if self.doc.lead_name:
 			sql("update `tabLead` set status='Interested' where name=%s",self.doc.lead_name)
diff --git a/selling/doctype/lead/lead.py b/selling/doctype/lead/lead.py
index 1aff8c8..da11410 100644
--- a/selling/doctype/lead/lead.py
+++ b/selling/doctype/lead/lead.py
@@ -80,7 +80,6 @@
 		return webnotes.conn.get_value('Sales Email Settings',None,'email_id')
 
 	def on_trash(self):
-		webnotes.conn.sql("""update tabCommunication set lead=null where lead=%s""", self.doc.name)
 		webnotes.conn.sql("""update `tabSupport Ticket` set lead='' where lead=%s""",
 			self.doc.name)
 		
diff --git a/selling/doctype/quotation/quotation.py b/selling/doctype/quotation/quotation.py
index 588d8d6..44a67fa 100644
--- a/selling/doctype/quotation/quotation.py
+++ b/selling/doctype/quotation/quotation.py
@@ -204,11 +204,6 @@
 			print_lst.append(lst1)
 		return print_lst
 	
-	def update_followup_details(self):
-		sql("delete from `tabCommunication Log` where parent = '%s'"%self.doc.name)
-		for d in getlist(self.doclist, 'follow_up'):
-			d.save()
-
 @webnotes.whitelist()
 def make_sales_order(source_name, target_doclist=None):
 	return _make_sales_order(source_name, target_doclist)
diff --git a/startup/install.py b/startup/install.py
index ea281b8..655573f 100644
--- a/startup/install.py
+++ b/startup/install.py
@@ -64,7 +64,8 @@
 
 def feature_setup():
 	"""save global defaults and features setup"""
-	doc = webnotes.doc("Features Setup", "Features Setup")
+	bean = webnotes.bean("Features Setup", "Features Setup")
+	bean.ignore_permissions = True
 
 	# store value as 1 for all these fields
 	flds = ['fs_item_serial_nos', 'fs_item_batch_nos', 'fs_brands', 'fs_item_barcode',
@@ -74,8 +75,8 @@
 		'fs_recurring_invoice', 'fs_pos', 'fs_manufacturing', 'fs_quality',
 		'fs_page_break', 'fs_more_info', 'fs_pos_view'
 	]
-	doc.fields.update(dict(zip(flds, [1]*len(flds))))
-	doc.save()
+	bean.doc.fields.update(dict(zip(flds, [1]*len(flds))))
+	bean.save()
 
 def import_country_and_currency():
 	from webnotes.country_info import get_all
diff --git a/utilities/doctype/contact/contact.py b/utilities/doctype/contact/contact.py
index a116edb..84c8a59 100644
--- a/utilities/doctype/contact/contact.py
+++ b/utilities/doctype/contact/contact.py
@@ -55,7 +55,5 @@
 					self.doc.is_primary_contact = 1
 
 	def on_trash(self):
-		webnotes.conn.sql("""update tabCommunication set contact='' where contact=%s""",
-			self.doc.name)
 		webnotes.conn.sql("""update `tabSupport Ticket` set contact='' where contact=%s""",
 			self.doc.name)
\ No newline at end of file