Merge branch 'master' into edge
diff --git a/accounts/doctype/cost_center/cost_center.py b/accounts/doctype/cost_center/cost_center.py
index 8340a8b..e57b6a3 100644
--- a/accounts/doctype/cost_center/cost_center.py
+++ b/accounts/doctype/cost_center/cost_center.py
@@ -17,7 +17,7 @@
 from __future__ import unicode_literals
 import webnotes
 from webnotes.model.bean import getlist
-from webnotes import msgprint
+from webnotes import msgprint, _
 
 from webnotes.utils.nestedset import DocTypeNestedSet
 
@@ -37,6 +37,8 @@
 			
 		if self.doc.cost_center_name != 'Root' and not self.doc.parent_cost_center:
 			msgprint("Please enter parent cost center", raise_exception=1)
+		elif self.doc.cost_center_name == "Root" and self.doc.parent_cost_center:
+			msgprint(_("Root cannot have a parent cost center"), raise_exception=1)
 		
 	def convert_group_to_ledger(self):
 		if self.check_if_child_exists():
diff --git a/accounts/doctype/pos_setting/pos_setting.js b/accounts/doctype/pos_setting/pos_setting.js
index 237615b..3ba60b4 100755
--- a/accounts/doctype/pos_setting/pos_setting.js
+++ b/accounts/doctype/pos_setting/pos_setting.js
@@ -53,4 +53,15 @@
 	return 'SELECT `tabPrint Heading`.name FROM `tabPrint Heading` WHERE `tabPrint Heading`.docstatus !=2 AND `tabPrint Heading`.name LIKE "%s" ORDER BY `tabPrint Heading`.name ASC LIMIT 50';
 }
 
+cur_frm.fields_dict["expense_account"].get_query = function(doc) {
+	return {
+		"query": "accounts.utils.get_account_list", 
+		"filters": {
+			"is_pl_account": "Yes",
+			"debit_or_credit": "Debit",
+			"company": doc.company
+		}
+	}
+}
+
 cur_frm.fields_dict.user.get_query = erpnext.utils.profile_query;
\ No newline at end of file
diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py
index 85fdb47..50d5d43 100644
--- a/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -76,7 +76,11 @@
 		self.update_valuation_rate("entries")
 
 	def get_credit_to(self):
-		acc_head = sql("select name, credit_days from `tabAccount` where (name = %s or (master_name = %s and master_type = 'supplier')) and docstatus != 2", (cstr(self.doc.supplier) + " - " + self.company_abbr,self.doc.supplier))		
+		acc_head = sql("""select name, credit_days from `tabAccount` 
+			where (name = %s or (master_name = %s and master_type = 'supplier')) 
+			and docstatus != 2 and company = %s""", 
+			(cstr(self.doc.supplier) + " - " + self.company_abbr, 
+			self.doc.supplier, self.doc.company))
 
 		ret = {}
 		if acc_head and acc_head[0][0]:
@@ -217,7 +221,8 @@
 	# 3. Is not a PL Account
 	# ----------------------------
 	def validate_credit_acc(self):
-		acc = sql("select debit_or_credit, is_pl_account from tabAccount where name = '%s'" % self.doc.credit_to)
+		acc = sql("select debit_or_credit, is_pl_account from tabAccount where name = %s", 
+			self.doc.credit_to)
 		if not acc:
 			msgprint("Account: "+ self.doc.credit_to + "does not exist")
 			raise Exception
@@ -409,7 +414,7 @@
 		purchase_controller.update_prevdoc_detail(self, is_submit = 1)
 
 
-	def make_gl_entries(self, is_cancel = 0):
+	def make_gl_entries(self):
 		from accounts.general_ledger import make_gl_entries
 		auto_inventory_accounting = \
 			cint(webnotes.defaults.get_global_default("auto_inventory_accounting"))
@@ -426,7 +431,7 @@
 					"remarks": self.doc.remarks,
 					"against_voucher": self.doc.name,
 					"against_voucher_type": self.doc.doctype,
-				}, is_cancel)
+				})
 			)
 	
 		# tax table gl entries
@@ -441,7 +446,7 @@
 						"credit": tax.add_deduct_tax == "Deduct" and tax.tax_amount or 0,
 						"remarks": self.doc.remarks,
 						"cost_center": tax.cost_center
-					}, is_cancel)
+					})
 				)
 			
 			# accumulate valuation tax
@@ -469,7 +474,7 @@
 							"debit": flt(item.valuation_rate) * flt(item.conversion_factor) \
 								*  flt(item.qty),
 							"remarks": self.doc.remarks or "Accounting Entry for Stock"
-						}, is_cancel)
+						})
 					)
 			
 			elif flt(item.amount):
@@ -481,7 +486,7 @@
 						"debit": item.amount,
 						"remarks": self.doc.remarks,
 						"cost_center": item.cost_center
-					}, is_cancel)
+					})
 				)
 				
 		if stock_item_and_auto_inventory_accounting and valuation_tax:
@@ -494,7 +499,7 @@
 					"against": self.doc.credit_to,
 					"credit": valuation_tax,
 					"remarks": self.doc.remarks or "Accounting Entry for Stock"
-				}, is_cancel)
+				})
 			)
 		
 		# writeoff account includes petty difference in the invoice amount 
@@ -507,19 +512,19 @@
 					"credit": flt(self.doc.write_off_amount),
 					"remarks": self.doc.remarks,
 					"cost_center": self.doc.write_off_cost_center
-				}, is_cancel)
+				})
 			)
 		
 		if gl_entries:
-			make_gl_entries(gl_entries, cancel=is_cancel)
+			make_gl_entries(gl_entries, cancel=(self.doc.docstatus == 2))
 
 	def on_cancel(self):
 		from accounts.utils import remove_against_link_from_jv
 		remove_against_link_from_jv(self.doc.doctype, self.doc.name, "against_voucher")
-		
-		self.make_gl_entries(is_cancel=1)
 		get_obj(dt = 'Purchase Common').update_prevdoc_detail(self, is_submit = 0)
 		
+		self.make_cancel_gl_entries()
+		
 	def on_update(self):
 		pass
 		
diff --git a/accounts/doctype/purchase_invoice_item/purchase_invoice_item.txt b/accounts/doctype/purchase_invoice_item/purchase_invoice_item.txt
index b8d9a1d..5e9daf7 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-02-27 13:45:00", 
+  "creation": "2013-03-07 11:42:55", 
   "docstatus": 0, 
-  "modified": "2013-03-07 07:03:26", 
+  "modified": "2013-03-29 13:44:37", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -35,6 +35,7 @@
   "oldfieldtype": "Link", 
   "options": "Item", 
   "print_hide": 1, 
+  "read_only": 0, 
   "reqd": 0, 
   "search_index": 1
  }, 
@@ -46,6 +47,7 @@
   "label": "Item Name", 
   "oldfieldname": "item_name", 
   "oldfieldtype": "Data", 
+  "read_only": 0, 
   "reqd": 1, 
   "search_index": 0
  }, 
@@ -57,6 +59,7 @@
   "oldfieldname": "description", 
   "oldfieldtype": "Text", 
   "print_width": "300px", 
+  "read_only": 0, 
   "width": "300px"
  }, 
  {
@@ -67,6 +70,7 @@
   "oldfieldname": "qty", 
   "oldfieldtype": "Currency", 
   "print_hide": 0, 
+  "read_only": 0, 
   "reqd": 1
  }, 
  {
@@ -75,7 +79,8 @@
   "fieldtype": "Link", 
   "label": "UOM", 
   "options": "UOM", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -83,14 +88,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", 
@@ -101,6 +108,7 @@
   "oldfieldtype": "Currency", 
   "options": "currency", 
   "print_hide": 0, 
+  "read_only": 0, 
   "reqd": 1
  }, 
  {
@@ -120,7 +128,8 @@
   "fieldtype": "Currency", 
   "label": "Ref Rate*", 
   "options": "Company:company:default_currency", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -131,6 +140,7 @@
   "oldfieldtype": "Currency", 
   "options": "Company:company:default_currency", 
   "print_hide": 1, 
+  "read_only": 0, 
   "reqd": 1
  }, 
  {
@@ -155,7 +165,8 @@
   "options": "Account", 
   "print_hide": 1, 
   "print_width": "120px", 
-  "reqd": 1, 
+  "read_only": 0, 
+  "reqd": 0, 
   "width": "120px"
  }, 
  {
@@ -168,6 +179,7 @@
   "options": "Cost Center", 
   "print_hide": 1, 
   "print_width": "120px", 
+  "read_only": 0, 
   "width": "120px"
  }, 
  {
@@ -177,7 +189,8 @@
   "in_filter": 1, 
   "label": "Project Name", 
   "options": "Project", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -187,7 +200,8 @@
   "label": "Brand", 
   "oldfieldname": "brand", 
   "oldfieldtype": "Data", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -298,7 +312,8 @@
   "fieldname": "conversion_factor", 
   "fieldtype": "Float", 
   "label": "Conversion Factor", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -319,6 +334,7 @@
   "label": "Page Break", 
   "no_copy": 1, 
   "print_hide": 1, 
+  "read_only": 0, 
   "report_hide": 1
  }
 ]
\ No newline at end of file
diff --git a/accounts/doctype/sales_invoice/sales_invoice.js b/accounts/doctype/sales_invoice/sales_invoice.js
index 9532a54..e93a206 100644
--- a/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/accounts/doctype/sales_invoice/sales_invoice.js
@@ -80,7 +80,8 @@
 	'total_commission', 'advances'];
 	
 	item_flds_normal = ['sales_order', 'delivery_note']
-	item_flds_pos = ['warehouse', 'serial_no', 'batch_no', 'actual_qty', 'delivered_qty']
+	item_flds_pos = ['warehouse', 'serial_no', 'batch_no', 'actual_qty', 
+		'delivered_qty', 'expense_account']
 	
 	if(cint(doc.is_pos) == 1) {
 		hide_field(par_flds);
diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py
index 1003a8e..f44a787 100644
--- a/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/accounts/doctype/sales_invoice/sales_invoice.py
@@ -16,6 +16,7 @@
 
 from __future__ import unicode_literals
 import webnotes
+import webnotes.defaults
 
 from webnotes.utils import add_days, cint, cstr, date_diff, flt, getdate, nowdate, \
 	get_first_day, get_last_day
@@ -131,7 +132,7 @@
 
 		sales_com_obj.update_prevdoc_detail(0, self)
 		
-		self.make_gl_entries()
+		self.make_cancel_gl_entries()
 		
 	def on_update_after_submit(self):
 		self.validate_recurring_invoice()
diff --git a/accounts/doctype/sales_invoice_item/sales_invoice_item.txt b/accounts/doctype/sales_invoice_item/sales_invoice_item.txt
index dee0e85..98962b5 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-03-26 11:03:08", 
+  "creation": "2013-03-29 18:21:58", 
   "docstatus": 0, 
-  "modified": "2013-03-28 15:42:14", 
+  "modified": "2013-03-29 19:32:32", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -223,7 +223,7 @@
   "fieldname": "cost_center", 
   "fieldtype": "Link", 
   "in_filter": 1, 
-  "label": "Sales Cost Center", 
+  "label": "Cost Center", 
   "oldfieldname": "cost_center", 
   "oldfieldtype": "Link", 
   "options": "Cost Center", 
diff --git a/accounts/utils.py b/accounts/utils.py
index d6b2043..755546c 100644
--- a/accounts/utils.py
+++ b/accounts/utils.py
@@ -264,48 +264,61 @@
 	from webnotes.utils import nowdate
 	today = nowdate()
 	fiscal_year = get_fiscal_year(today)[0]
+	jv_list = []
 	
 	for company in webnotes.conn.sql_list("select name from `tabCompany`"):
 		stock_rbnb_value = get_stock_rbnb_value(company)
+		stock_rbnb_value = reverse and -1*stock_rbnb_value or stock_rbnb_value
+		if stock_rbnb_value:
+			jv = webnotes.bean([
+				{
+					"doctype": "Journal Voucher",
+					"naming_series": "_PATCH-",
+					"company": company,
+					"posting_date": today,
+					"fiscal_year": fiscal_year,
+					"voucher_type": "Journal Entry",
+					"user_remark": "Accounting Entry for Stock: \
+						Initial booking of stock received but not billed account"
+				},
+				{
+					"doctype": "Journal Voucher Detail",
+					"parentfield": "entries",
+					"account": get_company_default(company, "stock_received_but_not_billed"),
+					(stock_rbnb_value > 0 and "credit" or "debit"): abs(stock_rbnb_value)
+				},
+				{
+					"doctype": "Journal Voucher Detail",
+					"parentfield": "entries",
+					"account": get_company_default(company, "stock_adjustment_account"),
+					(stock_rbnb_value > 0 and "debit" or "credit"): abs(stock_rbnb_value),
+					"cost_center": get_company_default(company, "stock_adjustment_cost_center")
+				},
+			])
+			jv.insert()
+			jv.submit()
+			
+			jv_list.append(jv.doc.name)
+	
+	if jv_list:
+		webnotes.msgprint("""Folowing Journal Vouchers has been created automatically: 
+			%s""" % '\n'.join(jv_list))
+			
+	webnotes.msgprint("""Please refresh the system to get effect of Auto Inventory Accounting""")
+			
 		
-		jv = webnotes.bean([
-			{
-				"doctype": "Journal Voucher",
-				"naming_series": "_PATCH-",
-				"company": company,
-				"posting_date": today,
-				"fiscal_year": fiscal_year,
-				"voucher_type": "Journal Entry"
-			},
-			{
-				"doctype": "Journal Voucher Detail",
-				"parentfield": "entries",
-				"account": get_company_default(company, "stock_received_but_not_billed"),
-				(reverse and "debit" or "credit"): stock_rbnb_value
-			},
-			{
-				"doctype": "Journal Voucher Detail",
-				"parentfield": "entries",
-				"account": get_company_default(company, "stock_adjustment_account"),
-				(reverse and "credit" or "debit"): stock_rbnb_value
-			},
-		])
-		jv.insert()
-		jv.submit()
-		
-def get_stock_rbnb_value(company):	
-	total_received_amount = webnotes.conn.sql("""select sum(valuation_rate*qty) 
+def get_stock_rbnb_value(company):
+	total_received_amount = webnotes.conn.sql("""select sum(valuation_rate*qty*conversion_factor) 
 		from `tabPurchase Receipt Item` pr_item where docstatus=1 
 		and exists(select name from `tabItem` where name = pr_item.item_code 
 			and is_stock_item='Yes')
 		and exists(select name from `tabPurchase Receipt` 
 			where name = pr_item.parent and company = %s)""", company)
 		
-	total_billed_amount = webnotes.conn.sql("""select sum(valuation_rate*qty) 
+	total_billed_amount = webnotes.conn.sql("""select sum(valuation_rate*qty*conversion_factor) 
 		from `tabPurchase Invoice Item` pi_item where docstatus=1 
 		and exists(select name from `tabItem` where name = pi_item.item_code 
 			and is_stock_item='Yes')
 		and exists(select name from `tabPurchase Invoice` 
 			where name = pi_item.parent and company = %s)""", company)
-		
 	return flt(total_received_amount[0][0]) - flt(total_billed_amount[0][0])
diff --git a/config.json b/config.json
new file mode 100644
index 0000000..ff6f80f
--- /dev/null
+++ b/config.json
@@ -0,0 +1,146 @@
+{
+	"modules": {
+		"Selling": {
+			"link": "selling-home",
+			"color": "#3f4901",
+			"icon": "icon-tag",
+			"type": "module"
+		},
+		"Accounts": {
+			"link": "accounts-home",
+			"color": "#025770",
+			"icon": "icon-money",
+			"type": "module"
+		},
+		"Stock": {
+			"type": "module",
+			"link": "stock-home",
+			"color": "#a66a02",
+			"icon": "icon-truck"
+		},
+		"Buying": {
+			"type": "module",
+			"link": "buying-home",
+			"color": "#8F0222",
+			"icon": "icon-shopping-cart"
+		},
+		"Support": {
+			"type": "module",
+			"link": "support-home",
+			"color": "#410169",
+			"icon": "icon-phone"
+		},
+		"Projects": {
+			"type": "module",
+			"link": "projects-home",
+			"color": "#473b7f",
+			"icon": "icon-tasks"
+		},
+		"Manufacturing": {
+			"type": "module",
+			"link": "manufacturing-home",
+			"color": "#590116",
+			"icon": "icon-magic"
+		},
+		"Website": {
+			"type": "module",
+			"link": "website-home",
+			"color": "#968c00",
+			"icon": "icon-globe"
+		},
+		"HR": {
+			"type": "module",
+			"link": "hr-home",
+			"color": "#018d6c",
+			"label": "Human Resources",
+			"icon": "icon-group"
+		},
+		"Setup": {
+			"type": "setup",
+			"link": "Setup",
+			"color": "#484848",
+			"icon": "icon-wrench"
+		},
+		"Activity": {
+			"type": "page",
+			"link": "activity",
+			"color": "#633501",
+			"icon": "icon-play",
+			"label": "Activity"
+		},
+		"Knowledge Base": {
+			"type": "page",
+			"link": "questions",
+			"color": "#01372b",
+			"label": "Knowledge Base",
+			"icon": "icon-question-sign"
+		}
+	},
+	"web": {
+		"pages": {
+			"about": {
+				"template": "app/website/templates/pages/about",
+				"args_method": "website.doctype.about_us_settings.about_us_settings.get_args"
+			},
+			"account": {
+				"template": "app/website/templates/pages/account"
+			},
+			"attributions": {
+				"template": "app/website/templates/pages/attributions"
+			},
+			"blog": {
+				"template": "app/website/templates/pages/blog",
+				"args_method": "website.helpers.blog.get_blog_template_args"
+			},
+			"contact": {
+				"template": "app/website/templates/pages/contact",
+				"args_doctype": "Contact Us Settings"
+			},
+			"index": {
+				"template": "app/website/templates/pages/index"
+			},
+			"order": {
+				"no_cache": true,
+				"template": "app/website/templates/pages/order",
+				"args_method": "selling.doctype.sales_order.sales_order.get_website_args"
+			},
+			"orders": {
+				"template": "app/website/templates/pages/orders",
+				"args_method": "selling.doctype.sales_order.sales_order.get_currency_and_number_format"
+			},
+			"product_search": {
+				"template": "app/website/templates/pages/product_search"
+			},
+			"ticket": {
+				"no_cache": true,
+				"template": "app/website/templates/pages/ticket",
+				"get_website_args": "support.doctype.support_ticket.support_ticket.get_website_args"
+			},
+			"tickets": {
+				"template": "app/website/templates/pages/tickets"
+			},
+			"writers": {
+				"template": "app/website/templates/pages/writers",
+				"args_method": "website.helpers.blog.get_writers_args"
+			}
+		},
+		"generators": {
+			"Web Page": {
+				"template": "app/website/templates/html/web_page.html",
+				"condition_field": "published"
+			},
+			"Blog Post": {
+				"template": "app/website/templates/html/blog_page.html",
+				"condition_field": "published"
+			},
+			"Item": {
+				"template": "app/website/templates/html/product_page.html",
+				"condition_field": "show_in_website"
+			},
+			"Item Group":{
+				"template": "app/website/templates/html/product_group.html",
+				"condition_field": "show_in_website"
+			}
+		}
+	}
+}
\ No newline at end of file
diff --git a/controllers/selling_controller.py b/controllers/selling_controller.py
index f3fb47f..b22042d 100644
--- a/controllers/selling_controller.py
+++ b/controllers/selling_controller.py
@@ -41,9 +41,10 @@
 			self.doc.in_words_export = money_in_words(disable_rounded_total and 
 				self.doc.grand_total_export or self.doc.rounded_total_export, self.doc.currency)
 
-	def set_buying_amount(self):
+	def set_buying_amount(self, stock_ledger_entries = None):
 		from stock.utils import get_buying_amount
-		stock_ledger_entries = self.get_stock_ledger_entries()
+		if not stock_ledger_entries:
+			stock_ledger_entries = self.get_stock_ledger_entries()
 
 		item_sales_bom = {}
 		for d in self.doclist.get({"parentfield": "packing_details"}):
@@ -65,4 +66,8 @@
 	def check_expense_account(self, item):
 		if item.buying_amount and not item.expense_account:
 			msgprint(_("""Expense account is mandatory for item: """) + item.item_code, 
+				raise_exception=1)
+				
+		if item.buying_amount and not item.cost_center:
+			msgprint(_("""Cost Center is mandatory for item: """) + item.item_code, 
 				raise_exception=1)
\ No newline at end of file
diff --git a/controllers/stock_controller.py b/controllers/stock_controller.py
index 89f62aa..7cfb68c 100644
--- a/controllers/stock_controller.py
+++ b/controllers/stock_controller.py
@@ -16,7 +16,8 @@
 
 from __future__ import unicode_literals
 import webnotes
-from webnotes import msgprint, _
+from webnotes.utils import cint
+import webnotes.defaults
 from controllers.accounts_controller import AccountsController
 
 class StockController(AccountsController):
@@ -72,4 +73,10 @@
 			item_list.append(item.item_code)
 			warehouse_list.append(item.warehouse)
 			
-		return list(set(item_list)), list(set(warehouse_list))
\ No newline at end of file
+		return list(set(item_list)), list(set(warehouse_list))
+		
+	def make_cancel_gl_entries(self):
+		if webnotes.conn.sql("""select name from `tabGL Entry` where voucher_type=%s 
+			and voucher_no=%s and ifnull(is_cancelled, 'No')='No'""",
+			(self.doc.doctype, self.doc.name)):
+				self.make_gl_entries()
\ No newline at end of file
diff --git a/home/page/activity/activity.txt b/home/page/activity/activity.txt
index ec39d01..57f4b7a 100644
--- a/home/page/activity/activity.txt
+++ b/home/page/activity/activity.txt
@@ -1,21 +1,32 @@
 [
  {
-  "owner": "Administrator", 
+  "creation": "2012-06-14 18:44:56", 
   "docstatus": 0, 
-  "creation": "2012-02-29 11:59:13", 
+  "modified": "2013-04-03 14:59:38", 
   "modified_by": "Administrator", 
-  "modified": "2012-02-29 12:11:46"
+  "owner": "Administrator"
  }, 
  {
-  "name": "__common__", 
-  "title": "Activity", 
-  "module": "Home", 
   "doctype": "Page", 
+  "module": "Home", 
+  "name": "__common__", 
   "page_name": "activity", 
-  "standard": "Yes"
+  "standard": "Yes", 
+  "title": "Activity"
  }, 
  {
-  "name": "activity", 
-  "doctype": "Page"
+  "doctype": "Page Role", 
+  "name": "__common__", 
+  "parent": "activity", 
+  "parentfield": "roles", 
+  "parenttype": "Page", 
+  "role": "All"
+ }, 
+ {
+  "doctype": "Page", 
+  "name": "activity"
+ }, 
+ {
+  "doctype": "Page Role"
  }
 ]
\ No newline at end of file
diff --git a/home/page/desktop/__init__.py b/home/page/desktop/__init__.py
deleted file mode 100644
index baffc48..0000000
--- a/home/page/desktop/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-from __future__ import unicode_literals
diff --git a/home/page/desktop/desktop.css b/home/page/desktop/desktop.css
deleted file mode 100644
index ed3a1b3..0000000
--- a/home/page/desktop/desktop.css
+++ /dev/null
@@ -1,86 +0,0 @@
-/* Sprite CSS */
-
-.case-border {
-	border-radius: 10px;
-	-moz-border-radius: 10px;
-	-webkit-border-radius: 10px;
-	width: 32px;
-	height: 32px;
-	padding: 12px;
-	border: 2px solid white;
-	box-shadow: 0 0 4px 1px black;
-	-moz-box-shadow: 0 0 4px 1px black;
-	-webkit-box-shadow: 0 0 4px 1px black;
-	-o-box-shadow: 0 0 4px 1px black;
-	margin: auto;
-}
-
-.case-wrapper {
-	margin: 24px;
-	float: left;
-	width: 100px;
-	height: 100px;
-}
-
-.case-wrapper i {
-	font-size: 32px;
-	color: #f8f8f8;
-}
-
-.case-label {
-	color: white;
-	padding-top: 10px;
-	text-align: center;
-	text-shadow: 1px 1px 2px #000, 1px 1px 2px #000, 1px 1px 2px #000, 0px 0px 2px #000;
-}
-
-/* Hover and click effects */
-.case-border:hover, .circle:hover, .hover-effect {
-	box-shadow: 0 0 2px 0px black, 0 0 4px 1px white !important;
-	-moz-box-shadow: 0 0 2px 0px black, 0 0 4px 1px white !important;
-	-webkit-box-shadow: 0 0 2px 0px black, 0 0 4px 1px white !important;
-	-o-box-shadow: 0 0 2px 0px black, 0 0 10px 1px white !important;
-}
-
-.case-border:active, .case-border:focus, .case-border-click {
-	transform: scale(0.98, 0.98);
-	-ms-transform: scale(0.98, 0.98); /* IE 9 */
-	-webkit-transform: scale(0.98, 0.98); /* Safari and Chrome */
-	-o-transform: scale(0.98, 0.98); /* Opera */
-	-moz-transform: scale(0.98, 0.98); /* Firefox */
-}
-
-.circle:active, .circle:focus, .circle-click {
-	transform: scale(1, 1);
-	-ms-transform: scale(1, 1); /* IE 9 */
-	-webkit-transform: scale(1, 1); /* Safari and Chrome */
-	-o-transform: scale(1, 1); /* Opera */
-	-moz-transform: scale(1, 1); /* Firefox */
-}
-
-.circle {
-	border-radius: 30px;
-	-moz-border-radius: 30px;
-	-webkit-border-radius: 30px;
-	height: 15px;
-	line-height: 12px;
-	min-width: 15px;
-	background: #B00D07;
-	padding: 3px;
-	float: right;
-	margin-top: -12px;
-	margin-right: 10px;
-	border: 2px solid white;
-	box-shadow: 0 0 4px 1px black;
-	-moz-box-shadow: 0 0 4px 1px black;
-	-webkit-box-shadow: 0 0 4px 1px black;
-	-o-box-shadow: 0 0 4px 1px black;
-}
-
-.circle-text {
-	color: white;
-	text-align: center;
-	display: inline-block;
-	margin-top: 1px;
-}
-
diff --git a/home/page/desktop/desktop.html b/home/page/desktop/desktop.html
deleted file mode 100644
index 43ee423..0000000
--- a/home/page/desktop/desktop.html
+++ /dev/null
@@ -1,6 +0,0 @@
-<div style="min-height: 500px; background: None; text-align: center;
-	margin: 0px auto;">	
-	<div id="icon-grid">
-	</div>
-</div>
-<div style="clear: both"></div>
diff --git a/home/page/desktop/desktop.js b/home/page/desktop/desktop.js
deleted file mode 100644
index 87181d8..0000000
--- a/home/page/desktop/desktop.js
+++ /dev/null
@@ -1,101 +0,0 @@
-wn.provide('erpnext.desktop');
-
-erpnext.desktop.refresh = function() {
-	erpnext.desktop.render();
-
-	$("#icon-grid").sortable({
-		update: function() {
-			new_order = [];
-			$("#icon-grid .case-wrapper").each(function(i, e) {
-				new_order.push($(this).attr("data-name"));
-			});
-			wn.defaults.set_default("_desktop_items", new_order);
-		}
-	});
-}
-
-erpnext.desktop.render = function() {
-	document.title = "Desktop";
-	var add_icon = function(m) {
-		var module = wn.modules[m];
-		if(!module.label) 
-			module.label = m;
-		module.name = m;
-		module.label = wn._(module.label);
-		module.gradient_css = wn.get_gradient_css(module.color, 45);
-		module._link = module.link.toLowerCase().replace("/", "-");
-		
-		$module_icon = $(repl('\
-			<div id="module-icon-%(_link)s" class="case-wrapper" \
-				data-name="%(name)s" data-link="%(link)s">\
-				<div class="case-border" style="%(gradient_css)s">\
-					<i class="%(icon)s"></i>\
-				</div>\
-				<div class="case-label">%(label)s</div>\
-			</div>', module)).click(function() {
-				wn.set_route($(this).attr("data-link"));
-			}).css({
-				cursor:"pointer"
-			}).appendTo("#icon-grid");
-	}
-	
-	// modules
-	var modules_list = wn.user.get_desktop_items();
-	$.each(modules_list, function(i, m) {
-		if(!in_list(['Setup', 'Core'], m) && wn.boot.profile.allow_modules.indexOf(m)!=-1)
-			add_icon(m);
-	})
-
-	// setup
-	if(user_roles.indexOf('System Manager')!=-1)
-		add_icon('Setup')
-
-	// notifications
-	erpnext.desktop.show_pending_notifications();
-
-}
-
-erpnext.desktop.show_pending_notifications = function() {
-	var add_circle = function(str_module, id, title) {
-		var module = $('#'+str_module);
-		module.prepend(
-			repl('<div id="%(id)s" class="circle" title="%(title)s" style="display: None">\
-					<span class="circle-text"></span>\
-				 </div>', {id: id, title: wn._(title)}));
-		
-		var case_border = module.find('.case-border');
-		var circle = module.find('.circle');
-
-		var add_hover_and_click = function(primary, secondary, hover_class, click_class) {
-			primary
-			.hover(
-				function() { secondary.addClass(hover_class); },
-				function() { secondary.removeClass(hover_class); })
-			.mousedown(function() { secondary.addClass(click_class); })
-			.mouseup(function() { secondary.removeClass(click_class); })
-			.focusin(function() { $(this).mousedown(); })
-			.focusout(function() { $(this).mouseup(); })
-		}
-		
-		add_hover_and_click(case_border, circle, 'hover-effect', 'circle-click');
-		add_hover_and_click(circle, case_border, 'hover-effect', 'case-border-click');
-
-	}
-
-	add_circle('module-icon-messages', 'unread_messages', 'Unread Messages');
-	add_circle('module-icon-support-home', 'open_support_tickets', 'Open Support Tickets');
-	add_circle('module-icon-todo', 'things_todo', 'Things To Do');
-	add_circle('module-icon-calendar-event', 'todays_events', 'Todays Events');
-	add_circle('module-icon-projects-home', 'open_tasks', 'Open Tasks');
-	add_circle('module-icon-questions', 'unanswered_questions', 'Unanswered Questions');
-	add_circle('module-icon-selling-home', 'open_leads', 'Open Leads');
-
-	erpnext.update_messages();
-
-}
-
-pscript.onload_desktop = function() {
-	// load desktop
-	erpnext.desktop.refresh();
-}
-
diff --git a/home/page/desktop/desktop.txt b/home/page/desktop/desktop.txt
deleted file mode 100644
index 4a5fb95..0000000
--- a/home/page/desktop/desktop.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-[
- {
-  "creation": "2012-06-14 18:44:56", 
-  "docstatus": 0, 
-  "modified": "2013-02-12 18:11:00", 
-  "modified_by": "Administrator", 
-  "owner": "Administrator"
- }, 
- {
-  "doctype": "Page", 
-  "module": "Home", 
-  "name": "__common__", 
-  "page_name": "desktop", 
-  "standard": "Yes", 
-  "title": "Desktop"
- }, 
- {
-  "doctype": "Page Role", 
-  "name": "__common__", 
-  "parent": "desktop", 
-  "parentfield": "roles", 
-  "parenttype": "Page", 
-  "role": "All"
- }, 
- {
-  "doctype": "Page", 
-  "name": "desktop"
- }, 
- {
-  "doctype": "Page Role"
- }
-]
\ 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 f2a58c8..d34abd8 100755
--- a/hr/doctype/leave_application/leave_application.py
+++ b/hr/doctype/leave_application/leave_application.py
@@ -199,7 +199,7 @@
 		
 	def notify(self, args):
 		args = webnotes._dict(args)
-		from utilities.page.messages.messages import post
+		from core.page.messages.messages import post
 		post({"txt": args.message, "contact": args.message_to, "subject": args.subject,
 			"notify": cint(self.doc.follow_via_email)})
 
diff --git a/hr/doctype/leave_control_panel/leave_control_panel.py b/hr/doctype/leave_control_panel/leave_control_panel.py
index d26efd4..e771c5c 100644
--- a/hr/doctype/leave_control_panel/leave_control_panel.py
+++ b/hr/doctype/leave_control_panel/leave_control_panel.py
@@ -17,10 +17,8 @@
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import cint, cstr, flt, now, nowdate
-from webnotes.model import db_exists
+from webnotes.utils import cint, cstr, flt, nowdate
 from webnotes.model.doc import Document
-from webnotes.model.bean import copy_doclist
 from webnotes.model.code import get_obj
 from webnotes import msgprint
 
@@ -49,7 +47,7 @@
     emp_query = "select name from `tabEmployee` "
     if flag == 1:
       emp_query += condition 
-    e = sql(emp_query, debug=1)
+    e = sql(emp_query)
     return e
 
   # ----------------
diff --git a/manufacturing/doctype/bom/bom.py b/manufacturing/doctype/bom/bom.py
index ef07e5e..75bf305 100644
--- a/manufacturing/doctype/bom/bom.py
+++ b/manufacturing/doctype/bom/bom.py
@@ -17,7 +17,7 @@
 from __future__ import unicode_literals
 import webnotes
 from webnotes.utils import cint, cstr, flt, now, nowdate
-from webnotes.model.doc import Document, addchild
+from webnotes.model.doc import addchild
 from webnotes.model.bean import getlist
 from webnotes.model.code import get_obj
 from webnotes import msgprint, _
@@ -76,7 +76,7 @@
 
 	def get_item_details(self, item_code):
 		res = sql("""select description, stock_uom as uom
-			from `tabItem` where item_code = %s""", item_code, as_dict = 1, debug=1)
+			from `tabItem` where item_code = %s""", item_code, as_dict = 1)
 		return res and res[0] or {}
 
 	def get_workstation_details(self,workstation):
diff --git a/patches/april_2013/p04_reverse_modules_list.py b/patches/april_2013/p04_reverse_modules_list.py
new file mode 100644
index 0000000..9215fea
--- /dev/null
+++ b/patches/april_2013/p04_reverse_modules_list.py
@@ -0,0 +1,11 @@
+import webnotes, json
+import webnotes.utils
+
+def execute():
+	modules = webnotes.get_config().modules
+	
+	ml = json.loads(webnotes.conn.get_global("modules_list") or "[]")
+	
+	webnotes.conn.set_global("hidden_modules", 
+		json.dumps(list(set(modules.keys()).difference(set(ml)))))
+	
\ No newline at end of file
diff --git a/patches/march_2013/p03_update_buying_amount.py b/patches/march_2013/p03_update_buying_amount.py
index ae0c5ea..0d96feb 100644
--- a/patches/march_2013/p03_update_buying_amount.py
+++ b/patches/march_2013/p03_update_buying_amount.py
@@ -1,10 +1,33 @@
 import webnotes
+from webnotes.utils import now_datetime
 
 def execute():
-	dn_list = webnotes.conn.sql("""select name from `tabDelivery Note` where docstatus < 2""")
-	for dn in dn_list:
-		webnotes.bean("Delivery Note", dn[0]).run_method("set_buying_amount")
+	webnotes.reload_doc("stock", "doctype", "delivery_note_item")
+	webnotes.reload_doc("accounts", "doctype", "sales_invoice_item")
+
+	webnotes.conn.auto_commit_on_many_writes = True
+	for company in webnotes.conn.sql("select name from `tabCompany`"):
+		print company[0]
+		stock_ledger_entries = webnotes.conn.sql("""select item_code, voucher_type, voucher_no,
+			voucher_detail_no, posting_date, posting_time, stock_value, 
+			warehouse, actual_qty as qty from `tabStock Ledger Entry` 
+			where ifnull(`is_cancelled`, "No") = "No" and company = %s
+			order by item_code desc, warehouse desc, 
+			posting_date desc, posting_time desc, name desc""", company[0], as_dict=True)
 		
-	si_list = webnotes.conn.sql("""select name from `tabSales Invoice` where docstatus < 2""")
-	for si in si_list:
-		webnotes.bean("Sales Invoice", si[0]).run_method("set_buying_amount")
\ No newline at end of file
+		dn_list = webnotes.conn.sql("""select name from `tabDelivery Note` 
+			where docstatus < 2 and company = %s""", company[0])
+		print "Total Delivery Note: ", len(dn_list)
+		
+		for dn in dn_list:
+			dn = webnotes.get_obj("Delivery Note", dn[0], with_children = 1)
+			dn.set_buying_amount(stock_ledger_entries)
+		
+		si_list = webnotes.conn.sql("""select name from `tabSales Invoice` 
+			where docstatus < 2	and company = %s""", company[0])
+		print "Total Sales Invoice: ", len(si_list)
+		for si in si_list:
+			si = webnotes.get_obj("Sales Invoice", si[0], with_children = 1)
+			si.set_buying_amount(stock_ledger_entries)
+		
+	webnotes.conn.auto_commit_on_many_writes = False
\ No newline at end of file
diff --git a/patches/march_2013/p07_update_valuation_rate.py b/patches/march_2013/p07_update_valuation_rate.py
index 7cc3e11..885fad6 100644
--- a/patches/march_2013/p07_update_valuation_rate.py
+++ b/patches/march_2013/p07_update_valuation_rate.py
@@ -1,6 +1,8 @@
 import webnotes
 
 def execute():
+	webnotes.reload_doc("accounts", "doctype", "purchase_invoice_item")
+	
 	for purchase_invoice in webnotes.conn.sql_list("""select distinct parent 
 		from `tabPurchase Invoice Item` where docstatus = 1 and ifnull(valuation_rate, 0)=0"""):
 		pi = webnotes.get_obj("Purchase Invoice", purchase_invoice)
@@ -10,4 +12,3 @@
 		for item in pi.doclist.get({"parentfield": "entries"}):
 			webnotes.conn.sql("""update `tabPurchase Invoice Item` set valuation_rate = %s 
 				where name = %s""", (item.valuation_rate, item.name))
-	
\ No newline at end of file
diff --git a/patches/march_2013/p08_create_aii_accounts.py b/patches/march_2013/p08_create_aii_accounts.py
index ff53d8b..ec186b4 100644
--- a/patches/march_2013/p08_create_aii_accounts.py
+++ b/patches/march_2013/p08_create_aii_accounts.py
@@ -1,7 +1,15 @@
 import webnotes
 def execute():
+	webnotes.reload_doc("setup", "doctype", "company")
+	
 	add_group_accounts()
 	add_ledger_accounts()
+	add_aii_cost_center()
+	set_default_accounts()
+	
+def set_default_accounts():
+	for company in webnotes.conn.sql_list("select name from `tabCompany`"):
+		webnotes.get_obj("Company", company).set_default_accounts()
 	
 def _check(parent_account, company):
 	def _get_root(is_pl_account, debit_or_credit):
@@ -34,7 +42,6 @@
 def add_ledger_accounts():
 	accounts_to_add = [
 		["Stock In Hand", "Stock Assets", "Ledger", ""],
-		["Stock Debit But Not Billed", "Stock Assets", "Ledger", ""],
 		["Cost of Goods Sold", "Stock Expenses", "Ledger", "Expense Account"],
 		["Stock Adjustment", "Stock Expenses", "Ledger", "Expense Account"],
 		["Expenses Included In Valuation", "Stock Expenses", "Ledger", "Expense Account"],
@@ -45,6 +52,14 @@
 	
 def add_accounts(accounts_to_add, check_fn=None):	
 	for company, abbr in webnotes.conn.sql("""select name, abbr from `tabCompany`"""):
+		count = webnotes.conn.sql("""select count(name) from `tabAccount`
+			where company=%s and ifnull(parent_account, '')=''""", company)[0][0]
+		
+		if count > 4:
+			print "Company", company, \
+				"has more than 4 root accounts. cannot apply patch to this company."
+			continue
+		
 		for account_name, parent_account_name, group_or_ledger, account_type in accounts_to_add:
 			if not webnotes.conn.exists("Account", "%s - %s" % (account_name, abbr)):
 				parent_account = "%s - %s" % (parent_account_name, abbr)
@@ -58,4 +73,25 @@
 					"account_type": account_type,
 					"company": company
 				})
-				account.insert()
\ No newline at end of file
+				account.insert()
+				
+def add_aii_cost_center():
+	for company, abbr in webnotes.conn.sql("""select name, abbr from `tabCompany`"""):
+		if not webnotes.conn.exists("Cost Center", "Auto Inventory Accounting - %s" % abbr):
+			parent_cost_center = webnotes.conn.get_value("Cost Center", 
+				{"parent_cost_center['']": '', "company_name": company})
+				
+			if not parent_cost_center:
+				print "Company", company, "does not have a root cost center"
+				continue
+			
+			cc = webnotes.bean({
+				"doctype": "Cost Center",
+				"cost_center_name": "Auto Inventory Accounting",
+				"parent_cost_center": parent_cost_center,
+				"group_or_ledger": "Ledger",
+				"company_name": company
+			})
+			cc.insert()
+				
+				
\ No newline at end of file
diff --git a/patches/patch_list.py b/patches/patch_list.py
index 0b7092c..1ee7c02 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -228,12 +228,15 @@
 	"patches.march_2013.p10_update_against_expense_account",
 	"patches.march_2013.p11_update_attach_files",
 	"patches.march_2013.p12_set_item_tax_rate_in_json",
+	"patches.march_2013.p07_update_valuation_rate",
+	"patches.march_2013.p08_create_aii_accounts",
+	"patches.march_2013.p03_update_buying_amount",
 	"patches.april_2013.p01_update_serial_no_valuation_rate",
 	"patches.april_2013.p02_add_country_and_currency",
 	"patches.april_2013.p03_fixes_for_lead_in_quotation",
 	'execute:webnotes.reload_doc("selling", "Print Format", "Quotation Classic") # 2013-04-02',
 	'execute:webnotes.reload_doc("selling", "Print Format", "Quotation Modern") # 2013-04-02',
 	'execute:webnotes.reload_doc("selling", "Print Format", "Quotation Spartan") # 2013-04-02',
+	"patches.april_2013.p04_reverse_modules_list",
 	"execute:webnotes.delete_doc('Search Criteria', 'time_log_summary')"
-	
 ]
\ No newline at end of file
diff --git a/projects/page/projects_home/projects_home.js b/projects/page/projects_home/projects_home.js
index 0e7ccff..cfde6b3 100644
--- a/projects/page/projects_home/projects_home.js
+++ b/projects/page/projects_home/projects_home.js
@@ -26,12 +26,6 @@
 				description: wn._("Batch Time Logs for billing."),
 				doctype:"Time Log Batch"
 			},
-			{
-				label: wn._("Timesheet"),
-				description: wn._("[DEPRECATED] Timesheet for tasks."),
-				doctype:"Timesheet"
-			},
-
 		]
 	},
 	{
diff --git a/public/build.json b/public/build.json
index 05d603f..24abde2 100644
--- a/public/build.json
+++ b/public/build.json
@@ -13,7 +13,6 @@
 	"public/js/all-app.min.js": [
 		"app/public/js/startup.js",
 		"app/public/js/conf.js",
-		"app/public/js/modules.js",
 		"app/public/js/toolbar.js",
 		"app/public/js/feature_setup.js",
 		"app/public/js/utils.js",
diff --git a/public/js/modules.js b/public/js/modules.js
deleted file mode 100644
index dc9548f..0000000
--- a/public/js/modules.js
+++ /dev/null
@@ -1,105 +0,0 @@
-// 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/>.
-
-wn.home_page = "desktop";
-wn.provide("wn.module_page");
-
-$.extend(wn.modules, {
-	"Selling": {
-		link: "selling-home",
-		color: "#3f4901",
-		icon: "icon-tag"
-	},
-	"Accounts": {
-		link: "accounts-home",
-		color: "#025770",
-		icon: "icon-money"
-	},
-	"Stock": {
-		link: "stock-home",
-		color: "#a66a02",
-		icon: "icon-truck"
-	},
-	"Buying": {
-		link: "buying-home",
-		color: "#8F0222",
-		icon: "icon-shopping-cart"
-	},
-	"Support": {
-		link: "support-home",
-		color: "#410169",
-		icon: "icon-phone"
-	},
-	"Projects": {
-		link: "projects-home",
-		color: "#473b7f",
-		icon: "icon-tasks"
-	},
-	"Manufacturing": {
-		link: "manufacturing-home",
-		color: "#590116",
-		icon: "icon-magic"
-	},
-	"Website": {
-		link: "website-home",
-		color: "#968c00",
-		icon: "icon-globe"
-	},
-	"HR": {
-		link: "hr-home",
-		color: "#018d6c",
-		label: wn._("Human Resources"),
-		icon: "icon-group"
-	},
-	"Setup": {
-		link: "Setup",
-		color: "#484848",
-		icon: "icon-wrench"
-	},
-	"Activity": {
-		link: "activity",
-		color: "#633501",
-		icon: "icon-play",
-		label: wn._("Activity"),
-	},
-	"To Do": {
-		link: "todo",
-		color: "#febf04",
-		label: wn._("To Do"),
-		icon: "icon-check"
-	},
-	"Calendar": {
-		link: "Calendar/Event",
-		color: "#026584",
-		label: wn._("Calendar"),
-		icon: "icon-calendar"
-	},
-	"Messages": {
-		link: "messages",
-		color: "#8d016e",
-		label: wn._("Messages"),
-		icon: "icon-comments"
-	},
-	"Knowledge Base": {
-		link: "questions",
-		color: "#01372b",
-		label: wn._("Knowledge Base"),
-		icon: "icon-question-sign"
-	},
-	
-});
-
-wn.provide('erpnext.module_page');
\ No newline at end of file
diff --git a/public/js/startup.js b/public/js/startup.js
index 1ae3feb..0a6580b 100644
--- a/public/js/startup.js
+++ b/public/js/startup.js
@@ -31,11 +31,7 @@
 
 	if(user != 'Guest'){
 		erpnext.setup_mousetrap();
-		
-		// always allow apps
-		wn.boot.profile.allow_modules = wn.boot.profile.allow_modules.concat(
-			['To Do', 'Knowledge Base', 'Calendar', 'Activity', 'Messages'])
-		
+				
 		// setup toolbar
 		erpnext.toolbar.setup();
 		
diff --git a/public/js/toolbar.js b/public/js/toolbar.js
index bcd2ddd..03d7d0a 100644
--- a/public/js/toolbar.js
+++ b/public/js/toolbar.js
@@ -74,12 +74,11 @@
 	}
 
 	// add to dropdown
-	for(var i in modules_list) {
-		var m = modules_list[i]
-		if(m!='Setup' && wn.boot.profile.allow_modules.indexOf(m)!=-1 && wn.modules[m]) {
+	$.each(modules_list,function(i, m) {
+		if(m!='Setup') {
 			$('.navbar .modules').append(_get_list_item(m));			
 		}
-	}
+	})
 	
 	// setup for system manager
 	if(user_roles.indexOf("System Manager")!=-1) {
diff --git a/selling/doctype/sales_common/sales_common.py b/selling/doctype/sales_common/sales_common.py
index 729013f..b9f9af6 100644
--- a/selling/doctype/sales_common/sales_common.py
+++ b/selling/doctype/sales_common/sales_common.py
@@ -212,7 +212,8 @@
 	
 	# ***************** Get Ref rate as entered in Item Master ********************
 	def get_ref_rate(self, item_code, price_list_name, price_list_currency, plc_conv_rate):
-		ref_rate = webnotes.conn.sql("select ref_rate from `tabItem Price` where parent = %s and price_list_name = %s and ref_currency = %s", (item_code, price_list_name, price_list_currency))
+		ref_rate = webnotes.conn.sql("select ref_rate from `tabItem Price` where parent = %s and price_list_name = %s and ref_currency = %s and selling=1", 
+		(item_code, price_list_name, price_list_currency))
 		base_ref_rate = ref_rate and flt(ref_rate[0][0]) * flt(plc_conv_rate) or 0
 		return base_ref_rate
 
@@ -361,7 +362,7 @@
 		sales_team_list = obj.doclist.get({"parentfield": "sales_team"})
 		total_allocation = sum([flt(d.allocated_percentage) for d in sales_team_list])
 		if sales_team_list and total_allocation != 100.0:
-			msgprint("Total Allocated %% of Sales Persons should be 100%", raise_exception=True)
+			msgprint("Total Allocated % of Sales Persons should be 100%", raise_exception=True)
 			
 	# Check Conversion Rate (i.e. it will not allow conversion rate to be 1 for Currency other than default currency set in Global Defaults)
 	# ===========================================================================
diff --git a/setup/doctype/company/company.js b/setup/doctype/company/company.js
index 5e78b79..463b922 100644
--- a/setup/doctype/company/company.js
+++ b/setup/doctype/company/company.js
@@ -89,9 +89,6 @@
 cur_frm.fields_dict["expenses_included_in_valuation"].get_query = 
 	cur_frm.fields_dict["stock_adjustment_account"].get_query;
 	
-cur_frm.fields_dict["stock_delivered_but_not_billed"].get_query = 
-	cur_frm.fields_dict["stock_in_hand_account"].get_query;
-
 cur_frm.fields_dict["stock_received_but_not_billed"].get_query = function(doc) {
 	return {
 		"query": "accounts.utils.get_account_list", 
@@ -106,6 +103,6 @@
 cur_frm.fields_dict["stock_adjustment_cost_center"].get_query = function(doc) {
 	return {
 		"query": "accounts.utils.get_cost_center_list", 
-		"filters": {"company": doc.name}
+		"filters": {"company_name": doc.name}
 	}
 }
\ No newline at end of file
diff --git a/setup/doctype/company/company.py b/setup/doctype/company/company.py
index 47b250d..bee1333 100644
--- a/setup/doctype/company/company.py
+++ b/setup/doctype/company/company.py
@@ -49,8 +49,6 @@
 						['Earnest Money','Securities and Deposits','Ledger','No','','Debit',self.doc.name,''],
 					['Stock Assets','Current Assets','Group','No','','Debit',self.doc.name,''],
 						['Stock In Hand','Stock Assets','Ledger','No','','Debit',self.doc.name,''],
-						['Stock Delivered But Not Billed', 'Stock Assets', 'Ledger', 
-							'No', '', 'Debit', self.doc.name, ''],
 					['Tax Assets','Current Assets','Group','No','','Debit',self.doc.name,''],
 				['Fixed Assets','Application of Funds (Assets)','Group','No','','Debit',self.doc.name,''],
 					['Capital Equipments','Fixed Assets','Ledger','No','Fixed Asset Account','Debit',self.doc.name,''],
diff --git a/setup/doctype/company/company.txt b/setup/doctype/company/company.txt
index feb3bca..a49a7e0 100644
--- a/setup/doctype/company/company.txt
+++ b/setup/doctype/company/company.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-03-21 17:41:00", 
+  "creation": "2013-03-26 11:03:08", 
   "docstatus": 0, 
-  "modified": "2013-03-25 15:35:34", 
+  "modified": "2013-03-28 16:04:27", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -25,14 +25,19 @@
  }, 
  {
   "amend": 0, 
+  "cancel": 1, 
+  "create": 1, 
   "doctype": "DocPerm", 
   "name": "__common__", 
   "parent": "Company", 
   "parentfield": "permissions", 
   "parenttype": "DocType", 
+  "permlevel": 0, 
   "read": 1, 
   "report": 1, 
-  "submit": 0
+  "role": "System Manager", 
+  "submit": 0, 
+  "write": 1
  }, 
  {
   "doctype": "DocType", 
@@ -43,7 +48,8 @@
   "fieldname": "details", 
   "fieldtype": "Section Break", 
   "label": "Company Details", 
-  "oldfieldtype": "Section Break"
+  "oldfieldtype": "Section Break", 
+  "read_only": 0
  }, 
  {
   "description": "Please Enter Abbreviation or Short Name properly as it will be added as Suffix to all Account Heads.", 
@@ -54,12 +60,14 @@
   "no_copy": 0, 
   "oldfieldname": "abbr", 
   "oldfieldtype": "Data", 
+  "read_only": 0, 
   "reqd": 1
  }, 
  {
   "doctype": "DocField", 
   "fieldname": "cb0", 
-  "fieldtype": "Column Break"
+  "fieldtype": "Column Break", 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -69,6 +77,7 @@
   "no_copy": 0, 
   "oldfieldname": "company_name", 
   "oldfieldtype": "Data", 
+  "read_only": 0, 
   "reqd": 1
  }, 
  {
@@ -76,7 +85,8 @@
   "fieldname": "default_settings", 
   "fieldtype": "Section Break", 
   "label": "Default Settings", 
-  "oldfieldtype": "Section Break"
+  "oldfieldtype": "Section Break", 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -84,6 +94,7 @@
   "fieldtype": "Link", 
   "label": "Default Currency", 
   "options": "Currency", 
+  "read_only": 0, 
   "reqd": 1
  }, 
  {
@@ -95,14 +106,16 @@
   "no_copy": 1, 
   "oldfieldname": "default_bank_account", 
   "oldfieldtype": "Link", 
-  "options": "Account"
+  "options": "Account", 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
   "fieldname": "default_cash_account", 
   "fieldtype": "Link", 
   "label": "Default Cash Account", 
-  "options": "Account"
+  "options": "Account", 
+  "read_only": 0
  }, 
  {
   "depends_on": "eval:!doc.__islocal", 
@@ -113,7 +126,8 @@
   "no_copy": 1, 
   "oldfieldname": "receivables_group", 
   "oldfieldtype": "Link", 
-  "options": "Account"
+  "options": "Account", 
+  "read_only": 0
  }, 
  {
   "depends_on": "eval:!doc.__islocal", 
@@ -124,13 +138,15 @@
   "no_copy": 1, 
   "oldfieldname": "payables_group", 
   "oldfieldtype": "Link", 
-  "options": "Account"
+  "options": "Account", 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
   "fieldname": "column_break0", 
   "fieldtype": "Column Break", 
   "oldfieldtype": "Column Break", 
+  "read_only": 0, 
   "width": "50%"
  }, 
  {
@@ -140,7 +156,8 @@
   "fieldtype": "Int", 
   "label": "Credit Days", 
   "oldfieldname": "credit_days", 
-  "oldfieldtype": "Int"
+  "oldfieldtype": "Int", 
+  "read_only": 0
  }, 
  {
   "depends_on": "eval:!doc.__islocal", 
@@ -150,7 +167,8 @@
   "label": "Credit Limit", 
   "oldfieldname": "credit_limit", 
   "oldfieldtype": "Currency", 
-  "options": "default_currency"
+  "options": "default_currency", 
+  "read_only": 0
  }, 
  {
   "depends_on": "eval:!doc.__islocal", 
@@ -160,7 +178,8 @@
   "label": "If Yearly Budget Exceeded", 
   "oldfieldname": "yearly_bgt_flag", 
   "oldfieldtype": "Select", 
-  "options": "\nWarn\nIgnore\nStop"
+  "options": "\nWarn\nIgnore\nStop", 
+  "read_only": 0
  }, 
  {
   "depends_on": "eval:!doc.__islocal", 
@@ -170,14 +189,16 @@
   "label": "If Monthly Budget Exceeded", 
   "oldfieldname": "monthly_bgt_flag", 
   "oldfieldtype": "Select", 
-  "options": "\nWarn\nIgnore\nStop"
+  "options": "\nWarn\nIgnore\nStop", 
+  "read_only": 0
  }, 
  {
-  "depends_on": "eval:!doc.__islocal && sys_defaults.auto_inventory_accounting", 
+  "depends_on": "eval:!doc.__islocal", 
   "doctype": "DocField", 
   "fieldname": "auto_inventory_accounting_settings", 
   "fieldtype": "Section Break", 
-  "label": "Auto Inventory Accounting Settings"
+  "label": "Auto Inventory Accounting Settings", 
+  "read_only": 0
  }, 
  {
   "description": "This account will be used to maintain value of available stock", 
@@ -195,12 +216,14 @@
   "fieldtype": "Link", 
   "label": "Stock Received But Not Billed", 
   "no_copy": 1, 
-  "options": "Account"
+  "options": "Account", 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
   "fieldname": "col_break23", 
   "fieldtype": "Column Break", 
+  "read_only": 0, 
   "width": "50%"
  }, 
  {
@@ -209,7 +232,8 @@
   "fieldtype": "Link", 
   "label": "Stock Adjustment Account", 
   "no_copy": 1, 
-  "options": "Account"
+  "options": "Account", 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -217,7 +241,8 @@
   "fieldtype": "Link", 
   "label": "Expenses Included In Valuation", 
   "no_copy": 1, 
-  "options": "Account"
+  "options": "Account", 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -225,14 +250,16 @@
   "fieldtype": "Link", 
   "label": "Stock Adjustment Cost Center", 
   "no_copy": 1, 
-  "options": "Cost Center"
+  "options": "Cost Center", 
+  "read_only": 0
  }, 
  {
   "description": "For reference only.", 
   "doctype": "DocField", 
   "fieldname": "company_info", 
   "fieldtype": "Section Break", 
-  "label": "Company Info"
+  "label": "Company Info", 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -240,13 +267,15 @@
   "fieldtype": "Small Text", 
   "label": "Address", 
   "oldfieldname": "address", 
-  "oldfieldtype": "Small Text"
+  "oldfieldtype": "Small Text", 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
   "fieldname": "column_break1", 
   "fieldtype": "Column Break", 
   "oldfieldtype": "Column Break", 
+  "read_only": 0, 
   "width": "50%"
  }, 
  {
@@ -256,7 +285,8 @@
   "label": "Phone No", 
   "oldfieldname": "phone_no", 
   "oldfieldtype": "Data", 
-  "options": "Phone"
+  "options": "Phone", 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -265,7 +295,8 @@
   "label": "Fax", 
   "oldfieldname": "fax", 
   "oldfieldtype": "Data", 
-  "options": "Phone"
+  "options": "Phone", 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -274,7 +305,8 @@
   "label": "Email", 
   "oldfieldname": "email", 
   "oldfieldtype": "Data", 
-  "options": "Email"
+  "options": "Email", 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -282,7 +314,8 @@
   "fieldtype": "Data", 
   "label": "Website", 
   "oldfieldname": "website", 
-  "oldfieldtype": "Data"
+  "oldfieldtype": "Data", 
+  "read_only": 0
  }, 
  {
   "description": "Company registration numbers for your reference. Example: VAT Registration Numbers etc.", 
@@ -291,6 +324,7 @@
   "fieldtype": "Section Break", 
   "label": "Registration Info", 
   "oldfieldtype": "Section Break", 
+  "read_only": 0, 
   "width": "50%"
  }, 
  {
@@ -300,7 +334,8 @@
   "fieldtype": "Code", 
   "label": "Registration Details", 
   "oldfieldname": "registration_details", 
-  "oldfieldtype": "Code"
+  "oldfieldtype": "Code", 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -313,19 +348,6 @@
   "read_only": 1
  }, 
  {
-  "cancel": 1, 
-  "create": 1, 
-  "doctype": "DocPerm", 
-  "permlevel": 0, 
-  "role": "System Manager", 
-  "write": 1
- }, 
- {
-  "cancel": 0, 
-  "create": 0, 
-  "doctype": "DocPerm", 
-  "permlevel": 1, 
-  "role": "All", 
-  "write": 0
+  "doctype": "DocPerm"
  }
 ]
\ No newline at end of file
diff --git a/setup/doctype/email_digest/email_digest.py b/setup/doctype/email_digest/email_digest.py
index cb49f3c..0b0b21a 100644
--- a/setup/doctype/email_digest/email_digest.py
+++ b/setup/doctype/email_digest/email_digest.py
@@ -315,7 +315,7 @@
 			return 0, "<p>Calendar Events</p>"
 	
 	def get_todo_list(self, user_id):
-		from utilities.page.todo.todo import get
+		from core.page.todo.todo import get
 		todo_list = get()
 		
 		html = ""
diff --git a/setup/doctype/global_defaults/global_defaults.py b/setup/doctype/global_defaults/global_defaults.py
index 3f8de1d..8275513 100644
--- a/setup/doctype/global_defaults/global_defaults.py
+++ b/setup/doctype/global_defaults/global_defaults.py
@@ -62,7 +62,6 @@
 
 	def on_update(self):
 		"""update defaults"""
-		
 		self.validate_session_expiry()
 		
 		for key in keydict:
diff --git a/setup/page/modules_setup/__init__.py b/setup/page/modules_setup/__init__.py
deleted file mode 100644
index baffc48..0000000
--- a/setup/page/modules_setup/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-from __future__ import unicode_literals
diff --git a/setup/page/modules_setup/modules_setup.css b/setup/page/modules_setup/modules_setup.css
deleted file mode 100644
index e69de29..0000000
--- a/setup/page/modules_setup/modules_setup.css
+++ /dev/null
diff --git a/setup/page/modules_setup/modules_setup.html b/setup/page/modules_setup/modules_setup.html
deleted file mode 100644
index 26130de..0000000
--- a/setup/page/modules_setup/modules_setup.html
+++ /dev/null
@@ -1,14 +0,0 @@
-<div class="layout-wrapper">
-	<a class="close" onclick="window.history.back();">&times;</a>		
-	<h1>Modules Setup</h1>
-	<hr>
-	<div class="help" style="width: 300px; float: right">
-		Select checkbox to show / hide module.
-	</div>
-	<div id="modules-list">
-	</div>
-	<div>
-		<button class="btn btn-small btn-primary" id="modules-update" 
-			onclick="wn.pages.modules_setup.update()">Update</button>
-	</div>
-</div>
\ No newline at end of file
diff --git a/setup/page/modules_setup/modules_setup.js b/setup/page/modules_setup/modules_setup.js
deleted file mode 100644
index 5868b46..0000000
--- a/setup/page/modules_setup/modules_setup.js
+++ /dev/null
@@ -1,51 +0,0 @@
-wn.require('lib/js/lib/jquery/jquery.ui.sortable.js');
-
-$.extend(wn.pages.modules_setup, {
-	modules: ['Activity', 'Accounts', 'Selling', 'Buying', 'Stock', 'Manufacturing', 'Projects', 
-		'Support', 'HR', 'Website', 'To Do', 'Messages', 'Calendar', 'Knowledge Base'],	
-	onload: function(wrapper) {
-		wn.pages.modules_setup.refresh_page(JSON.parse(wn.boot.modules_list || "[]"));
-	},
-	refresh_page: function(ml) {
-		$('#modules-list').empty();
-
-		// Hide Setup and Dashboard modules
-		ml.indexOf('Setup')!=-1 && ml.splice(ml.indexOf('Setup'), 1);
-
-		// checked modules
-		for(i in ml) {
-			$('#modules-list').append(repl('<p style="cursor:move;">\
-				<input type="checkbox" data-module="%(m)s"> \
-				%(m)s</p>', {m:ml[i]}));
-		}
-		$('#modules-list [data-module]').attr('checked', true);
-		
-		// unchecked modules
-		var all = wn.pages.modules_setup.modules;
-		for(i in all) {
-			if(!$('#modules-list [data-module="'+all[i]+'"]').length) {
-				$('#modules-list').append(repl('<p style="cursor:move;">\
-					<input type="checkbox" data-module="%(m)s"> \
-					%(m)s</p>', {m:all[i]}));				
-			}
-		}
-		
-	},
-	update: function() {
-		var ml = [];
-		$('#modules-list [data-module]').each(function() {
-			if($(this).attr('checked')) 
-				ml.push($(this).attr('data-module'));
-		});
-		
-		wn.call({
-			method: 'setup.page.modules_setup.modules_setup.update',
-			args: {
-				ml: JSON.stringify(ml)
-			},
-			callback: function(r) {
-			},
-			btn: $('#modules-update').get(0)
-		});
-	}
-});
diff --git a/setup/page/modules_setup/modules_setup.py b/setup/page/modules_setup/modules_setup.py
deleted file mode 100644
index 3a3504a..0000000
--- a/setup/page/modules_setup/modules_setup.py
+++ /dev/null
@@ -1,9 +0,0 @@
-from __future__ import unicode_literals
-import webnotes
-
-@webnotes.whitelist()
-def update(arg=None):
-	"""update modules"""
-	webnotes.conn.set_global('modules_list', webnotes.form_dict['ml'])
-	webnotes.msgprint('Updated')
-	webnotes.clear_cache()
\ No newline at end of file
diff --git a/setup/page/modules_setup/modules_setup.txt b/setup/page/modules_setup/modules_setup.txt
deleted file mode 100644
index a20e9df..0000000
--- a/setup/page/modules_setup/modules_setup.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-[
- {
-  "owner": "Administrator", 
-  "docstatus": 0, 
-  "creation": "2012-06-14 15:07:28", 
-  "modified_by": "Administrator", 
-  "modified": "2012-10-04 16:55:31"
- }, 
- {
-  "name": "__common__", 
-  "title": "Modules Setup", 
-  "module": "Setup", 
-  "doctype": "Page", 
-  "page_name": "modules_setup", 
-  "standard": "Yes"
- }, 
- {
-  "parent": "modules_setup", 
-  "name": "__common__", 
-  "doctype": "Page Role", 
-  "parenttype": "Page", 
-  "role": "System Manager", 
-  "parentfield": "roles"
- }, 
- {
-  "name": "modules_setup", 
-  "doctype": "Page"
- }, 
- {
-  "doctype": "Page Role"
- }
-]
\ No newline at end of file
diff --git a/startup/boot.py b/startup/boot.py
index 574646f..4774a90 100644
--- a/startup/boot.py
+++ b/startup/boot.py
@@ -26,9 +26,7 @@
 		import webnotes.model.doctype
 		bootinfo['notification_settings'] = webnotes.doc("Notification Control", 
 			"Notification Control").get_values()
-		
-		bootinfo['modules_list'] = webnotes.conn.get_global('modules_list')
-		
+				
 		# if no company, show a dialog box to create a new company
 		bootinfo['setup_complete'] = webnotes.conn.sql("""select name from 
 			tabCompany limit 1""") and 'Yes' or 'No'
diff --git a/startup/website.py b/startup/website.py
index 1041039..295e5bb 100644
--- a/startup/website.py
+++ b/startup/website.py
@@ -1,47 +1,8 @@
 import webnotes, conf, os
 
-
 def get_templates_path():
 	return os.path.join(os.path.dirname(conf.__file__), "app", "website", "templates")
 
-standard_pages = [
-	"404", "about", "account", "attributions", "blog", "contact", "error", "index",
-	"login", "message", "order", "orders", "print", "product_search", "profile",
-	"ticket", "tickets", "writers"
-]
-
-page_map = {
-	'Web Page': webnotes._dict({
-		"template": 'html/web_page.html',
-		"condition_field": "published"
-	}),
-	'Blog Post': webnotes._dict({
-		"template": 'html/blog_page.html',
-		"condition_field": "published",
-	}),
-	'Item': webnotes._dict({
-		"template": 'html/product_page.html',
-		"condition_field": "show_in_website",
-	}),
-	'Item Group': webnotes._dict({
-		"template": "html/product_group.html",
-		"condition_field": "show_in_website"
-	})
-}
-
-page_settings_map = {
-	"about": "website.doctype.about_us_settings.about_us_settings.get_args",
-	"contact": "Contact Us Settings",
-	"blog": "website.helpers.blog.get_blog_template_args",
-	"writers": "website.helpers.blog.get_writers_args",
-	"print": "core.doctype.print_format.print_format.get_args",
-	"orders": "selling.doctype.sales_order.sales_order.get_currency_and_number_format",
-	"order": "selling.doctype.sales_order.sales_order.get_website_args",
-	"ticket": "support.doctype.support_ticket.support_ticket.get_website_args"
-}
-
-no_cache = ["message", "print", "order", "ticket"]
-
 def get_home_page():
 	doc_name = webnotes.conn.get_value('Website Settings', None, 'home_page')
 	if doc_name:
diff --git a/stock/doctype/delivery_note/delivery_note.js b/stock/doctype/delivery_note/delivery_note.js
index 61df6b0..8870832 100644
--- a/stock/doctype/delivery_note/delivery_note.js
+++ b/stock/doctype/delivery_note/delivery_note.js
@@ -74,6 +74,11 @@
 	cur_frm.toggle_display("contact_info", doc.customer);
 	
 	set_print_hide(doc, cdt, cdn);
+	
+	// unhide expense_account and cost_center is auto_inventory_accounting enabled
+	var aii_enabled = cint(sys_defaults.auto_inventory_accounting)
+	cur_frm.fields_dict[cur_frm.cscript.fname].grid.set_column_disp("expense_account", aii_enabled);
+	cur_frm.fields_dict[cur_frm.cscript.fname].grid.set_column_disp("cost_center", aii_enabled);
 }
 
 
diff --git a/stock/doctype/delivery_note/delivery_note.py b/stock/doctype/delivery_note/delivery_note.py
index ab7d060..0019698 100644
--- a/stock/doctype/delivery_note/delivery_note.py
+++ b/stock/doctype/delivery_note/delivery_note.py
@@ -21,6 +21,8 @@
 from webnotes.model.bean import getlist
 from webnotes.model.code import get_obj
 from webnotes import msgprint
+import webnotes.defaults
+
 
 sql = webnotes.conn.sql
 
@@ -312,7 +314,7 @@
 		webnotes.conn.set(self.doc, 'status', 'Cancelled')
 		self.cancel_packing_slips()
 		
-		self.make_gl_entries()
+		self.make_cancel_gl_entries()
 
 
 	def check_next_docstatus(self):
diff --git a/stock/doctype/item/item.py b/stock/doctype/item/item.py
index 43bae2c..5d52f84 100644
--- a/stock/doctype/item/item.py
+++ b/stock/doctype/item/item.py
@@ -17,7 +17,7 @@
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import cstr, flt
+from webnotes.utils import cstr, flt, cint
 from webnotes.model.doc import addchild
 from webnotes.model.bean import getlist
 from webnotes import msgprint, _
@@ -119,7 +119,7 @@
 	def check_ref_rate_detail(self):
 		check_list=[]
 		for d in getlist(self.doclist,'ref_rate_details'):
-			if [cstr(d.price_list_name),cstr(d.ref_currency)] in check_list:
+			if [cstr(d.price_list_name),cstr(d.ref_currency),cint(d.selling),cint(d.buying)] in check_list:
 				msgprint("Ref Rate is entered twice for Price List : '%s' and Currency : '%s'." % (d.price_list_name,d.ref_currency))
 				raise Exception
 			else:
diff --git a/stock/doctype/purchase_receipt/purchase_receipt.py b/stock/doctype/purchase_receipt/purchase_receipt.py
index 7bc470d..8e81fa5 100644
--- a/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -21,6 +21,7 @@
 from webnotes.model.bean import getlist
 from webnotes.model.code import get_obj
 from webnotes import msgprint
+import webnotes.defaults
 
 sql = webnotes.conn.sql
 
@@ -290,7 +291,7 @@
 		# 6. Update last purchase rate
 		pc_obj.update_last_purchase_rate(self, 0)
 		
-		self.make_gl_entries()
+		self.make_cancel_gl_entries()
 
 	def bk_flush_supp_wh(self, is_submit):
 		for d in getlist(self.doclist, 'pr_raw_material_details'):
@@ -326,7 +327,7 @@
 		gl_entries = self.get_gl_entries_for_stock(against_stock_account, total_valuation_amount)
 		
 		if gl_entries:
-			make_gl_entries(gl_entries, cancel=self.doc.docstatus == 2)
+			make_gl_entries(gl_entries, cancel=(self.doc.docstatus == 2))
 		
 	def get_total_valuation_amount(self):
 		total_valuation_amount = 0.0
diff --git a/stock/doctype/serial_no/serial_no.py b/stock/doctype/serial_no/serial_no.py
index 5b15977..65bd2dd 100644
--- a/stock/doctype/serial_no/serial_no.py
+++ b/stock/doctype/serial_no/serial_no.py
@@ -19,7 +19,7 @@
 
 from webnotes.utils import cint, getdate, nowdate
 import datetime
-from webnotes import msgprint, _
+from webnotes import msgprint
 	
 from controllers.stock_controller import StockController
 
@@ -103,7 +103,12 @@
 		elif self.doc.status == 'In Store': 
 			webnotes.conn.set(self.doc, 'status', 'Not in Use')
 			self.make_stock_ledger_entry(-1)
-			self.make_gl_entries(cancel=True)
+			
+			if cint(webnotes.defaults.get_global_default("auto_inventory_accounting")) \
+				and webnotes.conn.sql("""select name from `tabGL Entry`
+				where voucher_type=%s and voucher_no=%s and ifnull(is_cancelled, 'No')='No'""",
+				(self.doc.doctype, self.doc.name)):
+					self.make_gl_entries(cancel=True)
 
 
 	def on_cancel(self):
diff --git a/stock/doctype/stock_entry/stock_entry.js b/stock/doctype/stock_entry/stock_entry.js
index 3e21207..1f4aafa 100644
--- a/stock/doctype/stock_entry/stock_entry.js
+++ b/stock/doctype/stock_entry/stock_entry.js
@@ -77,7 +77,7 @@
 		};
 		
 		if (sys_defaults.auto_inventory_accounting) {
-			this.frm.add_fetch("company", "expense_adjustment_account", "stock_adjustment_account");
+			this.frm.add_fetch("company", "stock_adjustment_account", "expense_adjustment_account");
 
 			this.frm.fields_dict["expense_adjustment_account"].get_query = function() {
 				return {
diff --git a/stock/doctype/stock_entry/stock_entry.py b/stock/doctype/stock_entry/stock_entry.py
index a176188..fa60072 100644
--- a/stock/doctype/stock_entry/stock_entry.py
+++ b/stock/doctype/stock_entry/stock_entry.py
@@ -16,6 +16,7 @@
 
 from __future__ import unicode_literals
 import webnotes
+import webnotes.defaults
 
 from webnotes.utils import cstr, cint, flt, comma_or
 from webnotes.model.doc import Document, addchild
@@ -67,7 +68,7 @@
 		self.update_serial_no(0)
 		self.update_stock_ledger(1)
 		self.update_production_order(0)
-		self.make_gl_entries()
+		self.make_cancel_gl_entries()
 		
 	def validate_fiscal_year(self):
 		import accounts.utils
@@ -426,16 +427,18 @@
 		
 	def get_warehouse_details(self, args):
 		args = json.loads(args)
-		args.update({
-			"posting_date": self.doc.posting_date,
-			"posting_time": self.doc.posting_time,
-		})
-		args = webnotes._dict(args)
+		ret = {}
+		if args.get('warehouse') and args.get('item_code'):
+			args.update({
+				"posting_date": self.doc.posting_date,
+				"posting_time": self.doc.posting_time,
+			})
+			args = webnotes._dict(args)
 		
-		ret = {
-			"actual_qty" : get_previous_sle(args).get("qty_after_transaction") or 0,
-			"incoming_rate" : self.get_incoming_rate(args)
-		}
+			ret = {
+				"actual_qty" : get_previous_sle(args).get("qty_after_transaction") or 0,
+				"incoming_rate" : self.get_incoming_rate(args)
+			}
 		return ret
 		
 	def get_items(self):
diff --git a/stock/doctype/stock_entry/stock_entry.txt b/stock/doctype/stock_entry/stock_entry.txt
index 91f9bb4..fef710b 100644
--- a/stock/doctype/stock_entry/stock_entry.txt
+++ b/stock/doctype/stock_entry/stock_entry.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-03-26 06:51:17", 
+  "creation": "2013-03-28 15:56:40", 
   "docstatus": 0, 
-  "modified": "2013-03-26 07:24:53", 
+  "modified": "2013-03-29 15:31:42", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -116,6 +116,7 @@
   "oldfieldtype": "Link", 
   "options": "Delivery Note", 
   "print_hide": 1, 
+  "read_only": 0, 
   "report_hide": 0, 
   "reqd": 0, 
   "search_index": 1
@@ -129,7 +130,8 @@
   "label": "Sales Invoice No", 
   "no_copy": 1, 
   "options": "Sales Invoice", 
-  "print_hide": 1
+  "print_hide": 1, 
+  "read_only": 0
  }, 
  {
   "allow_on_submit": 0, 
@@ -145,6 +147,7 @@
   "oldfieldtype": "Link", 
   "options": "Purchase Receipt", 
   "print_hide": 1, 
+  "read_only": 0, 
   "report_hide": 0, 
   "reqd": 0, 
   "search_index": 1
@@ -201,7 +204,9 @@
   "fieldname": "expense_adjustment_account", 
   "fieldtype": "Link", 
   "label": "Expense/Adjustment Account", 
-  "options": "Account"
+  "options": "Account", 
+  "print_hide": 1, 
+  "read_only": 0
  }, 
  {
   "doctype": "DocField", 
@@ -550,6 +555,7 @@
   "label": "Fiscal Year", 
   "options": "link:Fiscal Year", 
   "print_hide": 1, 
+  "read_only": 0, 
   "reqd": 1
  }, 
  {
@@ -620,5 +626,13 @@
  {
   "doctype": "DocPerm", 
   "role": "Manufacturing User"
+ }, 
+ {
+  "doctype": "DocPerm", 
+  "role": "Manufacturing Manager"
+ }, 
+ {
+  "doctype": "DocPerm", 
+  "role": "Material Manager"
  }
 ]
\ No newline at end of file
diff --git a/stock/doctype/stock_entry_detail/stock_entry_detail.txt b/stock/doctype/stock_entry_detail/stock_entry_detail.txt
index 2c59dd7..8426ddca 100644
--- a/stock/doctype/stock_entry_detail/stock_entry_detail.txt
+++ b/stock/doctype/stock_entry_detail/stock_entry_detail.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-02-22 01:28:04", 
+  "creation": "2013-03-29 18:22:12", 
   "docstatus": 0, 
-  "modified": "2013-03-07 07:03:32", 
+  "modified": "2013-03-29 19:43:04", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -158,6 +158,7 @@
   "label": "Conversion Factor", 
   "oldfieldname": "conversion_factor", 
   "oldfieldtype": "Currency", 
+  "print_hide": 1, 
   "read_only": 1, 
   "reqd": 1
  }, 
@@ -168,6 +169,7 @@
   "label": "Qty as per Stock UOM", 
   "oldfieldname": "transfer_qty", 
   "oldfieldtype": "Currency", 
+  "print_hide": 1, 
   "read_only": 1, 
   "reqd": 1
  }, 
@@ -180,6 +182,7 @@
   "oldfieldname": "stock_uom", 
   "oldfieldtype": "Link", 
   "options": "UOM", 
+  "print_hide": 1, 
   "read_only": 1, 
   "reqd": 1, 
   "search_index": 0
diff --git a/stock/doctype/stock_reconciliation/stock_reconciliation.js b/stock/doctype/stock_reconciliation/stock_reconciliation.js
index b723061..a115364 100644
--- a/stock/doctype/stock_reconciliation/stock_reconciliation.js
+++ b/stock/doctype/stock_reconciliation/stock_reconciliation.js
@@ -42,7 +42,7 @@
 	setup: function() {
 		var me = this;
 		
-		this.frm.add_fetch("company", "expense_account", "stock_adjustment_account");
+		this.frm.add_fetch("company", "stock_adjustment_account", "expense_account");
 		
 		this.frm.fields_dict["expense_account"].get_query = function() {
 			return {
diff --git a/stock/doctype/stock_reconciliation/stock_reconciliation.py b/stock/doctype/stock_reconciliation/stock_reconciliation.py
index f32a78b..49e8b15 100644
--- a/stock/doctype/stock_reconciliation/stock_reconciliation.py
+++ b/stock/doctype/stock_reconciliation/stock_reconciliation.py
@@ -16,6 +16,7 @@
 
 from __future__ import unicode_literals
 import webnotes
+import webnotes.defaults
 import json
 from webnotes import msgprint, _
 from webnotes.utils import cstr, flt, cint
@@ -37,7 +38,7 @@
 		
 	def on_cancel(self):
 		self.delete_stock_ledger_entries()
-		self.make_gl_entries()
+		self.make_cancel_gl_entries()
 		
 	def validate_data(self):
 		if not self.doc.reconciliation_json:
diff --git a/utilities/page/messages/__init__.py b/utilities/page/messages/__init__.py
deleted file mode 100644
index baffc48..0000000
--- a/utilities/page/messages/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-from __future__ import unicode_literals
diff --git a/utilities/page/messages/messages.css b/utilities/page/messages/messages.css
deleted file mode 100644
index 88bbde7..0000000
--- a/utilities/page/messages/messages.css
+++ /dev/null
@@ -1,32 +0,0 @@
-#message-post-text {
-}
-
-#message-list {	
-}
-
-.message {
-	padding: 7px;
-	padding-left: 17px;
-	border-bottom: 1px solid #ccc;
-}
-
-.message-mark {
-	margin-left: -17px;
-	width: 9px;
-	position: absolute;
-	height: 30px;
-}
-
-.message .help {
-	margin-bottom: 0px;
-	padding-bottom: 0px;
-	color: #888;
-	font-size: 11px;
-}
-
-.message-other {
-}
-
-.message-self {
-	background-color: #eee;
-}
\ No newline at end of file
diff --git a/utilities/page/messages/messages.html b/utilities/page/messages/messages.html
deleted file mode 100644
index e69de29..0000000
--- a/utilities/page/messages/messages.html
+++ /dev/null
diff --git a/utilities/page/messages/messages.js b/utilities/page/messages/messages.js
deleted file mode 100644
index 4d77e16..0000000
--- a/utilities/page/messages/messages.js
+++ /dev/null
@@ -1,214 +0,0 @@
-// 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/>.
-
-wn.provide('erpnext.messages');
-
-wn.pages.messages.onload = function(wrapper) {
-	wn.ui.make_app_page({
-		parent: wrapper,
-		title: "Messages"
-	});
-	
-	$('<div><div class="avatar avatar-large">\
-		<img id="avatar-image" src="lib/images/ui/avatar.png"></div>\
-		<h3 style="display: inline-block" id="message-title">Everyone</h3>\
-	</div><hr>\
-	<div id="post-message">\
-	<textarea style="width: 100%; height: 24px;"></textarea>\
-	<div><button class="btn">Post</button></div><hr>\
-	</div>\
-	<div class="all-messages"></div>').appendTo($(wrapper).find('.layout-main-section'));
-
-	wrapper.appframe.add_home_breadcrumb();
-	wrapper.appframe.add_breadcrumb(wn.modules["Messages"].icon);
-	
-	erpnext.messages = new erpnext.Messages(wrapper);
-	erpnext.toolbar.set_new_comments(0);
-}
-
-$(wn.pages.messages).bind('show', function() {
-	// remove alerts
-	$('#alert-container .alert').remove();
-	
-	erpnext.toolbar.set_new_comments(0);	
-	erpnext.messages.show();
-	setTimeout("erpnext.messages.refresh()", 17000);
-})
-
-erpnext.Messages = Class.extend({
-	init: function(wrapper) {
-		this.wrapper = wrapper;
-		this.show_active_users();
-		this.make_post_message();
-		this.make_list();
-		//this.update_messages('reset'); //Resets notification icons		
-	},
-	make_post_message: function() {
-		var me = this;
-		$('#post-message textarea').keydown(function(e) {
-			if(e.which==13) {
-				$('#post-message .btn').click();
-				return false;
-			}
-		});
-		
-		$('#post-message .btn').click(function() {
-			var txt = $('#post-message textarea').val();
-			if(txt) {
-				wn.call({
-					module:'utilities',
-					page:'messages',
-					method:'post',
-					args: {
-						txt: txt,
-						contact: me.contact
-					},
-					callback:function(r,rt) {
-						$('#post-message textarea').val('')
-						me.list.run();
-					},
-					btn: this
-				});
-			}			
-		});
-	},
-	show: function() {
-		var contact = this.get_contact() || this.contact || user;
-
-		$('#message-title').html(contact==user ? "Everyone" :
-			wn.user_info(contact).fullname)
-
-		$('#avatar-image').attr("src", wn.utils.get_file_link(wn.user_info(contact).image));
-
-		$("#show-everyone").toggle(contact!=user);
-		
-		$("#post-message button").text(contact==user ? "Post Publicly" : "Post to user")
-		
-		this.contact = contact;
-		this.list.opts.args.contact = contact;
-		this.list.run();
-		
-	},
-	// check for updates every 5 seconds if page is active
-	refresh: function() {
-		setTimeout("erpnext.messages.refresh()", 17000);
-		if(wn.container.page.label != 'Messages') return;
-		this.show();
-	},
-	get_contact: function() {
-		var route = location.hash;
-		if(route.indexOf('/')!=-1) {
-			var name = decodeURIComponent(route.split('/')[1]);
-			if(name.indexOf('__at__')!=-1) {
-				name = name.replace('__at__', '@');
-			}
-			return name;
-		}
-	},
-	make_list: function() {
-		this.list = new wn.ui.Listing({
-			parent: $(this.wrapper).find('.all-messages'),
-			method: 'utilities.page.messages.messages.get_list',
-			args: {
-				contact: null
-			},
-			hide_refresh: true,
-			no_loading: true,
-			render_row: function(wrapper, data) {
-				$(wrapper).removeClass('list-row');
-				
-				data.creation = dateutil.comment_when(data.creation);
-				data.comment_by_fullname = wn.user_info(data.owner).fullname;
-				data.image = wn.utils.get_file_link(wn.user_info(data.owner).image);
-				data.mark_html = "";
-
-				data.reply_html = '';
-				if(data.owner==user) {
-					data.cls = 'message-self';
-					data.comment_by_fullname = 'You';	
-				} else {
-					data.cls = 'message-other';
-				}
-
-				// delete
-				data.delete_html = "";
-				if(data.owner==user || data.comment.indexOf("assigned to")!=-1) {
-					data.delete_html = repl('<a class="close" \
-						onclick="erpnext.messages.delete(this)"\
-						data-name="%(name)s">&times;</a>', data);
-				}
-				
-				if(data.owner==data.comment_docname && data.parenttype!="Assignment") {
-					data.mark_html = "<div class='message-mark' title='Public'\
-						style='background-color: green'></div>"
-				}
-
-				wrapper.innerHTML = repl('<div class="message %(cls)s">%(mark_html)s\
-						<span class="avatar avatar-small"><img src="%(image)s"></span><b>%(comment)s</b>\
-						%(delete_html)s\
-						<div class="help">by %(comment_by_fullname)s, %(creation)s</div>\
-					</div>\
-					<div style="clear: both;"></div>', data);
-			}
-		});
-	},
-	delete: function(ele) {
-		$(ele).parent().css('opacity', 0.6);
-		wn.call({
-			method:'utilities.page.messages.messages.delete',
-			args: {name : $(ele).attr('data-name')},
-			callback: function() {
-				$(ele).parent().toggle(false);
-			}
-		});
-	},
-	show_active_users: function() {
-		var me = this;
-		wn.call({
-			module:'utilities',
-			page:'messages',
-			method:'get_active_users',
-			callback: function(r,rt) {
-				var $body = $(me.wrapper).find('.layout-side-section');
-				$('<h4>Users</h4><hr>\
-					<div id="show-everyone">\
-						<a href="#messages/'+user+'" class="btn">\
-							Show messages from everyone</a><hr></div>\
-				').appendTo($body);
-				r.message.sort(function(a, b) { return b.has_session - a.has_session; });
-				for(var i in r.message) {
-					var p = r.message[i];
-					if(p.name != user) {
-						p.fullname = wn.user_info(p.name).fullname;
-						p.image = wn.utils.get_file_link(wn.user_info(p.name).image);
-						p.name = p.name.replace('@', '__at__');
-						p.status_color = p.has_session ? "green" : "#ddd";
-						p.status = p.has_session ? "Online" : "Offline";
-						$(repl('<p>\
-							<span class="avatar avatar-small" \
-								style="border: 3px solid %(status_color)s" \
-								title="%(status)s"><img src="%(image)s"></span>\
-							<a href="#!messages/%(name)s">%(fullname)s</a>\
-							</p>', p))
-							.appendTo($body);						
-					}
-				}
-			}
-		});
-	}
-});
-
-
diff --git a/utilities/page/messages/messages.py b/utilities/page/messages/messages.py
deleted file mode 100644
index 90f5e91..0000000
--- a/utilities/page/messages/messages.py
+++ /dev/null
@@ -1,117 +0,0 @@
-# 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
-
-@webnotes.whitelist()
-def get_list(arg=None):
-	"""get list of messages"""
-	webnotes.form_dict['limit_start'] = int(webnotes.form_dict['limit_start'])
-	webnotes.form_dict['limit_page_length'] = int(webnotes.form_dict['limit_page_length'])
-	webnotes.form_dict['user'] = webnotes.session['user']
-
-	# set all messages as read
-	webnotes.conn.begin()
-	webnotes.conn.sql("""UPDATE `tabComment`
-	set docstatus = 1 where comment_doctype in ('My Company', 'Message')
-	and comment_docname = %s
-	""", webnotes.user.name)
-	webnotes.conn.commit()
-
-	if webnotes.form_dict['contact'] == webnotes.session['user']:
-		# return messages
-		return webnotes.conn.sql("""select * from `tabComment` 
-		where (owner=%(contact)s 
-			or comment_docname=%(user)s 
-			or (owner=comment_docname and ifnull(parenttype, "")!="Assignment"))
-		and comment_doctype ='Message'
-		order by creation desc
-		limit %(limit_start)s, %(limit_page_length)s""", webnotes.form_dict, as_dict=1)		
-	else:
-		return webnotes.conn.sql("""select * from `tabComment` 
-		where (owner=%(contact)s and comment_docname=%(user)s)
-		or (owner=%(user)s and comment_docname=%(contact)s)
-		or (owner=%(contact)s and comment_docname=%(contact)s)
-		and comment_doctype ='Message'
-		order by creation desc
-		limit %(limit_start)s, %(limit_page_length)s""", webnotes.form_dict, as_dict=1)
-		
-
-@webnotes.whitelist()
-def get_active_users(arg=None):
-	return webnotes.conn.sql("""select name,
-		(select count(*) from tabSessions where user=tabProfile.name
-			and timediff(now(), lastupdate) < time("01:00:00")) as has_session
-	 	from tabProfile 
-		where ifnull(enabled,0)=1 and
-		docstatus < 2 and 
-		name not in ('Administrator', 'Guest') 
-		order by first_name""", as_dict=1)
-
-@webnotes.whitelist()
-def post(arg=None):
-	import webnotes
-	"""post message"""
-	if not arg:
-		arg = {}
-		arg.update(webnotes.form_dict)
-	
-	if isinstance(arg, basestring):
-		import json
-		arg = json.loads(arg)
-
-	from webnotes.model.doc import Document
-	d = Document('Comment')
-	d.parenttype = arg.get("parenttype")
-	d.comment = arg['txt']
-	d.comment_docname = arg['contact']
-	d.comment_doctype = 'Message'
-	d.save()
-
-	import webnotes.utils
-	if webnotes.utils.cint(arg.get('notify')):
-		notify(arg)
-	
-@webnotes.whitelist()
-def delete(arg=None):
-	webnotes.conn.sql("""delete from `tabComment` where name=%s""", 
-		webnotes.form_dict['name']);
-
-def notify(arg=None):
-	from webnotes.utils import cstr, get_fullname
-	from startup import get_url
-	
-	fn = get_fullname(webnotes.user.name) or webnotes.user.name
-	
-	url = get_url()
-	
-	message = '''You have a message from <b>%s</b>:
-	
-	%s
-	
-	To answer, please login to your erpnext account at \
-	<a href=\"%s\" target='_blank'>%s</a>
-	''' % (fn, arg['txt'], url, url)
-	
-	sender = webnotes.conn.get_value("Profile", webnotes.user.name, "email") \
-		or webnotes.user.name
-	recipient = [webnotes.conn.get_value("Profile", arg["contact"], "email") \
-		or arg["contact"]]
-	
-	from webnotes.utils.email_lib import sendmail
-	sendmail(recipient, sender, message, arg.get("subject") or "You have a message from %s" % (fn,))
-	
\ No newline at end of file
diff --git a/utilities/page/messages/messages.txt b/utilities/page/messages/messages.txt
deleted file mode 100644
index 32fab17..0000000
--- a/utilities/page/messages/messages.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-[
- {
-  "owner": "Administrator", 
-  "docstatus": 0, 
-  "creation": "2012-02-24 11:21:57", 
-  "modified_by": "Administrator", 
-  "modified": "2012-02-24 11:21:57"
- }, 
- {
-  "name": "__common__", 
-  "title": "Messages", 
-  "module": "Utilities", 
-  "doctype": "Page", 
-  "page_name": "messages", 
-  "standard": "Yes"
- }, 
- {
-  "name": "messages", 
-  "doctype": "Page"
- }
-]
\ No newline at end of file
diff --git a/utilities/page/questions/questions.py b/utilities/page/questions/questions.py
index 20d3803..442fb01 100644
--- a/utilities/page/questions/questions.py
+++ b/utilities/page/questions/questions.py
@@ -55,7 +55,7 @@
 	d.save(1)
 	
 	if args['suggest']:
-		from utilities.page.messages import messages
+		from core.page.messages import messages
 		for s in args['suggest']:
 			if s:
 				messages.post(json.dumps({
diff --git a/utilities/page/todo/__init__.py b/utilities/page/todo/__init__.py
deleted file mode 100644
index baffc48..0000000
--- a/utilities/page/todo/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-from __future__ import unicode_literals
diff --git a/utilities/page/todo/todo.css b/utilities/page/todo/todo.css
deleted file mode 100644
index f67f729..0000000
--- a/utilities/page/todo/todo.css
+++ /dev/null
@@ -1,51 +0,0 @@
-.todoitem {
-	padding-bottom: 3px;
-	clear: both;
-}
-
-.todoitem div {
-	float: left;
-	display: inline-block;
-	padding: 3px;
-}
-
-.todoitem .label {
-	width: 50px;
-	margin-right: 11px;
-	margin-top: 3px;
-	text-align: center;
-}
-
-.todoitem .todo-date {
-	margin-top: -2px;
-	margin-right: 7px;
-	color: #aaa;
-}
-
-.todoitem .close {
-	margin-left: 5px;
-	font-size: 17px;
-}
-
-.todoitem .close-span {
-	float: right;
-}
-
-.todo-separator {
-	border-bottom: 1px solid #DEB85F;
-	margin-bottom: 5px;
-	clear: both;
-}
-
-.todo-content {
-	padding-right: 15px;
-}
-
-.todo-layout {
-	background-color: #FFFDC9;
-	min-height: 300px;
-}
-
-.todoitem .popup-on-click {
-	margin: 0px 6px;
-}
\ No newline at end of file
diff --git a/utilities/page/todo/todo.html b/utilities/page/todo/todo.html
deleted file mode 100644
index e00f8ef..0000000
--- a/utilities/page/todo/todo.html
+++ /dev/null
@@ -1,11 +0,0 @@
-<div class="layout-wrapper layout-wrapper-background">
-	<div class="appframe-area"></div>
-	<div class="layout-main todo-layout">
-		<div>
-			<div id="todo-list">
-				<div class="todo-content"></div>
-			</div>
-		</div>
-		<div style="clear: both"></div>
-	</div>
-</div>
\ No newline at end of file
diff --git a/utilities/page/todo/todo.js b/utilities/page/todo/todo.js
deleted file mode 100644
index fa82002..0000000
--- a/utilities/page/todo/todo.js
+++ /dev/null
@@ -1,212 +0,0 @@
-// 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/>.
-
-wn.provide('erpnext.todo');
-
-erpnext.todo.refresh = function() {
-	wn.call({
-		method: 'utilities.page.todo.todo.get',
-		callback: function(r,rt) {
-			var todo_list = $('#todo-list div.todo-content');
-			var assigned_todo_list = $('#assigned-todo-list div.todo-content');
-			todo_list.empty();
-			assigned_todo_list.empty();
-			
-			var nothing_to_do = function() {
-				$('#todo-list div.todo-content')
-					.html('<div class="alert">Nothing to do :)</div>');
-			}
-			
-			
-			if(r.message) {
-				for(var i in r.message) {
-					new erpnext.todo.ToDoItem(r.message[i]);
-				}
-				if (!todo_list.html()) { nothing_to_do(); }
-			} else {
-				nothing_to_do();
-			}
-		}
-	});
-}
-
-erpnext.todo.ToDoItem = Class.extend({
-	init: function(todo) {
-		label_map = {
-			'High': 'label-important',
-			'Medium': 'label-info',
-			'Low':''
-		}
-		todo.labelclass = label_map[todo.priority];
-		todo.userdate = dateutil.str_to_user(todo.date) || '';
-		
-		todo.fullname = '';
-		if(todo.assigned_by) {
-			var assigned_by = wn.boot.user_info[todo.assigned_by]
-			todo.fullname = repl("[By %(fullname)s] ".bold(), {
-				fullname: (assigned_by ? assigned_by.fullname : todo.assigned_by),
-			});
-		}
-		
-		var parent_list = "#todo-list";
-		if(todo.owner !== user) {
-			var owner = wn.boot.user_info[todo.owner];
-			todo.fullname = repl("[To %(fullname)s] ".bold(), {
-				fullname: (owner ? owner.fullname : todo.owner),
-			});
-		}
-		parent_list += " div.todo-content";
-		
-		if(todo.reference_name && todo.reference_type) {
-			todo.link = repl('<a href="#!Form/%(reference_type)s/%(reference_name)s">\
-						%(reference_type)s: %(reference_name)s</a>', todo);
-		} else if(todo.reference_type) {
-			todo.link = repl('<br><a href="#!List/%(reference_type)s">\
-						%(reference_type)s</a>', todo);
-		} else {
-			todo.link = '';
-		}
-		if(!todo.description) todo.description = '';
-		todo.description_display = todo.description.replace(/\n\n/g, "<br>").trim();
-				
-		$(parent_list).append(repl('\
-			<div class="todoitem">\
-				<div class="label %(labelclass)s">%(priority)s</div>\
-				<div class="popup-on-click"><a href="#">[edit]</a></div>\
-				<div class="todo-date-fullname">\
-					<div class="todo-date">%(userdate)s</div>\
-					%(fullname)s:\
-				</div>\
-				<div class="description">%(description_display)s\
-					<span class="ref_link">%(link)s</span>\
-				</div>\
-				<div class="close-span"><a href="#" class="close">&times;</a></div>\
-			</div>\
-			<div class="todo-separator"></div>', todo));
-		$todo = $(parent_list + ' div.todoitem:last');
-		
-		if(todo.checked) {
-			$todo.find('.description').css('text-decoration', 'line-through');
-		}
-		
-		if(!todo.reference_type)
-			$todo.find('.ref_link').toggle(false);
-		
-		$todo.find('.popup-on-click')
-			.data('todo', todo)
-			.click(function() {
-				erpnext.todo.make_dialog($(this).data('todo'));
-				return false;
-			});
-			
-		$todo.find('.close')
-			.data('name', todo.name)
-			.click(function() {
-				$(this).parent().css('opacity', 0.5);
-				wn.call({
-					method:'utilities.page.todo.todo.delete',
-					args: {name: $(this).data('name')},
-					callback: function() {
-						erpnext.todo.refresh();
-					}
-				});
-				return false;
-			})
-	}
-});
-
-erpnext.todo.make_dialog = function(det) {
-	if(!erpnext.todo.dialog) {
-		var dialog = new wn.ui.Dialog({
-			width: 480,
-			title: 'To Do', 
-			fields: [
-				{fieldtype:'Text', fieldname:'description', label:'Description', 
-					reqd:1},
-				{fieldtype:'Date', fieldname:'date', label:'Event Date', reqd:1},
-				{fieldtype:'Check', fieldname:'checked', label:'Completed'},
-				{fieldtype:'Select', fieldname:'priority', label:'Priority', reqd:1, 'options':['Medium','High','Low'].join('\n')},
-				{fieldtype:'Button', fieldname:'save', label:'Save (Ctrl+S)'}
-			]
-		});
-		
-		dialog.fields_dict.save.input.onclick = function() {
-			erpnext.todo.save(this);	
-		}
-		erpnext.todo.dialog = dialog;
-	}
-
-	if(det) {
-		erpnext.todo.dialog.set_values({
-			date: det.date,
-			priority: det.priority,
-			description: det.description,
-			checked: det.checked
-		});
-		erpnext.todo.dialog.det = det;		
-	}
-	erpnext.todo.dialog.show();
-	
-}
-
-erpnext.todo.save = function(btn) {
-	var d = erpnext.todo.dialog;
-	var det = d.get_values();
-	
-	if(!det) {
-	 	return;
-	}
-	
-	det.name = d.det.name || '';
-	wn.call({
-		method:'utilities.page.todo.todo.edit',
-		args: det,
-		btn: btn,
-		callback: function() {
-			erpnext.todo.dialog.hide();
-			erpnext.todo.refresh();
-		}
-	});
-}
-
-wn.pages.todo.onload = function(wrapper) {
-	// create app frame
-	wrapper.appframe = new wn.ui.AppFrame($(wrapper).find('.appframe-area'), 'To Do');
-	wrapper.appframe.add_home_breadcrumb();
-	wrapper.appframe.add_breadcrumb(wn.modules["To Do"].icon);
-	wrapper.appframe.add_button('Refresh', erpnext.todo.refresh, 'icon-refresh');
-	wrapper.appframe.add_button('Add', function() {
-		erpnext.todo.make_dialog({
-			date:get_today(), priority:'Medium', checked:0, description:''});
-	}, 'icon-plus');
-	wrapper.appframe.add_ripped_paper_effect(wrapper);
-	
-	// show report button for System Manager
-	if(wn.boot.profile.roles.indexOf("System Manager") !== -1) {
-		wrapper.appframe.add_button("Report", function() { wn.set_route("query-report", "todo"); },
-			"icon-table");
-	}
-
-	// load todos
-	erpnext.todo.refresh();
-	
-	// save on click
-	wrapper.save_action = function() {
-		if(erpnext.todo.dialog && erpnext.todo.dialog.display) {
-			erpnext.todo.dialog.fields_dict.save.input.click();
-		}
-	};
-}
\ No newline at end of file
diff --git a/utilities/page/todo/todo.py b/utilities/page/todo/todo.py
deleted file mode 100644
index f0de04e..0000000
--- a/utilities/page/todo/todo.py
+++ /dev/null
@@ -1,64 +0,0 @@
-# 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
-from webnotes.model.doc import Document
-
-@webnotes.whitelist()
-def get(arg=None):
-	"""get todo list"""
-	return webnotes.conn.sql("""select name, owner, description, date,
-		priority, checked, reference_type, reference_name, assigned_by
-		from `tabToDo` where (owner=%s or assigned_by=%s)
-		order by field(priority, 'High', 'Medium', 'Low') asc, date asc""",
-		(webnotes.session['user'], webnotes.session['user']), as_dict=1)
-
-@webnotes.whitelist()		
-def edit(arg=None):
-	import markdown2
-	args = webnotes.form_dict
-
-	d = Document('ToDo', args.get('name') or None)
-	d.description = args['description']
-	d.date = args['date']
-	d.priority = args['priority']
-	d.checked = args.get('checked', 0)
-	if not d.owner: d.owner = webnotes.session['user']
-	d.save(not args.get('name') and 1 or 0)
-
-	if args.get('name') and d.checked:
-		notify_assignment(d)
-
-	return d.name
-
-@webnotes.whitelist()
-def delete(arg=None):
-	name = webnotes.form_dict['name']
-	d = Document('ToDo', name)
-	if d and d.name and d.owner != webnotes.session['user']:
-		notify_assignment(d)
-	webnotes.conn.sql("delete from `tabToDo` where name = %s", name)
-
-def notify_assignment(d):
-	doc_type = d.reference_type
-	doc_name = d.reference_name
-	assigned_by = d.assigned_by
-	
-	if doc_type and doc_name and assigned_by:
-		from webnotes.widgets.form import assign_to
-		assign_to.notify_assignment(assigned_by, d.owner, doc_type, doc_name)
-		
\ No newline at end of file
diff --git a/utilities/page/todo/todo.txt b/utilities/page/todo/todo.txt
deleted file mode 100644
index 523bb43..0000000
--- a/utilities/page/todo/todo.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-[
- {
-  "owner": "Administrator", 
-  "docstatus": 0, 
-  "creation": "2012-02-23 13:59:03", 
-  "modified_by": "Administrator", 
-  "modified": "2012-02-23 13:59:03"
- }, 
- {
-  "name": "__common__", 
-  "title": "To Do", 
-  "module": "Utilities", 
-  "doctype": "Page", 
-  "page_name": "todo", 
-  "standard": "Yes"
- }, 
- {
-  "name": "todo", 
-  "doctype": "Page"
- }
-]
\ No newline at end of file
diff --git a/website/helpers/blog.py b/website/helpers/blog.py
index fb85e0d..386c4b7 100644
--- a/website/helpers/blog.py
+++ b/website/helpers/blog.py
@@ -74,7 +74,7 @@
 	webnotes.webutils.clear_cache(args.get('page_name'))
 	
 	comment['comment_date'] = webnotes.utils.global_date_format(comment['creation'])
-	template_args = { 'comment_list': [comment], 'template': 'html/comment.html' }
+	template_args = { 'comment_list': [comment], 'template': 'app/website/templates/html/comment.html' }
 	
 	# get html of comment row
 	comment_html = webnotes.webutils.build_html(template_args)
diff --git a/website/helpers/product.py b/website/helpers/product.py
index 4a1cd40..d6f16fb 100644
--- a/website/helpers/product.py
+++ b/website/helpers/product.py
@@ -82,7 +82,7 @@
 
 def get_item_for_list_in_html(r):
 	scrub_item_for_list(r)
-	r.template = "html/product_in_list.html"
+	r.template = "app/website/templates/html/product_in_list.html"
 	return build_html(r)
 
 def scrub_item_for_list(r):
diff --git a/website/templates/css/login.css b/website/templates/css/login.css
deleted file mode 100644
index 4120807..0000000
--- a/website/templates/css/login.css
+++ /dev/null
@@ -1,43 +0,0 @@
-	<style>
-		#login_wrapper {
-			width: 300px;
-			margin: 70px auto;
-		}
-
-		#login_wrapper,
-		#login_wrapper h3 {
-			color: #333;
-		}
-		
-		#login_wrapper a {
-			color: #0088cc;
-		}
-
-		.layout-wrapper {
-			background-color: #fff;
-			padding: 10px;
-			box-shadow: 1px 1px 3px 3px #ccc;
-			font-size: 12px;
-			min-height: 100px;
-			border-radius: 5px;
-		}
-
-		#login_wrapper h3 {
-			text-align: center;
-		}
-
-		.login-banner {
-			margin-bottom: 20px;
-		}
-		
-		.login-box td {
-			padding: 8px;
-		}
-		.login-box td input {
-			margin-bottom: 0px;
-		}
-		.login-footer {
-			text-align: center;
-			padding: 15px;
-		}
-	</style>
\ No newline at end of file
diff --git a/website/templates/html/base.html b/website/templates/html/base.html
deleted file mode 100644
index cfba1a5..0000000
--- a/website/templates/html/base.html
+++ /dev/null
@@ -1,25 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-	<meta charset="utf-8">
-	<meta name="viewport" content="width=device-width, initial-scale=1.0">
-	<title>{{ title }}</title>
-	<meta name="generator" content="wnframework">
-	<script type="text/javascript" src="lib/js/lib/jquery/jquery.min.js"></script>
-	<script type="text/javascript" src="js/all-web.min.js"></script>
-	<script type="text/javascript" src="js/wn-web.js"></script>
-	<link type="text/css" rel="stylesheet" href="css/all-web.css">
-	<link type="text/css" rel="stylesheet" href="css/wn-web.css">
-	<link rel="shortcut icon" href="{{ favicon }}" type="image/x-icon">
-	<link rel="icon" href="{{ favicon }}" type="image/x-icon">
-	{% if description -%}
-	<meta name="description" content="{{ description }}">	
-	{%- endif %}
-	{% block header -%}
-	{%- endblock %}
-</head>
-<body>
-	{% block body %}
-	{% endblock %}
-</body>
-</html>
\ No newline at end of file
diff --git a/website/templates/html/blog_page.html b/website/templates/html/blog_page.html
index 270d427..cf1f00e 100644
--- a/website/templates/html/blog_page.html
+++ b/website/templates/html/blog_page.html
@@ -1,11 +1,11 @@
-{% extends "html/page.html" %}
+{% extends "app/website/templates/html/page.html" %}
 
 {% block javascript %}
-	{% include "js/blog_page.js" %}
+	{% include "app/website/templates/js/blog_page.js" %}
 {% endblock %}
 
 {% block css %}
-	{% include "css/blog_page.css" %}
+	{% include "app/website/templates/css/blog_page.css" %}
 {% endblock %}
 
 {% block content %}
@@ -23,7 +23,7 @@
 	<!-- end blog content -->
 	{% if blogger_info %}
 	<hr />
-	{% include "html/blogger.html" %}
+	{% include "app/website/templates/html/blogger.html" %}
 	{% endif %}
 	<hr>
 	<h3>{{ texts.comments }}</h3><br>
@@ -35,7 +35,7 @@
 		</div>
 		{% endif %}
 		
-		{% include 'html/comment.html' %}
+		{% include 'app/website/templates/html/comment.html' %}
 	</div>
 	<div><button class="btn add-comment">{{ texts.add_comment }}</button></div>
 	<div style="display: none; margin-top: 10px;" 
@@ -52,5 +52,5 @@
 		</form>
 	</div>
 </div>
-{% include 'html/blog_footer.html' %}
+{% include 'app/website/templates/html/blog_footer.html' %}
 {% endblock %}
\ No newline at end of file
diff --git a/website/templates/html/outer.html b/website/templates/html/outer.html
index 624371e..570c769 100644
--- a/website/templates/html/outer.html
+++ b/website/templates/html/outer.html
@@ -1,4 +1,4 @@
-{% extends "html/base.html" %}
+{% extends "lib/templates/base.html" %}
 
 {% block body %}
 	<div class="container">
@@ -10,13 +10,13 @@
 			<div class="span12">{{ banner_html }}</div>
 		</div>{% endif %}
 		<div class="outer">
-			{% include "html/navbar.html" %}
+			{% include "app/website/templates/html/navbar.html" %}
 			<div class="content row" id="page-{{ name }}" style="display: block;">
 			{%- block content -%}
 			{%- endblock -%}
 			</div>
 		</div>
 	</div>
-	{% include "html/footer.html" %}
+	{% include "app/website/templates/html/footer.html" %}
 
 {% endblock %}
\ No newline at end of file
diff --git a/website/templates/html/page.html b/website/templates/html/page.html
index 9d38cdc..c9fbec4 100644
--- a/website/templates/html/page.html
+++ b/website/templates/html/page.html
@@ -1,4 +1,4 @@
-{% extends "html/outer.html" %}
+{% extends "app/website/templates/html/outer.html" %}
 
 {% block title -%}{{ title }}{%- endblock %}
 
diff --git a/website/templates/html/product_group.html b/website/templates/html/product_group.html
index 510f994..b3c8511 100644
--- a/website/templates/html/product_group.html
+++ b/website/templates/html/product_group.html
@@ -1,11 +1,11 @@
-{% extends "html/page.html" %}
+{% extends "app/website/templates/html/page.html" %}
 
 {% block content %}
-{% include 'html/product_search_box.html' %}
-{% include 'html/product_breadcrumbs.html' %}
+{% include 'app/website/templates/html/product_search_box.html' %}
+{% include 'app/website/templates/html/product_breadcrumbs.html' %}
 <div class="span12">
 	{% if slideshow %}<!-- slideshow -->
-	{% include "html/slideshow.html" %}
+	{% include "app/website/templates/html/slideshow.html" %}
 	{% endif %}
 	{% if description %}<!-- description -->
 	<div>{{ description or ""}}</div>
diff --git a/website/templates/html/product_in_list.html b/website/templates/html/product_in_list.html
index bc62607..5cd9eac 100644
--- a/website/templates/html/product_in_list.html
+++ b/website/templates/html/product_in_list.html
@@ -4,7 +4,7 @@
 		{%- if website_image -%}
 		<img class="product-image" style="width: 80%; margin: auto;" src="{{ website_image }}">
 		{%- else -%}
-		{% include 'html/product_missing_image.html' %}
+		{% include 'app/website/templates/html/product_missing_image.html' %}
 		{%- endif -%}
 		</a>
 	</div>
diff --git a/website/templates/html/product_page.html b/website/templates/html/product_page.html
index f897a31..23091ad 100644
--- a/website/templates/html/product_page.html
+++ b/website/templates/html/product_page.html
@@ -1,28 +1,28 @@
-{% extends "html/page.html" %}
+{% extends "app/website/templates/html/page.html" %}
 
 {% block javascript %}
-	{% include "js/product_page.js" %}
+	{% include "app/website/templates/js/product_page.js" %}
 {% endblock %}
 
 {% block css %}
-	{% include "css/product_page.css" %}
+	{% include "app/website/templates/css/product_page.css" %}
 {% endblock %}
 
 {% block content %}
-	{% include 'html/product_search_box.html' %}
-	{% include 'html/product_breadcrumbs.html' %}
+	{% include 'app/website/templates/html/product_search_box.html' %}
+	{% include 'app/website/templates/html/product_breadcrumbs.html' %}
 	<div class="span12 product-page-content" itemscope itemtype="http://schema.org/Product">
 		<div class="row">
 			<div class="span6">
 				{% if slideshow %}
-					{% include "html/slideshow.html" %}
+					{% include "app/website/templates/html/slideshow.html" %}
 				{% else %}
 					{% if website_image %}
 					<image itemprop="image" class="item-main-image"
 						src="{{ website_image }}" />
 					{% else %}
 					<div class="img-area">
-						{% include 'html/product_missing_image.html' %}
+						{% include 'app/website/templates/html/product_missing_image.html' %}
 					</div>
 					{% endif %}
 				{% endif %}
diff --git a/website/templates/html/web_page.html b/website/templates/html/web_page.html
index d3c646a..6b8c914 100644
--- a/website/templates/html/web_page.html
+++ b/website/templates/html/web_page.html
@@ -1,4 +1,4 @@
-{% extends "html/page.html" %}
+{% extends "app/website/templates/html/page.html" %}
 
 {% block javascript %}
 	{% if insert_code %}
@@ -8,7 +8,7 @@
 
 {% block content %}
 <div class="span12" style="margin-top: 15px;">
-	{% include "html/slideshow.html" %}
+	{% include "app/website/templates/html/slideshow.html" %}
 	{{ main_section }}
 </div>
 {% endblock %}
\ No newline at end of file
diff --git a/website/templates/js/login.js b/website/templates/js/login.js
deleted file mode 100644
index 06ea4c5..0000000
--- a/website/templates/js/login.js
+++ /dev/null
@@ -1,97 +0,0 @@
-
-var login = {};
-
-$(document).ready(function(wrapper) {
-	$('#login_btn').click(login.do_login)
-		
-	$('#password').keypress(function(ev){
-		if(ev.which==13 && $('#password').val()) {
-			$('form').submit(function() {
-				login.do_login();
-				return false;
-			});
-		}
-	});
-	$(document).trigger('login_rendered');
-})
-
-// Login
-login.do_login = function(){
-    var args = {};
-	if(window.is_sign_up) {
-		args.cmd = "core.doctype.profile.profile.sign_up";
-		args.email = $("#login_id").val();
-	    args.full_name = $("#full_name").val();
-
-		if(!args.email || !valid_email(args.email) || !args.full_name) {
-			login.set_message("Valid email and name required.");
-			return false;
-		}
-	} else if(window.is_forgot) {
-		args.cmd = "reset_password";
-		args.user = $("#login_id").val();
-		
-		if(!args.user) {
-			login.set_message("Valid Login Id required.");
-			return false;
-		}
-
-	} else {
-		args.cmd = "login"
-	    args.usr = $("#login_id").val();
-	    args.pwd = $("#password").val();
-
-		if(!args.usr || !args.pwd) {
-			login.set_message("Both login and password required.");
-			return false;
-		}	
-	}
-
-	$('#login_btn').attr("disabled", "disabled");
-	$("#login-spinner").toggle(true);
-	$('#login_message').toggle(false);
-	
-	$.ajax({
-		type: "POST",
-		url: "server.py",
-		data: args,
-		dataType: "json",
-		success: function(data) {
-			$("input").val("");
-			$("#login-spinner").toggle(false);
-			$('#login_btn').attr("disabled", false);
-			if(data.message=="Logged In") {
-				window.location.href = "app.html";
-			} else if(data.message=="No App") {
-				window.location.href = "index";
-			} else {
-				login.set_message(data.message);
-			}
-		}
-	})
-	
-	return false;
-}
-
-login.sign_up = function() {
-	$("#login_wrapper h3").html("Sign Up");
-	$("#login-label").html("Email Id");
-	$("#password-row, #sign-up-wrapper, #login_message").toggle(false);
-	$("#full-name-row").toggle(true);
-	$("#login_btn").html("Register");
-	$("#forgot-wrapper").html("<a onclick='location.reload()' href='#'>Login</a>")
-	window.is_sign_up = true;
-}
-
-login.show_forgot_password = function() {
-	$("#login_wrapper h3").html("Forgot");
-	$("#login-label").html("Email Id");
-	$("#password-row, #sign-up-wrapper, #login_message").toggle(false);
-	$("#login_btn").html("Send Password");
-	$("#forgot-wrapper").html("<a onclick='location.reload()' href='#'>Login</a>")
-	window.is_forgot = true;
-}
-
-login.set_message = function(message, color) {
-    $('#login_message').html(message).toggle(true);	
-}
\ No newline at end of file
diff --git a/website/templates/pages/404.html b/website/templates/pages/404.html
deleted file mode 100644
index 8a676ce..0000000
--- a/website/templates/pages/404.html
+++ /dev/null
@@ -1,14 +0,0 @@
-{% extends "html/outer.html" %}
-
-{% set title="Not Found" %}
-
-{% block content %}
-<div class="content">
-	<div class="layout-wrapper layout-main">
-		<h3><i class="icon-exclamation-sign"></i> Page missing or moved</h3>
-		<br>
-		<p>We are very sorry for this, but the page you are looking for is missing
-			(this could be because of a typo in the address) or moved.</p>
-	</div>
-</div>
-{% endblock %}
\ No newline at end of file
diff --git a/website/templates/pages/about.html b/website/templates/pages/about.html
index 380c543..0cbd562 100644
--- a/website/templates/pages/about.html
+++ b/website/templates/pages/about.html
@@ -1,4 +1,4 @@
-{% extends "html/page.html" %}
+{% extends "app/website/templates/html/page.html" %}
 
 {% set title="About Us" %}
 
diff --git a/website/templates/pages/account.html b/website/templates/pages/account.html
index 8e8f4b4..fe2b858 100644
--- a/website/templates/pages/account.html
+++ b/website/templates/pages/account.html
@@ -1,4 +1,4 @@
-{% extends "html/page.html" %}
+{% extends "app/website/templates/html/page.html" %}
 
 {% set title="My Account" %}
 
diff --git a/website/templates/pages/attributions.html b/website/templates/pages/attributions.html
index 9e4b50d..05e8e88 100644
--- a/website/templates/pages/attributions.html
+++ b/website/templates/pages/attributions.html
@@ -1,4 +1,4 @@
-{% extends "html/outer.html" %}
+{% extends "app/website/templates/html/outer.html" %}
 
 {% block header %}
 <style>
diff --git a/website/templates/pages/blog.html b/website/templates/pages/blog.html
index df258e1..7483c7c 100644
--- a/website/templates/pages/blog.html
+++ b/website/templates/pages/blog.html
@@ -1,11 +1,11 @@
-{% extends "html/page.html" %}
+{% extends "app/website/templates/html/page.html" %}
 
 {% block javascript %}
-	{% include "js/blog.js" %}
+	{% include "app/website/templates/js/blog.js" %}
 {% endblock %}
 
 {% block css %}
-	{% include "css/blog.css" %}
+	{% include "app/website/templates/css/blog.css" %}
 {% endblock %}
 
 {% set title="Blog" %}
@@ -29,5 +29,5 @@
 			style="display:none;">More...</button>
 	</div>
 </div>
-{% include 'html/blog_footer.html' %}
+{% include 'app/website/templates/html/blog_footer.html' %}
 {% endblock %}
\ No newline at end of file
diff --git a/website/templates/pages/contact.html b/website/templates/pages/contact.html
index 79bcb04..b9b3cd7 100644
--- a/website/templates/pages/contact.html
+++ b/website/templates/pages/contact.html
@@ -1,7 +1,7 @@
-{% extends "html/page.html" %}
+{% extends "app/website/templates/html/page.html" %}
 
 {% block javascript %}
-	{% include "js/contact.js" %}
+	{% include "app/website/templates/js/contact.js" %}
 {% endblock %}
 
 {% set title="Contact Us" %}
diff --git a/website/templates/pages/error.html b/website/templates/pages/error.html
deleted file mode 100644
index 2be810d..0000000
--- a/website/templates/pages/error.html
+++ /dev/null
@@ -1,13 +0,0 @@
-{% extends "html/outer.html" %}
-
-{% set title="Error" %}
-
-{% block content %}
-<div class="content">
-	<div class="layout-wrapper layout-main">
-		<h3><i class="icon-exclamation-sign"></i> Oops, a server error has occured</h3>
-		<br>
-		<pre>%(error)s</pre>
-	</div>
-</div>
-{% endblock %}
\ No newline at end of file
diff --git a/website/templates/pages/index.html b/website/templates/pages/index.html
index 1307872..761da0c 100644
--- a/website/templates/pages/index.html
+++ b/website/templates/pages/index.html
@@ -1 +1 @@
-{% extends "html/web_page.html" %}
\ No newline at end of file
+{% extends "app/website/templates/html/web_page.html" %}
\ No newline at end of file
diff --git a/website/templates/pages/login.html b/website/templates/pages/login.html
deleted file mode 100644
index 6b847ff..0000000
--- a/website/templates/pages/login.html
+++ /dev/null
@@ -1,62 +0,0 @@
-{% extends "html/base.html" %}
-
-{% block header %}
-	<script>
-		{% include "js/login.js" %}
-	</script>
-	{% include "css/login.css" %}
-{% endblock %}
-
-{% set title="Login" %}
-
-{% block body %}
-	<div class="container" id='login_wrapper'>
-		<div class='layout-wrapper layout-main'>
-			<p id="login_message" class="alert" style="display: none;"></p>
-			<h3><i class="icon-lock" style="margin-top: 7px"></i> Login</h3>
-			<form autocomplete="on">
-				<table border="0" class="login-box">
-					<tbody>
-						<tr>
-							<td style="text-align: right; padding: 3px;" 
-								id="login-label">Login Id</td>
-							<td><input id="login_id" type="text" style="width: 180px"/></td>
-						</tr>
-						<tr id="password-row">
-							<td style="text-align: right; padding: 3px;" >Password</td>
-							<td><input id="password" type="password" style="width: 180px" /></td>
-						</tr>
-						<tr id="full-name-row" style="display: none;">
-							<td style="text-align: right; padding: 3px;">Full Name</td>
-							<td><input id="full_name" type="text" style="width: 180px" /></td>
-						</tr>
-						<tr>
-							<td>&nbsp;</td>
-							<td>
-								<button type="submit" id="login_btn" 
-									class="btn btn-small btn-primary">Login</button>
-								<img src="lib/images/ui/button-load.gif" id="login-spinner" 
-									style="display: none;">
-							</td>
-						</tr>
-						</tbody>
-				</table>
-			</form>
-			<br>
-			<p style="text-align: center" id="forgot-wrapper">
-				<a id="forgot-password" style="cursor:pointer"
-				onclick="return login.show_forgot_password()">Forgot Password</a></p>
-			<p style="text-align: center" id="sign-up-wrapper">
-				New user? <a id="sign-up" style="cursor:pointer"
-				onclick="return login.sign_up()">Sign Up</a></p>
-		</div>
-	</div>
-	<div class="web-footer login-footer container">
-		<a href="index.html">Home</a> | 
-			<a href="https://erpnext.com">ERPNext</a><br><br>
-			{% if copyright %}
-			<div class="web-footer-copyright">&copy; {{ copyright }}
-			{% endif %}
-	</div>
-
-{% endblock %}
\ No newline at end of file
diff --git a/website/templates/pages/message.html b/website/templates/pages/message.html
deleted file mode 100644
index ea9e14e..0000000
--- a/website/templates/pages/message.html
+++ /dev/null
@@ -1,11 +0,0 @@
-{% extends "html/outer.html" %}
-
-{% set title=webnotes.message_title %}
-
-{% block content %}
-<div class="content">
-	<div class="layout-wrapper layout-main">
-		{{ webnotes.message }}
-	</div>
-</div>
-{% endblock %}
\ No newline at end of file
diff --git a/website/templates/pages/order.html b/website/templates/pages/order.html
index 9e80694..8e7bfe7 100644
--- a/website/templates/pages/order.html
+++ b/website/templates/pages/order.html
@@ -1,4 +1,4 @@
-{% extends "html/page.html" %}
+{% extends "app/website/templates/html/page.html" %}
 
 {% set title=doc.name %}
 
diff --git a/website/templates/pages/orders.html b/website/templates/pages/orders.html
index 3bb7bd4..0c93a68 100644
--- a/website/templates/pages/orders.html
+++ b/website/templates/pages/orders.html
@@ -1,4 +1,4 @@
-{% extends "html/page.html" %}
+{% extends "app/website/templates/html/page.html" %}
 
 {% set title="My Orders" %}
 
diff --git a/website/templates/pages/print.html b/website/templates/pages/print.html
deleted file mode 100644
index b684dfe..0000000
--- a/website/templates/pages/print.html
+++ /dev/null
@@ -1,18 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-	<meta charset="utf-8">
-	<meta name="viewport" content="width=device-width, initial-scale=1.0">
-	<title>Print Format</title>
-	<meta name="generator" content="wnframework">
-	<style>
-	{{ css }}
-	</style>
-</head>
-<body>
-	{{ body }}
-</body>
-{%- if comment -%}
-<!-- {{ comment }} -->
-{%- endif -%}
-</html>
\ No newline at end of file
diff --git a/website/templates/pages/product_search.html b/website/templates/pages/product_search.html
index 66bf160..2dab6ff 100644
--- a/website/templates/pages/product_search.html
+++ b/website/templates/pages/product_search.html
@@ -1,9 +1,9 @@
-{% extends "html/page.html" %}
+{% extends "app/website/templates/html/page.html" %}
 
 {% set title="Product Search" %}
 
 {% block javascript %}
-{% include "js/product_list.js" %}
+{% include "app/website/templates/js/product_list.js" %}
 {% endblock %}
 
 {% block content %}
@@ -17,7 +17,7 @@
 });
 </script>
 
-{% include 'html/product_search_box.html' %}
+{% include 'app/website/templates/html/product_search_box.html' %}
 <div class="span12">
 	<h3 class="search-results">Search Results</h3>
 	<div id="search-list" class="row">
diff --git a/website/templates/pages/profile.html b/website/templates/pages/profile.html
index 1b9350c..d689cfb 100644
--- a/website/templates/pages/profile.html
+++ b/website/templates/pages/profile.html
@@ -1,4 +1,4 @@
-{% extends "html/page.html" %}
+{% extends "app/website/templates/html/page.html" %}
 
 {% set title="My Profile" %}
 
diff --git a/website/templates/pages/ticket.html b/website/templates/pages/ticket.html
index fe185f8..858dd3b 100644
--- a/website/templates/pages/ticket.html
+++ b/website/templates/pages/ticket.html
@@ -1,4 +1,4 @@
-{% extends "html/page.html" %}
+{% extends "app/website/templates/html/page.html" %}
 
 {% set title=doc.name %}
 
diff --git a/website/templates/pages/tickets.html b/website/templates/pages/tickets.html
index 11da329..843d10e 100644
--- a/website/templates/pages/tickets.html
+++ b/website/templates/pages/tickets.html
@@ -1,4 +1,4 @@
-{% extends "html/page.html" %}
+{% extends "app/website/templates/html/page.html" %}
 
 {% set title="My Tickets" %}
 
diff --git a/website/templates/pages/writers.html b/website/templates/pages/writers.html
index bba3749..67c0b7e 100644
--- a/website/templates/pages/writers.html
+++ b/website/templates/pages/writers.html
@@ -1,4 +1,4 @@
-{% extends "html/page.html" %}
+{% extends "app/website/templates/html/page.html" %}
 
 {% set title="Blog Writers" %}
 
@@ -10,8 +10,8 @@
 	{% endif %}
 	<hr>
 	{% for blogger_info in bloggers %}
-	{% include "html/blogger.html" %}	
+	{% include "app/website/templates/html/blogger.html" %}	
 	{% endfor %}
 </div>
-{% include 'html/blog_footer.html' %}
+{% include 'app/website/templates/html/blog_footer.html' %}
 {% endblock %}
\ No newline at end of file