Merge branch 'pos_fetch'
diff --git a/accounts/page/accounts_home/accounts_home.js b/accounts/page/accounts_home/accounts_home.js
index 6a9f91a..d2b0a0e 100644
--- a/accounts/page/accounts_home/accounts_home.js
+++ b/accounts/page/accounts_home/accounts_home.js
@@ -188,6 +188,11 @@
 		icon: "icon-list",
 		items: [
 			{
+				"label":wn._("Bank Reconciliation Statement"),
+				route: "query-report/Bank Reconciliation Statement",
+				doctype: "Journal Voucher"
+			},
+			{
 				"label":wn._("Delivered Items To Be Billed"),
 				route: "query-report/Delivered Items To Be Billed",
 				doctype: "Sales Invoice"
@@ -197,6 +202,21 @@
 				route: "query-report/Ordered Items To Be Billed",
 				doctype: "Sales Invoice"
 			},
+			{
+				"label":wn._("Bank Clearance Summary"),
+				route: "query-report/Bank Clearance Summary",
+				doctype: "Journal Voucher"
+			},
+			{
+				"label":wn._("Payment Collection With Ageing"),
+				route: "query-report/Payment Collection With Ageing",
+				doctype: "Journal Voucher"
+			},
+			{
+				"label":wn._("Payment Made With Ageing"),
+				route: "query-report/Payment Made With Ageing",
+				doctype: "Journal Voucher"
+			},
 		]
 	}
 ]
diff --git a/accounts/report/accounts_payable/accounts_payable.py b/accounts/report/accounts_payable/accounts_payable.py
index a10dc7e..71aeb35 100644
--- a/accounts/report/accounts_payable/accounts_payable.py
+++ b/accounts/report/accounts_payable/accounts_payable.py
@@ -1,6 +1,8 @@
 from __future__ import unicode_literals
 import webnotes
 from webnotes.utils import getdate, nowdate, flt, cstr
+from webnotes import msgprint, _
+from accounts.report.accounts_receivable.accounts_receivable import get_ageing_data
 
 def execute(filters=None):
 	if not filters: filters = {}
@@ -67,8 +69,7 @@
 	gl_entries = []
 	gl_entries = webnotes.conn.sql("""select * from `tabGL Entry` 
 		where ifnull(is_cancelled, 'No') = 'No' %s order by posting_date, account""" % 
-		(conditions) % (", ".join(['%s']*len(supplier_accounts))), 
-		tuple(supplier_accounts), as_dict=1)
+		(conditions), tuple(supplier_accounts), as_dict=1)
 	return gl_entries
 	
 def get_conditions(filters, before_report_date=True):
@@ -79,13 +80,16 @@
 	supplier_accounts = []
 	if filters.get("account"):
 		supplier_accounts = [filters["account"]]
-	elif filters.get("company"):
+	else:
 		supplier_accounts = webnotes.conn.sql_list("""select name from `tabAccount` 
 			where ifnull(master_type, '') = 'Supplier' and docstatus < 2 %s""" % 
 			conditions, filters)
 	
 	if supplier_accounts:
-		conditions += " and account in (%s)"
+		conditions += " and account in (%s)" % (", ".join(['%s']*len(supplier_accounts)))
+	else:
+		msgprint(_("No Supplier Accounts found. Supplier Accounts are identified based on \
+			'Master Type' value in account record."), raise_exception=1)
 		
 	if filters.get("report_date"):
 		if before_report_date:
@@ -125,20 +129,4 @@
 			and against_voucher = %s and name != %s and ifnull(is_cancelled, 'No') = 'No'""", 
 			(gle.account, report_date, gle.voucher_type, gle.voucher_no, gle.name))[0][0]
 	
-	return flt(paid_amount)
-
-def get_ageing_data(ageing_based_on_date, age_on, outstanding_amount):
-	val1 = val2 = val3 = val4 = diff = 0
-	diff = age_on and ageing_based_on_date \
-		and (getdate(age_on) - getdate(ageing_based_on_date)).days or 0
-
-	if diff <= 30:
-		val1 = outstanding_amount
-	elif 30 < diff <= 60:
-		val2 = outstanding_amount
-	elif 60 < diff <= 90:
-		val3 = outstanding_amount
-	elif diff > 90:
-		val4 = outstanding_amount
-		
-	return [diff, val1, val2, val3, val4]
\ No newline at end of file
+	return flt(paid_amount)
\ No newline at end of file
diff --git a/accounts/report/accounts_receivable/accounts_receivable.py b/accounts/report/accounts_receivable/accounts_receivable.py
index a8c6d23..d791fad 100644
--- a/accounts/report/accounts_receivable/accounts_receivable.py
+++ b/accounts/report/accounts_receivable/accounts_receivable.py
@@ -1,5 +1,6 @@
 from __future__ import unicode_literals
 import webnotes
+from webnotes import msgprint, _
 from webnotes.utils import getdate, nowdate, flt, cstr
 
 def execute(filters=None):
@@ -58,8 +59,7 @@
 	conditions, customer_accounts = get_conditions(filters, upto_report_date)
 	return webnotes.conn.sql("""select * from `tabGL Entry` 
 		where ifnull(is_cancelled, 'No') = 'No' %s order by posting_date, account""" % 
-		(conditions) % (", ".join(['%s']*len(customer_accounts))), 
-		tuple(customer_accounts), as_dict=1)
+		(conditions), tuple(customer_accounts), as_dict=1)
 	
 def get_conditions(filters, upto_report_date=True):
 	conditions = ""
@@ -69,13 +69,16 @@
 	customer_accounts = []
 	if filters.get("account"):
 		customer_accounts = [filters["account"]]
-	elif filters.get("company"):
+	else:
 		customer_accounts = webnotes.conn.sql_list("""select name from `tabAccount` 
 			where ifnull(master_type, '') = 'Customer' and docstatus < 2 %s""" % 
 			conditions, filters)
 	
 	if customer_accounts:
-		conditions += " and account in (%s)"
+		conditions += " and account in (%s)" % (", ".join(['%s']*len(customer_accounts)))
+	else:
+		msgprint(_("No Customer Accounts found. Customer Accounts are identified based on \
+			'Master Type' value in account record."), raise_exception=1)
 		
 	if filters.get("report_date"):
 		if upto_report_date:
@@ -96,7 +99,7 @@
 def get_si_due_date_map():
 	""" get due_date from sales invoice """
 	si_due_date_map = {}
-	for t in webnotes.conn.sql("""select name, due_date from `tabSales Invoice` group by name"""):
+	for t in webnotes.conn.sql("""select name, due_date from `tabSales Invoice`"""):
 		si_due_date_map[t[0]] = t[1]
 		
 	return si_due_date_map
diff --git a/accounts/report/bank_clearance_summary/__init__.py b/accounts/report/bank_clearance_summary/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/accounts/report/bank_clearance_summary/__init__.py
diff --git a/accounts/report/bank_clearance_summary/bank_clearance_summary.js b/accounts/report/bank_clearance_summary/bank_clearance_summary.js
new file mode 100644
index 0000000..76adfd3
--- /dev/null
+++ b/accounts/report/bank_clearance_summary/bank_clearance_summary.js
@@ -0,0 +1,32 @@
+wn.query_reports["Bank Clearance Summary"] = {
+	"filters": [
+		{
+			"fieldname":"from_date",
+			"label": "From Date",
+			"fieldtype": "Date",
+			"default": wn.defaults.get_user_default("year_start_date"),
+			"width": "80"
+		},
+		{
+			"fieldname":"to_date",
+			"label": "To Date",
+			"fieldtype": "Date",
+			"default": get_today()
+		},
+		{
+			"fieldname":"account",
+			"label": "Bank Account",
+			"fieldtype": "Link",
+			"options": "Account",
+			"get_query": function() {
+				return {
+					"query": "accounts.utils.get_account_list", 
+					"filters": {
+						"is_pl_account": "No",
+						"account_type": "Bank or Cash"
+					}
+				}
+			}
+		},
+	]
+}
\ No newline at end of file
diff --git a/accounts/report/bank_clearance_summary/bank_clearance_summary.py b/accounts/report/bank_clearance_summary/bank_clearance_summary.py
new file mode 100644
index 0000000..49ac1a4
--- /dev/null
+++ b/accounts/report/bank_clearance_summary/bank_clearance_summary.py
@@ -0,0 +1,54 @@
+# 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 import _, msgprint
+
+def execute(filters=None):
+	if not filters: filters = {}
+	
+	columns = get_columns()
+	data = get_entries(filters)
+	
+	return columns, data
+	
+def get_columns():
+	return ["Journal Voucher:Link/Journal Voucher:140", "Account:Link/Account:140", 
+		"Posting Date:Date:100", "Clearance Date:Date:110", "Against Account:Link/Account:200", 
+		"Debit:Currency:120", "Credit:Currency:120"
+	]
+
+def get_conditions(filters):
+	conditions = ""
+	if not filters.get("account"):
+		msgprint(_("Please select Bank Account"), raise_exception=1)
+	else:
+		conditions += " and jvd.account = %(account)s"
+		
+	if filters.get("from_date"): conditions += " and jv.posting_date>=%(from_date)s"
+	if filters.get("to_date"): conditions += " and jv.posting_date<=%(to_date)s"
+	
+	return conditions
+	
+def get_entries(filters):
+	conditions = get_conditions(filters)
+	entries =  webnotes.conn.sql("""select jv.name, jvd.account, jv.posting_date, 
+		jv.clearance_date, jvd.against_account, jvd.debit, jvd.credit
+		from `tabJournal Voucher Detail` jvd, `tabJournal Voucher` jv 
+		where jvd.parent = jv.name and jv.docstatus=1 %s
+		order by jv.name DESC""" % conditions, filters, as_list=1)
+	return entries
\ No newline at end of file
diff --git a/accounts/report/bank_clearance_summary/bank_clearance_summary.txt b/accounts/report/bank_clearance_summary/bank_clearance_summary.txt
new file mode 100644
index 0000000..3dd2079
--- /dev/null
+++ b/accounts/report/bank_clearance_summary/bank_clearance_summary.txt
@@ -0,0 +1,21 @@
+[
+ {
+  "creation": "2013-05-01 12:13:25", 
+  "docstatus": 0, 
+  "modified": "2013-05-01 12:13:25", 
+  "modified_by": "Administrator", 
+  "owner": "Administrator"
+ }, 
+ {
+  "doctype": "Report", 
+  "is_standard": "Yes", 
+  "name": "__common__", 
+  "ref_doctype": "Journal Voucher", 
+  "report_name": "Bank Clearance Summary", 
+  "report_type": "Script Report"
+ }, 
+ {
+  "doctype": "Report", 
+  "name": "Bank Clearance Summary"
+ }
+]
\ No newline at end of file
diff --git a/accounts/report/bank_reconciliation_statement/__init__.py b/accounts/report/bank_reconciliation_statement/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/accounts/report/bank_reconciliation_statement/__init__.py
diff --git a/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.js b/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.js
new file mode 100644
index 0000000..28ac920
--- /dev/null
+++ b/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.js
@@ -0,0 +1,25 @@
+wn.query_reports["Bank Reconciliation Statement"] = {
+	"filters": [
+		{
+			"fieldname":"account",
+			"label": "Bank Account",
+			"fieldtype": "Link",
+			"options": "Account",
+			"get_query": function() {
+				return {
+					"query": "accounts.utils.get_account_list", 
+					"filters": {
+						"is_pl_account": "No",
+						"account_type": "Bank or Cash"
+					}
+				}
+			}
+		},
+		{
+			"fieldname":"report_date",
+			"label": "Date",
+			"fieldtype": "Date",
+			"default": get_today()
+		},
+	]
+}
\ No newline at end of file
diff --git a/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py b/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py
new file mode 100644
index 0000000..1345cd8
--- /dev/null
+++ b/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py
@@ -0,0 +1,79 @@
+# 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 import _, msgprint
+from webnotes.utils import flt
+
+def execute(filters=None):
+	if not filters: filters = {}
+		
+	columns = get_columns()	
+	data = get_entries(filters)
+	
+	from accounts.utils import get_balance_on
+	balance_as_per_company = get_balance_on(filters["account"], filters["report_date"])
+
+	total_debit, total_credit = 0,0
+	for d in data:
+		total_debit += flt(d[4])
+		total_credit += flt(d[5])
+
+	if webnotes.conn.get_value("Account", filters["account"], "debit_or_credit") == 'Debit':
+		bank_bal = flt(balance_as_per_company) - flt(total_debit) + flt(total_credit)
+	else:
+		bank_bal = flt(balance_as_per_company) + flt(total_debit) - flt(total_credit)
+		
+	data += [
+		["", "", "", "Balance as per company books", balance_as_per_company, ""], 
+		["", "", "", "Amounts not reflected in bank", total_debit, total_credit], 
+		["", "", "", "Balance as per bank", bank_bal, ""]
+	]
+			
+	return columns, data
+	
+	
+def get_columns():
+	return ["Journal Voucher:Link/Journal Voucher:140", "Posting Date:Date:100", 
+		"Clearance Date:Date:110", "Against Account:Link/Account:200", 
+		"Debit:Currency:120", "Credit:Currency:120"
+	]
+
+def get_conditions(filters):
+	conditions = ""
+	if not filters.get("account"):
+		msgprint(_("Please select Bank Account"), raise_exception=1)
+	else:
+		conditions += " and jvd.account = %(account)s"
+		
+	if not filters.get("report_date"):
+		msgprint(_("Please select Date on which you want to run the report"), raise_exception=1)
+	else:
+		conditions += """ and jv.posting_date <= %(report_date)s 
+			and ifnull(jv.clearance_date, '4000-01-01') > %(report_date)s"""
+
+	return conditions
+	
+def get_entries(filters):
+	conditions = get_conditions(filters)
+	entries = webnotes.conn.sql("""select jv.name, jv.posting_date, jv.clearance_date, 
+		jvd.against_account, jvd.debit, jvd.credit
+		from `tabJournal Voucher Detail` jvd, `tabJournal Voucher` jv 
+		where jvd.parent = jv.name and jv.docstatus=1 and ifnull(jv.cheque_no, '')!= '' %s
+		order by jv.name DESC""" % conditions, filters, as_list=1)
+		
+	return entries
\ No newline at end of file
diff --git a/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.txt b/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.txt
new file mode 100644
index 0000000..9867c5d
--- /dev/null
+++ b/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.txt
@@ -0,0 +1,22 @@
+[
+ {
+  "creation": "2013-04-30 18:30:21", 
+  "docstatus": 0, 
+  "modified": "2013-05-01 10:53:12", 
+  "modified_by": "Administrator", 
+  "owner": "Administrator"
+ }, 
+ {
+  "add_total_row": 0, 
+  "doctype": "Report", 
+  "is_standard": "Yes", 
+  "name": "__common__", 
+  "ref_doctype": "Journal Voucher", 
+  "report_name": "Bank Reconciliation Statement", 
+  "report_type": "Script Report"
+ }, 
+ {
+  "doctype": "Report", 
+  "name": "Bank Reconciliation Statement"
+ }
+]
\ No newline at end of file
diff --git a/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.txt b/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.txt
index c84854f..e84c597 100644
--- a/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.txt
+++ b/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-02-22 17:55:23", 
+  "creation": "2013-02-25 10:38:57", 
   "docstatus": 0, 
-  "modified": "2013-02-23 14:35:28", 
+  "modified": "2013-05-01 11:56:43", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
diff --git a/accounts/report/payment_collection_with_ageing/__init__.py b/accounts/report/payment_collection_with_ageing/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/accounts/report/payment_collection_with_ageing/__init__.py
diff --git a/accounts/report/payment_collection_with_ageing/payment_collection_with_ageing.js b/accounts/report/payment_collection_with_ageing/payment_collection_with_ageing.js
new file mode 100644
index 0000000..d608fbd
--- /dev/null
+++ b/accounts/report/payment_collection_with_ageing/payment_collection_with_ageing.js
@@ -0,0 +1,42 @@
+wn.query_reports["Payment Collection With Ageing"] = {
+	"filters": [
+		{
+			"fieldname": "from_date",
+			"label": "From Date",
+			"fieldtype": "Date",
+			"default": wn.defaults.get_user_default("year_start_date"),
+			"width": "80"
+		},
+		{
+			"fieldname":"to_date",
+			"label": "To Date",
+			"fieldtype": "Date",
+			"default": get_today()
+		},
+		{
+			"fieldname":"account",
+			"label": "Customer Account",
+			"fieldtype": "Link",
+			"options": "Account",
+			"get_query": function() {
+				var company = wn.query_report.filters_by_name.company.get_value();
+				return {
+					"query": "accounts.utils.get_account_list", 
+					"filters": {
+						"is_pl_account": "No",
+						"debit_or_credit": "Debit",
+						"company": company,
+						"master_type": "Customer"
+					}
+				}
+			}
+		},
+		{
+			"fieldname":"company",
+			"label": "Company",
+			"fieldtype": "Link",
+			"options": "Company",
+			"default": sys_defaults.company
+		},
+	]
+}
\ No newline at end of file
diff --git a/accounts/report/payment_collection_with_ageing/payment_collection_with_ageing.py b/accounts/report/payment_collection_with_ageing/payment_collection_with_ageing.py
new file mode 100644
index 0000000..1268852
--- /dev/null
+++ b/accounts/report/payment_collection_with_ageing/payment_collection_with_ageing.py
@@ -0,0 +1,90 @@
+# 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 import msgprint, _
+from accounts.report.accounts_receivable.accounts_receivable import get_ageing_data
+
+def execute(filters=None):
+	if not filters: filters = {}
+	
+	columns = get_columns()
+	entries = get_entries(filters)
+	si_posting_date_map = get_si_posting_date_map()
+	
+	data = []
+	for d in entries:
+		against_invoice_date = d.against_invoice and si_posting_date_map[d.against_invoice] or ""
+		
+		row = [d.name, d.account, d.posting_date, d.against_invoice, against_invoice_date, 
+			d.debit, d.credit, d.cheque_no, d.cheque_date, d.remark]
+			
+		if d.against_invoice:
+			row += get_ageing_data(against_invoice_date, d.posting_date, d.credit or -1*d.debit)
+		else:
+			row += ["", "", "", "", ""]
+			
+		data.append(row)
+	
+	return columns, data
+	
+def get_columns():
+	return ["Journal Voucher:Link/Journal Voucher:140", "Account:Link/Account:140", 
+		"Posting Date:Date:100", "Against Invoice:Link/Sales Invoice:130", 
+		"Against Invoice Posting Date:Date:130", "Debit:Currency:120", "Credit:Currency:120", 
+		"Reference No::100", "Reference Date:Date:100", "Remarks::150", "Age:Int:40", 
+		"0-30:Currency:100", "30-60:Currency:100", "60-90:Currency:100", "90-Above:Currency:100"
+	]
+
+def get_conditions(filters):
+	conditions = ""
+	
+	customer_accounts = []
+	if filters.get("account"):
+		customer_accounts = [filters["account"]]
+	else:
+		cond = filters.get("company") and (" and company = '%s'" % filters["company"]) or ""
+		customer_accounts = webnotes.conn.sql_list("""select name from `tabAccount` 
+			where ifnull(master_type, '') = 'Customer' and docstatus < 2 %s""" % cond)
+	
+	if customer_accounts:
+		conditions += " and jvd.account in (%s)" % (", ".join(['%s']*len(customer_accounts)))
+	else:
+		msgprint(_("No Customer Accounts found. Customer Accounts are identified based on \
+			'Master Type' value in account record."), raise_exception=1)
+		
+	if filters.get("from_date"): conditions += " and jv.posting_date >= '%s'" % filters["from_date"]
+	if filters.get("to_date"): conditions += " and jv.posting_date <= '%s'" % filters["to_date"]
+	
+	return conditions, customer_accounts
+	
+def get_entries(filters):
+	conditions, customer_accounts = get_conditions(filters)
+	entries =  webnotes.conn.sql("""select jv.name, jvd.account, jv.posting_date, 
+		jvd.against_invoice, jvd.debit, jvd.credit, jv.cheque_no, jv.cheque_date, jv.remark
+		from `tabJournal Voucher Detail` jvd, `tabJournal Voucher` jv 
+		where jvd.parent = jv.name and jv.docstatus=1 %s order by jv.name DESC""" % 
+		(conditions), tuple(customer_accounts), as_dict=1)
+		
+	return entries
+	
+def get_si_posting_date_map():
+	si_posting_date_map = {}
+	for t in webnotes.conn.sql("""select name, posting_date from `tabSales Invoice`"""):
+		si_posting_date_map[t[0]] = t[1]
+		
+	return si_posting_date_map
\ No newline at end of file
diff --git a/accounts/report/payment_collection_with_ageing/payment_collection_with_ageing.txt b/accounts/report/payment_collection_with_ageing/payment_collection_with_ageing.txt
new file mode 100644
index 0000000..3405d19
--- /dev/null
+++ b/accounts/report/payment_collection_with_ageing/payment_collection_with_ageing.txt
@@ -0,0 +1,22 @@
+[
+ {
+  "creation": "2013-05-02 12:09:51", 
+  "docstatus": 0, 
+  "modified": "2013-05-02 12:09:51", 
+  "modified_by": "Administrator", 
+  "owner": "Administrator"
+ }, 
+ {
+  "add_total_row": 1, 
+  "doctype": "Report", 
+  "is_standard": "Yes", 
+  "name": "__common__", 
+  "ref_doctype": "Journal Voucher", 
+  "report_name": "Payment Collection With Ageing", 
+  "report_type": "Script Report"
+ }, 
+ {
+  "doctype": "Report", 
+  "name": "Payment Collection With Ageing"
+ }
+]
\ No newline at end of file
diff --git a/accounts/report/payment_made_with_ageing/__init__.py b/accounts/report/payment_made_with_ageing/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/accounts/report/payment_made_with_ageing/__init__.py
diff --git a/accounts/report/payment_made_with_ageing/payment_made_with_ageing.js b/accounts/report/payment_made_with_ageing/payment_made_with_ageing.js
new file mode 100644
index 0000000..533fe61
--- /dev/null
+++ b/accounts/report/payment_made_with_ageing/payment_made_with_ageing.js
@@ -0,0 +1,40 @@
+wn.query_reports["Payment Made With Ageing"] = {
+	"filters": [
+		{
+			fieldname: "from_date",
+			label: "From Date",
+			fieldtype: "Date",
+			default: wn.defaults.get_user_default("year_start_date"),
+		},
+		{
+			fieldname:"to_date",
+			label: "To Date",
+			fieldtype: "Date",
+			default: get_today()
+		},
+		{
+			fieldname:"account",
+			label: "Supplier Account",
+			fieldtype: "Link",
+			options: "Account",
+			get_query: function() {
+				return {
+					query: "accounts.utils.get_account_list", 
+					filters: {
+						is_pl_account: "No",
+						debit_or_credit: "Credit",
+						company: wn.query_report.filters_by_name.company.get_value(),
+						master_type: "Supplier"
+					}
+				}
+			}
+		},
+		{
+			fieldname:"company",
+			label: "Company",
+			fieldtype: "Link",
+			options: "Company",
+			default: sys_defaults.company
+		},
+	]
+}
\ No newline at end of file
diff --git a/accounts/report/payment_made_with_ageing/payment_made_with_ageing.py b/accounts/report/payment_made_with_ageing/payment_made_with_ageing.py
new file mode 100644
index 0000000..e7f13ef
--- /dev/null
+++ b/accounts/report/payment_made_with_ageing/payment_made_with_ageing.py
@@ -0,0 +1,89 @@
+# 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 import msgprint, _
+from accounts.report.accounts_receivable.accounts_receivable import get_ageing_data
+
+def execute(filters=None):
+	if not filters: filters = {}
+	
+	columns = get_columns()
+	entries = get_entries(filters)
+	pi_posting_date_map = get_pi_posting_date_map()
+	
+	data = []
+	for d in entries:
+		against_voucher_date = d.against_voucher and pi_posting_date_map[d.against_voucher] or ""
+		
+		row = [d.name, d.account, d.posting_date, d.against_voucher, against_voucher_date, 
+			d.debit, d.credit, d.cheque_no, d.cheque_date, d.remark]
+			
+		if d.against_voucher:
+			row += get_ageing_data(against_voucher_date, d.posting_date, d.debit or -1*d.credit)
+		else:
+			row += ["", "", "", "", ""]
+			
+		data.append(row)
+	
+	return columns, data
+	
+def get_columns():
+	return ["Journal Voucher:Link/Journal Voucher:140", "Account:Link/Account:140", 
+		"Posting Date:Date:100", "Against Invoice:Link/Purchase Invoice:130", 
+		"Against Invoice Posting Date:Date:130", "Debit:Currency:120", "Credit:Currency:120", 
+		"Reference No::100", "Reference Date:Date:100", "Remarks::150", "Age:Int:40", 
+		"0-30:Currency:100", "30-60:Currency:100", "60-90:Currency:100", "90-Above:Currency:100"
+	]
+
+def get_conditions(filters):
+	conditions = ""
+	supplier_accounts = []
+	if filters.get("account"):
+		supplier_accounts = [filters["account"]]
+	else:
+		cond = filters.get("company") and (" and company = '%s'" % filters["company"]) or ""
+		supplier_accounts = webnotes.conn.sql_list("""select name from `tabAccount` 
+			where ifnull(master_type, '') = 'Supplier' and docstatus < 2 %s""" % cond)
+	
+	if supplier_accounts:
+		conditions += " and jvd.account in (%s)" % (", ".join(['%s']*len(supplier_accounts)))
+	else:
+		msgprint(_("No Supplier Accounts found. Supplier Accounts are identified based on \
+			'Master Type' value in account record."), raise_exception=1)
+		
+	if filters.get("from_date"): conditions += " and jv.posting_date >= '%s'" % filters["from_date"]
+	if filters.get("to_date"): conditions += " and jv.posting_date <= '%s'" % filters["to_date"]
+
+	return conditions, supplier_accounts
+	
+def get_entries(filters):
+	conditions, supplier_accounts = get_conditions(filters)
+	entries =  webnotes.conn.sql("""select jv.name, jvd.account, jv.posting_date, 
+		jvd.against_voucher, jvd.debit, jvd.credit, jv.cheque_no, jv.cheque_date, jv.remark
+		from `tabJournal Voucher Detail` jvd, `tabJournal Voucher` jv 
+		where jvd.parent = jv.name and jv.docstatus=1 %s order by jv.name DESC""" % 
+		(conditions), tuple(supplier_accounts), as_dict=1)
+		
+	return entries
+	
+def get_pi_posting_date_map():
+	pi_posting_date_map = {}
+	for t in webnotes.conn.sql("""select name, posting_date from `tabPurchase Invoice`"""):
+		pi_posting_date_map[t[0]] = t[1]
+		
+	return pi_posting_date_map
\ No newline at end of file
diff --git a/accounts/report/payment_made_with_ageing/payment_made_with_ageing.txt b/accounts/report/payment_made_with_ageing/payment_made_with_ageing.txt
new file mode 100644
index 0000000..c5c85da
--- /dev/null
+++ b/accounts/report/payment_made_with_ageing/payment_made_with_ageing.txt
@@ -0,0 +1,22 @@
+[
+ {
+  "creation": "2013-05-02 12:10:21", 
+  "docstatus": 0, 
+  "modified": "2013-05-02 12:10:21", 
+  "modified_by": "Administrator", 
+  "owner": "Administrator"
+ }, 
+ {
+  "add_total_row": 1, 
+  "doctype": "Report", 
+  "is_standard": "Yes", 
+  "name": "__common__", 
+  "ref_doctype": "Journal Voucher", 
+  "report_name": "Payment Made With Ageing", 
+  "report_type": "Script Report"
+ }, 
+ {
+  "doctype": "Report", 
+  "name": "Payment Made With Ageing"
+ }
+]
\ No newline at end of file
diff --git a/accounts/report/purchase_register/purchase_register.py b/accounts/report/purchase_register/purchase_register.py
index 01dc937..c131c17 100644
--- a/accounts/report/purchase_register/purchase_register.py
+++ b/accounts/report/purchase_register/purchase_register.py
@@ -141,7 +141,6 @@
 	accounts = list(set([inv.credit_to for inv in invoice_list]))
 	for acc in webnotes.conn.sql("""select name, parent_account from tabAccount 
 		where name in (%s)""" % ", ".join(["%s"]*len(accounts)), tuple(accounts), as_dict=1):
-			account_map.setdefault(acc.name, "")
 			account_map[acc.name] = acc.parent_account
 						
 	return account_map	
\ No newline at end of file
diff --git a/accounts/report/sales_register/sales_register.py b/accounts/report/sales_register/sales_register.py
index a0020c4..23d2227 100644
--- a/accounts/report/sales_register/sales_register.py
+++ b/accounts/report/sales_register/sales_register.py
@@ -145,7 +145,6 @@
 	customers = list(set([inv.customer for inv in invoice_list]))
 	for cust in webnotes.conn.sql("""select name, territory from `tabCustomer` 
 		where name in (%s)""" % ", ".join(["%s"]*len(customers)), tuple(customers), as_dict=1):
-			customer_map.setdefault(cust.name, "")
 			customer_map[cust.name] = cust.territory
 	
 	return customer_map
@@ -155,7 +154,6 @@
 	accounts = list(set([inv.debit_to for inv in invoice_list]))
 	for acc in webnotes.conn.sql("""select name, parent_account from tabAccount 
 		where name in (%s)""" % ", ".join(["%s"]*len(accounts)), tuple(accounts), as_dict=1):
-			account_map.setdefault(acc.name, "")
 			account_map[acc.name] = acc.parent_account
 						
 	return account_map
\ No newline at end of file
diff --git a/buying/doctype/purchase_order/test_purchase_order.py b/buying/doctype/purchase_order/test_purchase_order.py
index bd27f07..be2e294 100644
--- a/buying/doctype/purchase_order/test_purchase_order.py
+++ b/buying/doctype/purchase_order/test_purchase_order.py
@@ -27,6 +27,12 @@
 		po.insert()		
 		self.assertEquals(len(po.doclist.get({"parentfield": "po_raw_material_details"})), 2)
 
+	def test_warehouse_company_validation(self):
+		from controllers.buying_controller import WrongWarehouseCompany
+		po = webnotes.bean(copy=test_records[0])
+		po.doc.company = "_Test Company 1"
+		self.assertRaises(WrongWarehouseCompany, po.insert)
+
 
 test_dependencies = ["BOM"]
 
diff --git a/buying/doctype/supplier/supplier.js b/buying/doctype/supplier/supplier.js
index 3834bda..202be71 100644
--- a/buying/doctype/supplier/supplier.js
+++ b/buying/doctype/supplier/supplier.js
@@ -47,7 +47,7 @@
 	if(!cur_frm.address_list) {
 		cur_frm.address_list = new wn.ui.Listing({
 			parent: cur_frm.fields_dict['address_html'].wrapper,
-			page_length: 2,
+			page_length: 5,
 			new_doctype: "Address",
 			custom_new_doc: function(doctype) {
 				var address = wn.model.make_new_doc_and_get_name('Address');
@@ -78,7 +78,7 @@
 	if(!cur_frm.contact_list) {
 		cur_frm.contact_list = new wn.ui.Listing({
 			parent: cur_frm.fields_dict['contact_html'].wrapper,
-			page_length: 2,
+			page_length: 5,
 			new_doctype: "Contact",
 			custom_new_doc: function(doctype) {
 				var contact = wn.model.make_new_doc_and_get_name('Contact');
diff --git a/controllers/buying_controller.py b/controllers/buying_controller.py
index e167dc5..9e181bc 100644
--- a/controllers/buying_controller.py
+++ b/controllers/buying_controller.py
@@ -26,10 +26,13 @@
 
 from controllers.stock_controller import StockController
 
+class WrongWarehouseCompany(Exception): pass
+
 class BuyingController(StockController):
 	def validate(self):
 		super(BuyingController, self).validate()
 		self.validate_stock_or_nonstock_items()
+		self.validate_warehouse_belongs_to_company()
 		if self.meta.get_field("currency"):
 			self.company_currency = get_company_currency(self.doc.company)
 			self.validate_conversion_rate("currency", "conversion_rate")
@@ -42,7 +45,14 @@
 						
 			# set total in words
 			self.set_total_in_words()
-			
+	
+	def validate_warehouse_belongs_to_company(self):
+		for warehouse, company in webnotes.conn.get_values("Warehouse", 
+			self.doclist.get_distinct_values("warehouse"), "company").items():
+			if company and company != self.doc.company:
+				webnotes.msgprint(_("Company mismatch for Warehouse") + (": %s" % (warehouse,)),
+					raise_exception=WrongWarehouseCompany)
+
 	def validate_stock_or_nonstock_items(self):
 		items = [d.item_code for d in self.doclist.get({"parentfield": self.fname})]
 		if self.stock_items:
diff --git a/home/page/latest_updates/latest_updates.js b/home/page/latest_updates/latest_updates.js
index b768f1a..38c0026 100644
--- a/home/page/latest_updates/latest_updates.js
+++ b/home/page/latest_updates/latest_updates.js
@@ -1,4 +1,10 @@
 erpnext.updates = [
+	["2nd May", ["Buying: Warehouse must belong to same company as transaction",
+		"Price List: Added Currency Field. One price list can have only one currency",
+		"Item: Naming can now be by series or item code",
+		"Naming Series: Set number of digits in series (optionally)",
+		"Login: Disable Signup link in the login page"]],
+	["30th April", ["Price List: Valid for all countries or only valid for specific countries"]],
 	["18th April", ["Cost Center: Set a default Cost Center for a Company"]],
 	["12th April", ["Employee: List of Leave Approvers who can approve the Employee's Leave Applications"]],
 	["10th April", ["Redesigned File Uploads and added File Manager in Setup"]],
diff --git a/hr/doctype/deduction_type/deduction_type.txt b/hr/doctype/deduction_type/deduction_type.txt
index 4c9ad7a..f346793 100644
--- a/hr/doctype/deduction_type/deduction_type.txt
+++ b/hr/doctype/deduction_type/deduction_type.txt
@@ -1,12 +1,13 @@
 [
  {
-  "creation": "2013-01-10 16:34:13", 
+  "creation": "2013-01-22 16:50:30", 
   "docstatus": 0, 
-  "modified": "2013-01-22 14:25:38", 
+  "modified": "2013-05-02 11:22:59", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
  {
+  "allow_rename": 1, 
   "autoname": "field:deduction_name", 
   "doctype": "DocType", 
   "document_type": "Master", 
diff --git a/hr/doctype/earning_type/earning_type.txt b/hr/doctype/earning_type/earning_type.txt
index 18cac68..d69f486 100644
--- a/hr/doctype/earning_type/earning_type.txt
+++ b/hr/doctype/earning_type/earning_type.txt
@@ -1,12 +1,13 @@
 [
  {
-  "creation": "2013-01-10 16:34:13", 
+  "creation": "2013-01-24 11:03:32", 
   "docstatus": 0, 
-  "modified": "2013-01-23 16:32:07", 
+  "modified": "2013-05-02 11:22:48", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
  {
+  "allow_rename": 1, 
   "autoname": "field:earning_name", 
   "doctype": "DocType", 
   "document_type": "Master", 
diff --git a/patches/april_2013/p08_price_list_country.py b/patches/april_2013/p08_price_list_country.py
new file mode 100644
index 0000000..65643cc
--- /dev/null
+++ b/patches/april_2013/p08_price_list_country.py
@@ -0,0 +1,5 @@
+import webnotes
+
+def execute():
+	webnotes.reload_doc("Setup", "DocType", "Price List")
+	webnotes.conn.sql("""update `tabPrice List` set valid_for_all_countries=1""")
\ No newline at end of file
diff --git a/patches/patch_list.py b/patches/patch_list.py
index c9a0ab5..ed1c846 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -154,12 +154,12 @@
 	"patches.january_2013.remove_tds_entry_from_gl_mapper",
 	"patches.january_2013.update_number_format",
 	"patches.january_2013.purchase_price_list",
+	"execute:webnotes.reload_doc('core', 'doctype', 'print_format') #2013-01",
 	"execute:webnotes.reload_doc('accounts','Print Format','Payment Receipt Voucher')",
 	"patches.january_2013.update_fraction_for_usd",
 	"patches.january_2013.enable_currencies",
 	"patches.january_2013.remove_unwanted_permission",
 	"patches.january_2013.remove_landed_cost_master",
-	"execute:webnotes.reload_doc('core', 'doctype', 'print_format')",
 	"patches.january_2013.reload_print_format",
 	"patches.january_2013.rebuild_tree",
 	"execute:webnotes.reload_doc('core','doctype','docfield') #2013-01-28",
@@ -249,4 +249,5 @@
 	"execute:webnotes.reset_perms('File Data')",
 	"patches.april_2013.p07_update_file_data_2",
 	"patches.april_2013.rebuild_sales_browser",
+	"patches.april_2013.p08_price_list_country",
 ]
\ No newline at end of file
diff --git a/selling/doctype/customer/customer.js b/selling/doctype/customer/customer.js
index 403b83f..40a7846 100644
--- a/selling/doctype/customer/customer.js
+++ b/selling/doctype/customer/customer.js
@@ -57,7 +57,7 @@
 	if(!cur_frm.address_list) {
 		cur_frm.address_list = new wn.ui.Listing({
 			parent: cur_frm.fields_dict['address_html'].wrapper,
-			page_length: 2,
+			page_length: 5,
 			new_doctype: "Address",
 			custom_new_doc: function(doctype) {
 				var address = wn.model.make_new_doc_and_get_name('Address');
@@ -88,7 +88,7 @@
 	if(!cur_frm.contact_list) {
 		cur_frm.contact_list = new wn.ui.Listing({
 			parent: cur_frm.fields_dict['contact_html'].wrapper,
-			page_length: 2,
+			page_length: 5,
 			custom_new_doc: function(doctype) {
 				var contact = wn.model.make_new_doc_and_get_name('Contact');
 				contact = locals['Contact'][contact];
diff --git a/setup/doctype/backup_manager/backup_dropbox.py b/setup/doctype/backup_manager/backup_dropbox.py
index ac07824..054d2b2 100644
--- a/setup/doctype/backup_manager/backup_dropbox.py
+++ b/setup/doctype/backup_manager/backup_dropbox.py
@@ -85,6 +85,7 @@
 		os.path.basename(backup.backup_path_db))
 	upload_file_to_dropbox(filename, "/database", dropbox_client)
 
+	webnotes.conn.close()
 	response = dropbox_client.metadata("/files")
 	
 	# upload files to files folder
@@ -108,6 +109,7 @@
 				did_not_upload.append(filename)
 				error_log.append(cstr(e))
 	
+	webnotes.connect()
 	return did_not_upload, list(set(error_log))
 
 def get_dropbox_session():
diff --git a/setup/doctype/backup_manager/backup_googledrive.py b/setup/doctype/backup_manager/backup_googledrive.py
index 7d980de..533b37d 100644
--- a/setup/doctype/backup_manager/backup_googledrive.py
+++ b/setup/doctype/backup_manager/backup_googledrive.py
@@ -34,7 +34,6 @@
 		"authorize_url": authorize_url,
 	}
 
-@webnotes.whitelist()
 def upload_files(name, mimetype, service, folder_id):
 	if not webnotes.conn:
 		webnotes.connect()
@@ -78,6 +77,9 @@
 	did_not_upload = []
 	error_log = []
 	
+	files_folder_id = webnotes.conn.get_value("Backup Manager", None, "files_folder_id")
+	
+	webnotes.conn.close()
 	path = os.path.join(get_base_path(), "public", "files")
 	for filename in os.listdir(path):
 		found = False
@@ -90,10 +92,7 @@
 			mimetype = mimetypes.types_map.get("." + ext) or "application/octet-stream"
 		
 		#Compare Local File with Server File
-		param = {}
-	  	children = drive_service.children().list(
-			folderId=webnotes.conn.get_value("Backup Manager", None, "files_folder_id"), 
-			**param).execute()
+	  	children = drive_service.children().list(folderId=files_folder_id).execute()
 	  	for child in children.get('items', []):
 			file = drive_service.files().get(fileId=child['id']).execute()
 			if filename == file['title'] and size == int(file['fileSize']):
@@ -101,12 +100,12 @@
 				break
 		if not found:
 			try:
-				upload_files(filepath, mimetype, drive_service, 
-					webnotes.conn.get_value("Backup Manager", None, "files_folder_id"))
+				upload_files(filepath, mimetype, drive_service, files_folder_id)
 			except Exception, e:
 				did_not_upload.append(filename)
 				error_log.append(cstr(e))
 	
+	webnotes.connect()
 	return did_not_upload, list(set(error_log))
 
 def get_gdrive_flow():
diff --git a/setup/doctype/backup_manager/backup_manager.js b/setup/doctype/backup_manager/backup_manager.js
index 8d2d8de..c78be3a 100644
--- a/setup/doctype/backup_manager/backup_manager.js
+++ b/setup/doctype/backup_manager/backup_manager.js
@@ -1,67 +1,90 @@
-cur_frm.cscript.refresh = function(doc) {
-	cur_frm.disable_save();
-}
-
-//dropbox
-cur_frm.cscript.allow_dropbox_access = function(doc) {
-	if (doc.send_notifications_to == '') {
-		msgprint("Please enter email address.")
-	}
-	else {
-		wn.call({
-			method: "setup.doctype.backup_manager.backup_dropbox.get_dropbox_authorize_url",
-			callback: function(r) {
-				if(!r.exc) {
-					cur_frm.set_value("dropbox_access_secret", r.message.secret);
-					cur_frm.set_value("dropbox_access_key", r.message.key);
-					cur_frm.save(null, function() {
-						window.open(r.message.url);
-					});
-				}
+$.extend(cur_frm.cscript, {
+	refresh: function() {
+		cur_frm.disable_save();
+		
+		if(!(cint(cur_frm.doc.dropbox_access_allowed) || 
+			cint(cur_frm.doc.gdrive_access_allowed))) {
+				cur_frm.set_intro(wn._("You can start by selecting backup frequency and \
+					granting access for sync"));
+		} else {
+			var services = {
+				"dropbox": wn._("Dropbox"),
+				"gdrive": wn._("Google Drive")
 			}
-		})
-	}
-}
-
-cur_frm.cscript.backup_right_now = function(doc) {
-	msgprint("Backing up and uploading. This may take a few minutes.")
-	wn.call({
-		method: "setup.doctype.backup_manager.backup_manager.take_backups_dropbox",
-		callback: function(r) {
-			msgprint("Backups taken. Please check your email for the response.")
+			var active_services = [];
+			
+			$.each(services, function(service, label) {
+				var access_allowed = cint(cur_frm.doc[service + "_access_allowed"]);
+				var frequency = cur_frm.doc["upload_backups_to_" + service];
+				if(access_allowed && frequency && frequency !== "Never") {
+					active_services.push(label + " [" + frequency + "]");
+				}
+			});
+			
+			if(active_services.length > 0) {
+				cur_frm.set_intro(wn._("Backups will be uploaded to") + ": " + 
+					wn.utils.comma_and(active_services));
+			} else {
+				cur_frm.set_intro("");
+			}
 		}
-	})
-}
-//gdrive
-cur_frm.cscript.allow_gdrive_access = function(doc) {
-	if (doc.send_notifications_to == '') {
-		msgprint("Please enter email address.")
-	}
-	else {
-		wn.call({
-			method: "setup.doctype.backup_manager.backup_googledrive.get_gdrive_authorize_url",
-			callback: function(r) {
-				if(!r.exc) {
-					window.open(r.message.authorize_url);
+		
+	},
+	
+	validate_send_notifications_to: function() {
+		if(!cur_frm.doc.send_notifications_to) {
+			msgprint(wn._("Please specify") + ": " + 
+				wn._(wn.meta.get_label(cur_frm.doctype, "send_notifications_to")));
+			return false;
+		}
+		
+		return true;
+	},
+	
+	allow_dropbox_access: function() {
+		if(cur_frm.cscript.validate_send_notifications_to()) {
+			wn.call({
+				method: "setup.doctype.backup_manager.backup_dropbox.get_dropbox_authorize_url",
+				callback: function(r) {
+					if(!r.exc) {
+						cur_frm.set_value("dropbox_access_secret", r.message.secret);
+						cur_frm.set_value("dropbox_access_key", r.message.key);
+						cur_frm.save(null, function() {
+							window.open(r.message.url);
+						});
+					}
 				}
-			}
-		})
-	}
-}
-
-cur_frm.cscript.validate_gdrive = function(doc) {
-	wn.call({
-		method: "setup.doctype.backup_manager.backup_googledrive.gdrive_callback",
-		args: {
-			verification_code: doc.verification_code
-		},
-	});
-}
-
-cur_frm.cscript.upload_backups_to_dropbox = function(doc) {
-	cur_frm.save()
-}
-
-cur_frm.cscript.upload_backups_to_gdrive = function(doc) {
-	cur_frm.save()
-}
+			});
+		}
+	},
+	
+	allow_gdrive_access: function() {
+		if(cur_frm.cscript.validate_send_notifications_to()) {
+			wn.call({
+				method: "setup.doctype.backup_manager.backup_googledrive.get_gdrive_authorize_url",
+				callback: function(r) {
+					if(!r.exc) {
+						window.open(r.message.authorize_url);
+					}
+				}
+			});
+		}
+	},
+	
+	validate_gdrive: function() {
+		wn.call({
+			method: "setup.doctype.backup_manager.backup_googledrive.gdrive_callback",
+			args: {
+				verification_code: cur_frm.doc.verification_code
+			},
+		});
+	},
+	
+	upload_backups_to_dropbox: function() {
+		cur_frm.save();
+	},
+	
+	upload_backups_to_gdrive: function() {
+		cur_frm.save();
+	},
+});
\ No newline at end of file
diff --git a/setup/doctype/backup_manager/backup_manager.py b/setup/doctype/backup_manager/backup_manager.py
index a8ecd63..c91cf11 100644
--- a/setup/doctype/backup_manager/backup_manager.py
+++ b/setup/doctype/backup_manager/backup_manager.py
@@ -20,8 +20,8 @@
 	if webnotes.conn.get_value("Backup Manager", None, "upload_backups_to_dropbox")==freq:
 		take_backups_dropbox()
 		
-	if webnotes.conn.get_value("Backup Manager", None, "upload_backups_to_gdrive")==freq:
-		take_backups_gdrive()
+	# if webnotes.conn.get_value("Backup Manager", None, "upload_backups_to_gdrive")==freq:
+	# 	take_backups_gdrive()
 	
 @webnotes.whitelist()
 def take_backups_dropbox():
@@ -35,7 +35,7 @@
 	except Exception:
 		file_and_error = [" - ".join(f) for f in zip(did_not_upload, error_log)]
 		error_message = ("\n".join(file_and_error) + "\n" + webnotes.getTraceback())
-		print error_message
+		webnotes.errprint(error_message)
 		send_email(False, "Dropbox", error_message)
 
 #backup to gdrive 
@@ -51,7 +51,7 @@
 	except Exception:
 		file_and_error = [" - ".join(f) for f in zip(did_not_upload, error_log)]
 		error_message = ("\n".join(file_and_error) + "\n" + webnotes.getTraceback())
-		print error_message
+		webnotes.errprint(error_message)
 		send_email(False, "Google Drive", error_message)
 
 def send_email(success, service_name, error_status=None):
diff --git a/setup/doctype/backup_manager/backup_manager.txt b/setup/doctype/backup_manager/backup_manager.txt
index 9a43f34..2d6f191 100644
--- a/setup/doctype/backup_manager/backup_manager.txt
+++ b/setup/doctype/backup_manager/backup_manager.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-03-15 11:06:59", 
+  "creation": "2013-04-30 12:58:38", 
   "docstatus": 0, 
-  "modified": "2013-03-15 17:27:33", 
+  "modified": "2013-05-02 11:42:08", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -109,6 +109,7 @@
   "doctype": "DocField", 
   "fieldname": "sync_with_gdrive", 
   "fieldtype": "Section Break", 
+  "hidden": 1, 
   "label": "Sync with Google Drive"
  }, 
  {
diff --git a/setup/doctype/global_defaults/global_defaults.py b/setup/doctype/global_defaults/global_defaults.py
index 8275513..191a47e 100644
--- a/setup/doctype/global_defaults/global_defaults.py
+++ b/setup/doctype/global_defaults/global_defaults.py
@@ -31,6 +31,7 @@
 	'item_group': 'default_item_group',
 	'customer_group': 'default_customer_group',
 	'cust_master_name': 'cust_master_name', 
+	"item_naming_by": "item_naming_by",
 	'supplier_type': 'default_supplier_type',
 	'supp_master_name': 'supp_master_name', 
 	'territory': 'default_territory',
diff --git a/setup/doctype/global_defaults/global_defaults.txt b/setup/doctype/global_defaults/global_defaults.txt
index 7f81618..853bb57 100644
--- a/setup/doctype/global_defaults/global_defaults.txt
+++ b/setup/doctype/global_defaults/global_defaults.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-03-25 11:08:14", 
+  "creation": "2013-04-01 15:05:24", 
   "docstatus": 0, 
-  "modified": "2013-03-28 15:41:03", 
+  "modified": "2013-05-02 15:05:21", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -27,8 +27,6 @@
   "permlevel": 0
  }, 
  {
-  "amend": 0, 
-  "cancel": 0, 
   "create": 1, 
   "doctype": "DocPerm", 
   "name": "__common__", 
@@ -169,6 +167,13 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "item_naming_by", 
+  "fieldtype": "Select", 
+  "label": "Item Naming By", 
+  "options": "Item Code\nNaming Series"
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "default_item_group", 
   "fieldtype": "Link", 
   "label": "Default Item Group", 
@@ -503,6 +508,11 @@
   "read_only": 0
  }, 
  {
+  "amend": 0, 
+  "cancel": 0, 
+  "doctype": "DocPerm"
+ }, 
+ {
   "doctype": "DocPerm"
  }
 ]
\ No newline at end of file
diff --git a/setup/doctype/naming_series/naming_series.py b/setup/doctype/naming_series/naming_series.py
index 7b804f8..3a6b36d 100644
--- a/setup/doctype/naming_series/naming_series.py
+++ b/setup/doctype/naming_series/naming_series.py
@@ -123,7 +123,14 @@
 			
 	def validate_series_name(self, n):
 		import re
-		if not re.match('[a-zA-Z0-9]+(([-/][a-zA-Z0-9])?[-/][a-zA-Z0-9]*)*',n):
+		if "." in n:
+			parts = n.split(".")
+			if len(parts) > 2:
+				msgprint("Only one dot (.) allowed in " + n, raise_exception=1)
+			if not re.match("#+$", parts[-1]):
+				msgprint("Numbering series must be in hashes (e.g. ####)", raise_exception=1)
+			n = n[0]
+		if not re.match("^[a-zA-Z0-9-/]*$", n):
 			msgprint('Special Characters except "-" and "/" not allowed in naming series')
 			raise Exception
 		
diff --git a/setup/doctype/naming_series/naming_series.txt b/setup/doctype/naming_series/naming_series.txt
index 3de9e5c..0dab9e9 100644
--- a/setup/doctype/naming_series/naming_series.txt
+++ b/setup/doctype/naming_series/naming_series.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-01-10 16:34:23", 
+  "creation": "2013-01-25 11:35:08", 
   "docstatus": 0, 
-  "modified": "2013-01-22 14:56:34", 
+  "modified": "2013-05-02 15:34:41", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -25,8 +25,6 @@
   "permlevel": 0
  }, 
  {
-  "amend": 0, 
-  "cancel": 0, 
   "create": 1, 
   "doctype": "DocPerm", 
   "name": "__common__", 
@@ -62,7 +60,7 @@
   "fieldname": "help_html", 
   "fieldtype": "HTML", 
   "label": "Help HTML", 
-  "options": "<div class=\"help-box\">\nEdit list of Series in the box below. Each Series Prefix on a new line.<br><br>\nAllowed special characters are \"/\" and \"-\"<br>\nExamples:<br>\nINV-<br>\nINV-10-<br>\nINVK-<br>\n</div>"
+  "options": "<div class=\"well\">\nEdit list of Series in the box below. Rules:\n<ul>\n<li>Each Series Prefix on a new line.</li>\n<li>Allowed special characters are \"/\" and \"-\"</li>\n<li>Optionally, set the number of digits in the series using dot (.) followed by hashes (#). For example, \".####\" means that the series will have four digits. Default is five digits.</li>\n</ul>\nExamples:<br>\nINV-<br>\nINV-10-<br>\nINVK-<br>\nINV-.####<br>\n</div>"
  }, 
  {
   "doctype": "DocField", 
diff --git a/setup/doctype/price_list/price_list.js b/setup/doctype/price_list/price_list.js
index 75d3d0f..b68627f 100644
--- a/setup/doctype/price_list/price_list.js
+++ b/setup/doctype/price_list/price_list.js
@@ -14,10 +14,46 @@
 // You should have received a copy of the GNU General Public License
 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+cur_frm.cscript.onload = function() {
+	cur_frm.cscript.show_item_prices();
+}
+
 cur_frm.cscript.refresh = function(doc, cdt, cdn) {
 	cur_frm.set_intro("");
 	if(doc.__islocal) {
 		cur_frm.set_intro("Save this list to begin.");
 		return;
+	} else {
+		cur_frm.cscript.show_item_prices();
 	}
 }
+
+cur_frm.cscript.show_item_prices = function() {
+	var item_price = wn.model.get("Item Price", {price_list_name: cur_frm.doc.name});
+	
+	var show = item_price && item_price.length;
+	
+	cur_frm.toggle_display("item_prices_section", show);
+	$(cur_frm.fields_dict.item_prices.wrapper).empty();
+	if (!show) return;
+	
+	var out = '<table class="table table-striped table-bordered">\
+		<thead><tr>\
+			<th>' + wn._("Item Code") + '</th>\
+			<th>' + wn._("Price") + '</th>\
+			<th>' + wn._("Valid For Selling") + '</th>\
+			<th>' + wn._("Valid For Buying") + '</th>\
+		</tr></thead>\
+		<tbody>'
+		+ $.map(item_price.sort(function(a, b) { return a.parent.localeCompare(b.parent); }), function(d) {
+			return '<tr>'
+				+ '<td>' + d.parent + '</td>'
+				+ '<td style="text-align: right;">' + format_currency(d.ref_rate, d.ref_currency) + '</td>'
+				+ '<td>' + (cint(d.selling) ? '<i class="icon-check"></i>' : "") + '</td>'
+				+ '<td>' + (cint(d.buying) ? '<i class="icon-check"></i>' : "") + '</td>'
+				+ '</tr>'
+		}).join("\n")
+		+ '</tbody>\
+	</table>';
+	$(out).appendTo($(cur_frm.fields_dict.item_prices.wrapper));
+}
diff --git a/setup/doctype/price_list/price_list.py b/setup/doctype/price_list/price_list.py
index a88309b..ae49bf8 100644
--- a/setup/doctype/price_list/price_list.py
+++ b/setup/doctype/price_list/price_list.py
@@ -16,73 +16,20 @@
 
 from __future__ import unicode_literals
 import webnotes
-
-from webnotes.model.doc import Document
-from webnotes import msgprint
+from webnotes import msgprint, _
+from webnotes.utils import cint
 
 
 class DocType:
 	def __init__(self, d, dl):
 		self.doc, self.doclist = d, dl
-		self.cl = []
-	
-	# validate currency
-	def is_currency_valid(self, currency):
-		if currency in self.cl:
-			return 1
-			
-		if webnotes.conn.sql("select name from tabCurrency where name=%s", currency):
-			self.cl.append(currency)
-			return 1
-		else:
-			return 0
-			
-	def download_template(self, arg=None):
-		"""download 3 column template with all Items"""
-		default_currency = webnotes.conn.get_default('currency')
-		item_list = webnotes.conn.sql("""select name from tabItem where 
-			(ifnull(is_sales_item,'')='Yes' or ifnull(is_service_item,'')='Yes')""")
-		data = [self.get_price(i[0], default_currency) for i in item_list]
-		return [['Item', 'Rate', 'Currency']] + data
-	
-	def get_price(self, item, default_currency):
-		rate = webnotes.conn.sql("""select ref_rate, ref_currency from `tabItem Price` 
-			where parent=%s and price_list_name=%s""", (item, self.doc.name))
-		return [item, rate and rate[0][0] or 0, rate and rate[0][1] or default_currency]
-	
-	# update prices in Price List
-	def update_prices(self):
-		from webnotes.utils.datautils import read_csv_content_from_attached_file
-		data = read_csv_content_from_attached_file(self.doc)
 		
-		webnotes.conn.auto_commit_on_many_writes = 1
-				
-		updated = 0
-		
-		for line in data:
-			if line and len(line)==3 and line[0]!='Item':
-				# if item exists
-				if webnotes.conn.sql("select name from tabItem where name=%s", line[0]):
-					if self.is_currency_valid(line[2]):
-						# if price exists
-						ref_ret_detail = webnotes.conn.sql("select name from `tabItem Price` where parent=%s and price_list_name=%s and ref_currency=%s", \
-							(line[0], self.doc.name, line[2]))
-						if ref_ret_detail:
-							webnotes.conn.sql("update `tabItem Price` set ref_rate=%s where name=%s", (line[1], ref_ret_detail[0][0]))
-						else:
-							d = Document('Item Price')
-							d.parent = line[0]
-							d.parentfield = 'ref_rate_details'
-							d.parenttype = 'Item'
-							d.price_list_name = self.doc.name
-							d.ref_rate = line[1]
-							d.ref_currency = line[2]
-							d.save(1)
-						updated += 1
-					else:
-						msgprint("[Ignored] Unknown currency '%s' for Item '%s'" % (line[2], line[0]))
-				else:
-					msgprint("[Ignored] Did not find Item '%s'" % line[1])
-		
-		msgprint("<b>%s</b> items updated" % updated)
-		webnotes.conn.auto_commit_on_many_writes = 0
\ No newline at end of file
+	def onload(self):
+		self.doclist.extend(webnotes.conn.sql("""select * from `tabItem Price` 
+			where price_list_name=%s""", self.doc.name, as_dict=True, update={"doctype": "Item Price"}))
+	
+	def validate(self):
+		if not (cint(self.doc.valid_for_all_countries) or len(self.doclist.get({"parentfield": "valid_for_countries"}))):
+			msgprint(_("""Please check "Valid For All Countries" or \
+				enter atlease one row in the "Countries" table."""), raise_exception=True)
+	
diff --git a/setup/doctype/price_list/price_list.txt b/setup/doctype/price_list/price_list.txt
index a230f5b..781eae5 100644
--- a/setup/doctype/price_list/price_list.txt
+++ b/setup/doctype/price_list/price_list.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-01-25 11:35:09", 
   "docstatus": 0, 
-  "modified": "2013-01-22 14:56:41", 
+  "modified": "2013-05-02 14:45:00", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -53,12 +53,54 @@
   "reqd": 1
  }, 
  {
-  "depends_on": "price_list_name", 
+  "doctype": "DocField", 
+  "fieldname": "currency", 
+  "fieldtype": "Link", 
+  "label": "Currency", 
+  "options": "Currency", 
+  "reqd": 1
+ }, 
+ {
+  "default": "1", 
+  "doctype": "DocField", 
+  "fieldname": "valid_for_all_countries", 
+  "fieldtype": "Check", 
+  "label": "Valid for all countries"
+ }, 
+ {
+  "description": "A list of Countries, for which, this Price List is valid", 
+  "doctype": "DocField", 
+  "fieldname": "valid_for_countries", 
+  "fieldtype": "Table", 
+  "label": "Valid for the following countries", 
+  "options": "Price List Country"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "item_prices_section", 
+  "fieldtype": "Section Break", 
+  "label": "Item Prices"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "item_prices", 
+  "fieldtype": "HTML", 
+  "label": "Item Prices"
+ }, 
+ {
+  "depends_on": "eval:!doc.__islocal", 
+  "doctype": "DocField", 
+  "fieldname": "section_break_1", 
+  "fieldtype": "Section Break", 
+  "label": "How to upload"
+ }, 
+ {
+  "depends_on": "eval:!doc.__islocal", 
   "doctype": "DocField", 
   "fieldname": "how_to_upload", 
   "fieldtype": "HTML", 
   "label": "How to upload", 
-  "options": "<div class=\"help\">Use the <a href=\"#data-import-tool\">Data Import Tool</a> to upload, update Item Prices in bulk:\n<ol> \n<li>Go to Data Import Tool.\n<li>Select \"Item\"\n<li>Check on \"With Data\"\n<li>Download \"Item Price\" from Child Tables.\n<li>Update the prices required and add new rows if required.\n<li>Check on \"Overwrite\"\n<li>Upload the modified sheet.\n</div>\n"
+  "options": "<div class=\"well\">Use the <a href=\"#data-import-tool\">Data Import Tool</a> to upload, update Item Prices in bulk:\n<ol> \n<li>Go to Data Import Tool.\n<li>Select \"Item\"\n<li>Check on \"With Data\"\n<li>Download \"Item Price\" from Child Tables.\n<li>Update the prices required and add new rows if required.\n<li>Check on \"Overwrite\"\n<li>Upload the modified sheet.\n</div>\n"
  }, 
  {
   "cancel": 0, 
@@ -78,7 +120,6 @@
   "cancel": 1, 
   "create": 1, 
   "doctype": "DocPerm", 
-  "match": "", 
   "role": "Sales Master Manager", 
   "write": 1
  }
diff --git a/setup/doctype/price_list/test_price_list.py b/setup/doctype/price_list/test_price_list.py
index 53b86a3..fe87821 100644
--- a/setup/doctype/price_list/test_price_list.py
+++ b/setup/doctype/price_list/test_price_list.py
@@ -1,6 +1,8 @@
 test_records = [
 	[{
 		"doctype": "Price List",
-		"price_list_name": "_Test Price List"
+		"price_list_name": "_Test Price List",
+		"currency": "INR",
+		"valid_for_all_countries": 1
 	}]
 ]
\ No newline at end of file
diff --git a/setup/doctype/price_list_country/__init__.py b/setup/doctype/price_list_country/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/setup/doctype/price_list_country/__init__.py
diff --git a/setup/doctype/price_list_country/price_list_country.py b/setup/doctype/price_list_country/price_list_country.py
new file mode 100644
index 0000000..928aa9f
--- /dev/null
+++ b/setup/doctype/price_list_country/price_list_country.py
@@ -0,0 +1,8 @@
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import webnotes
+
+class DocType:
+	def __init__(self, d, dl):
+		self.doc, self.doclist = d, dl
\ No newline at end of file
diff --git a/setup/doctype/price_list_country/price_list_country.txt b/setup/doctype/price_list_country/price_list_country.txt
new file mode 100644
index 0000000..640b0a8
--- /dev/null
+++ b/setup/doctype/price_list_country/price_list_country.txt
@@ -0,0 +1,36 @@
+[
+ {
+  "creation": "2013-04-29 18:24:32", 
+  "docstatus": 0, 
+  "modified": "2013-04-29 18:24:32", 
+  "modified_by": "Administrator", 
+  "owner": "Administrator"
+ }, 
+ {
+  "autoname": "PLCNTRY-.#####", 
+  "doctype": "DocType", 
+  "istable": 1, 
+  "module": "Setup", 
+  "name": "__common__"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "country", 
+  "fieldtype": "Link", 
+  "label": "Country", 
+  "name": "__common__", 
+  "options": "Country", 
+  "parent": "Price List Country", 
+  "parentfield": "fields", 
+  "parenttype": "DocType", 
+  "permlevel": 0, 
+  "reqd": 1
+ }, 
+ {
+  "doctype": "DocType", 
+  "name": "Price List Country"
+ }, 
+ {
+  "doctype": "DocField"
+ }
+]
\ No newline at end of file
diff --git a/startup/website.py b/startup/website.py
index 295e5bb..be8eba6 100644
--- a/startup/website.py
+++ b/startup/website.py
@@ -1,4 +1,5 @@
 import webnotes, conf, os
+from webnotes.utils import cint, cstr
 
 def get_templates_path():
 	return os.path.join(os.path.dirname(conf.__file__), "app", "website", "templates")
@@ -61,12 +62,14 @@
 	
 	settings = webnotes.doc("Website Settings", "Website Settings")
 	for k in ["banner_html", "brand_html", "copyright", "address", "twitter_share_via",
-		"favicon", "facebook_share", "google_plus_one", "twitter_share", "linked_in_share"]:
+		"favicon", "facebook_share", "google_plus_one", "twitter_share", "linked_in_share",
+		"disable_signup"]:
 		if k in settings.fields:
 			args[k] = settings.fields.get(k)
 
-	for k in ["facebook_share", "google_plus_one", "twitter_share", "linked_in_share"]:
-		args[k] = int(args.get(k) or 0)
+	for k in ["facebook_share", "google_plus_one", "twitter_share", "linked_in_share",
+		"disable_signup"]:
+		args[k] = cint(args.get(k) or 0)
 	
 	args.url = quote(str(get_request_site_address(full_address=True)), str(""))
 	args.encoded_title = quote(str(args.title or ""), str(""))
diff --git a/stock/doctype/batch/batch.txt b/stock/doctype/batch/batch.txt
index 4722996..c6ed3c3 100644
--- a/stock/doctype/batch/batch.txt
+++ b/stock/doctype/batch/batch.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-03-01 19:09:43", 
+  "creation": "2013-03-05 14:50:38", 
   "docstatus": 0, 
-  "modified": "2013-03-01 08:22:16", 
+  "modified": "2013-05-01 15:49:47", 
   "modified_by": "Administrator", 
   "owner": "harshada@webnotestech.com"
  }, 
@@ -24,14 +24,19 @@
   "permlevel": 0
  }, 
  {
+  "cancel": 1, 
+  "create": 1, 
   "doctype": "DocPerm", 
   "name": "__common__", 
   "parent": "Batch", 
   "parentfield": "permissions", 
   "parenttype": "DocType", 
+  "permlevel": 0, 
   "read": 1, 
+  "report": 1, 
   "role": "Material Master Manager", 
-  "submit": 0
+  "submit": 0, 
+  "write": 1
  }, 
  {
   "doctype": "DocType", 
@@ -94,28 +99,6 @@
   "oldfieldtype": "Date"
  }, 
  {
-  "doctype": "DocField", 
-  "fieldname": "trash_reason", 
-  "fieldtype": "Small Text", 
-  "label": "Trash Reason", 
-  "oldfieldname": "trash_reason", 
-  "oldfieldtype": "Small Text", 
-  "read_only": 1
- }, 
- {
-  "cancel": 1, 
-  "create": 1, 
-  "doctype": "DocPerm", 
-  "permlevel": 0, 
-  "report": 1, 
-  "write": 1
- }, 
- {
-  "amend": 0, 
-  "cancel": 0, 
-  "create": 0, 
-  "doctype": "DocPerm", 
-  "match": "", 
-  "permlevel": 1
+  "doctype": "DocPerm"
  }
 ]
\ No newline at end of file
diff --git a/stock/doctype/item/item.js b/stock/doctype/item/item.js
index 8b3e044..a344ad3 100644
--- a/stock/doctype/item/item.js
+++ b/stock/doctype/item/item.js
@@ -14,11 +14,17 @@
 // You should have received a copy of the GNU General Public License
 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+cur_frm.add_fetch("price_list_name", "currency", "ref_currency")
+
 cur_frm.cscript.refresh = function(doc) {
 	// make sensitive fields(has_serial_no, is_stock_item, valuation_method)
 	// read only if any stock ledger entry exists
 
-	cur_frm.toggle_enable("item_code", doc.__islocal);
+	cur_frm.toggle_display("naming_series", sys_defaults.item_naming_by=="Naming Series" 
+		&& doc.__islocal)
+	cur_frm.toggle_display("item_code", sys_defaults.item_naming_by!="Naming Series"
+		&& doc.__islocal)
+
 
 	if ((!doc.__islocal) && (doc.is_stock_item == 'Yes')) {
 		var callback = function(r, rt) {
diff --git a/stock/doctype/item/item.py b/stock/doctype/item/item.py
index 6b6dfb3..6327504 100644
--- a/stock/doctype/item/item.py
+++ b/stock/doctype/item/item.py
@@ -23,7 +23,17 @@
 from webnotes import msgprint, _
 
 from webnotes.model.controller import DocListController
+
+class PriceListCurrencyMismatch(Exception): pass
+
 class DocType(DocListController):
+	def autoname(self):
+		if webnotes.conn.get_default("item_naming_by")=="Naming Series":
+			from webnotes.model.doc import make_autoname
+			self.doc.item_code = make_autoname(self.doc.naming_series+'.#####')
+
+		self.doc.name = self.doc.item_code
+			
 	def validate(self):
 		if not self.doc.stock_uom:
 			msgprint(_("Please enter Default Unit of Measure"), raise_exception=1)
@@ -33,7 +43,7 @@
 		self.add_default_uom_in_conversion_factor_table()
 		self.valiadte_item_type()
 		self.check_for_active_boms()
-		self.check_ref_rate_detail()
+		self.validate_price_lists()
 		self.fill_customer_code()
 		self.check_item_tax()
 		self.validate_barcode()
@@ -121,16 +131,21 @@
 				if cstr(self.doc.fields.get(d)) != 'Yes':
 					_check_for_active_boms(fl[d])
 			
-	def check_ref_rate_detail(self):
-		check_list=[]
+	def validate_price_lists(self):
+		price_lists=[]
 		for d in getlist(self.doclist,'ref_rate_details'):
-			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=1)
+			if d.price_list_name in price_lists:
+				msgprint(_("Cannot have two prices for same Price List") + ": " + d.price_list_name,
+					raise_exception= webnotes.DuplicateEntryError)
 			else:
-				check_list.append([cstr(d.price_list_name),cstr(d.ref_currency)])
-	
+				price_list_currency = webnotes.conn.get_value("Price List", d.price_list_name, "currency")
+				if price_list_currency and d.ref_currency != price_list_currency:
+					msgprint(_("Currency does not match Price List Currency for Price List") \
+						+ ": " + d.price_list_name, raise_exception=PriceListCurrencyMismatch)
+				
+				price_lists.append(d.price_list_name)
+			
+					
 	def fill_customer_code(self):
 		""" Append all the customer codes and insert into "customer_code" field of item table """
 		cust_code=[]
diff --git a/stock/doctype/item/item.txt b/stock/doctype/item/item.txt
index 3497402..274719e 100644
--- a/stock/doctype/item/item.txt
+++ b/stock/doctype/item/item.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-03-28 15:56:38", 
+  "creation": "2013-04-25 10:56:55", 
   "docstatus": 0, 
-  "modified": "2013-04-23 11:44:39", 
+  "modified": "2013-05-02 15:10:53", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -34,7 +34,6 @@
   "parent": "Item", 
   "parentfield": "permissions", 
   "parenttype": "DocType", 
-  "permlevel": 0, 
   "read": 1, 
   "submit": 0
  }, 
@@ -52,6 +51,13 @@
   "read_only": 0
  }, 
  {
+  "doctype": "DocField", 
+  "fieldname": "naming_series", 
+  "fieldtype": "Select", 
+  "label": "Naming Series", 
+  "options": "\nITEM"
+ }, 
+ {
   "description": "Item will be saved by this name in the data base.", 
   "doctype": "DocField", 
   "fieldname": "item_code", 
@@ -878,16 +884,11 @@
   "read_only": 0
  }, 
  {
-  "cancel": 1, 
-  "create": 1, 
-  "doctype": "DocPerm", 
-  "role": "Material Master Manager", 
-  "write": 1
- }, 
- {
   "cancel": 0, 
   "create": 0, 
   "doctype": "DocPerm", 
+  "permlevel": 1, 
+  "report": 0, 
   "role": "Material Manager", 
   "write": 0
  }, 
@@ -895,7 +896,63 @@
   "cancel": 0, 
   "create": 0, 
   "doctype": "DocPerm", 
+  "permlevel": 0, 
+  "report": 1, 
+  "role": "Material Manager", 
+  "write": 0
+ }, 
+ {
+  "cancel": 0, 
+  "create": 0, 
+  "doctype": "DocPerm", 
+  "permlevel": 1, 
+  "report": 0, 
   "role": "Material User", 
   "write": 0
+ }, 
+ {
+  "cancel": 0, 
+  "create": 0, 
+  "doctype": "DocPerm", 
+  "permlevel": 0, 
+  "report": 1, 
+  "role": "Material User", 
+  "write": 0
+ }, 
+ {
+  "cancel": 1, 
+  "create": 1, 
+  "doctype": "DocPerm", 
+  "permlevel": 0, 
+  "report": 1, 
+  "role": "Material Master Manager", 
+  "write": 1
+ }, 
+ {
+  "cancel": 0, 
+  "create": 0, 
+  "doctype": "DocPerm", 
+  "permlevel": 1, 
+  "report": 0, 
+  "role": "Material Master Manager", 
+  "write": 0
+ }, 
+ {
+  "cancel": 1, 
+  "create": 1, 
+  "doctype": "DocPerm", 
+  "permlevel": 0, 
+  "report": 1, 
+  "role": "System Manager", 
+  "write": 1
+ }, 
+ {
+  "cancel": 0, 
+  "create": 0, 
+  "doctype": "DocPerm", 
+  "permlevel": 1, 
+  "report": 0, 
+  "role": "System Manager", 
+  "write": 0
  }
 ]
\ No newline at end of file
diff --git a/stock/doctype/item/test_item.py b/stock/doctype/item/test_item.py
index dbbeecc..f5a688c 100644
--- a/stock/doctype/item/test_item.py
+++ b/stock/doctype/item/test_item.py
@@ -20,6 +20,22 @@
 
 test_ignore = ["BOM"]
 
+class TestItem(unittest.TestCase):
+	def test_duplicate_price_list(self):
+		item = webnotes.bean(copy=test_records[0])
+		item.doc.item_code = "_Test Item 10"
+		item_price = item.doclist.get({"doctype": "Item Price"})[0]
+		item.doclist.append(webnotes.doc(item_price.fields.copy()))
+		self.assertRaises(webnotes.DuplicateEntryError, item.insert)
+
+	def test_price_list_mismatch(self):
+		from stock.doctype.item.item import PriceListCurrencyMismatch
+		item = webnotes.bean(copy=test_records[0])
+		item.doc.item_code = "_Test Item 11"
+		item_price = item.doclist.get({"doctype": "Item Price"})[0].ref_currency="USD"
+		self.assertRaises(PriceListCurrencyMismatch, item.insert)
+
+
 test_records = [
 	[{
 		"doctype": "Item",
@@ -45,7 +61,14 @@
 		"warehouse": "_Test Warehouse",
 		"warehouse_reorder_level": 20,
 		"warehouse_reorder_qty": 20
-	}],
+	}, {
+		"doctype": "Item Price",
+		"parentfield": "ref_rate_details",
+		"price_list_name": "_Test Price List",
+		"ref_rate": 100,
+		"ref_currency": "INR"
+	}
+	],
 	[{
 		"doctype": "Item",
 		"item_code": "_Test Item Home Desktop 100",
diff --git a/stock/doctype/item_price/item_price.txt b/stock/doctype/item_price/item_price.txt
index 721902b..ad0b840 100644
--- a/stock/doctype/item_price/item_price.txt
+++ b/stock/doctype/item_price/item_price.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-03-08 15:37:16", 
+  "creation": "2013-04-29 15:18:04", 
   "docstatus": 0, 
-  "modified": "2013-03-21 17:29:15", 
+  "modified": "2013-04-29 19:16:45", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -68,13 +68,13 @@
   "doctype": "DocField", 
   "fieldname": "selling", 
   "fieldtype": "Check", 
-  "label": "For Selling"
+  "label": "Valid For Selling"
  }, 
  {
   "description": "Allow this price in purchase related forms", 
   "doctype": "DocField", 
   "fieldname": "buying", 
   "fieldtype": "Check", 
-  "label": "For Buying"
+  "label": "Valid For Buying"
  }
 ]
\ No newline at end of file
diff --git a/stock/doctype/material_request/test_material_request.py b/stock/doctype/material_request/test_material_request.py
index 080989f..f5dbb52 100644
--- a/stock/doctype/material_request/test_material_request.py
+++ b/stock/doctype/material_request/test_material_request.py
@@ -263,6 +263,12 @@
 		se = webnotes.bean(copy=se_doclist)
 		self.assertRaises(webnotes.MappingMismatchError, se.insert)
 		
+	def test_warehouse_company_validation(self):
+		from controllers.buying_controller import WrongWarehouseCompany
+		mr = webnotes.bean(copy=test_records[0])
+		mr.doc.company = "_Test Company 1"
+		self.assertRaises(WrongWarehouseCompany, mr.insert)
+		
 test_records = [
 	[
 		{
diff --git a/stock/doctype/stock_ledger/stock_ledger.py b/stock/doctype/stock_ledger/stock_ledger.py
index 3c83de3..8fdb50e 100644
--- a/stock/doctype/stock_ledger/stock_ledger.py
+++ b/stock/doctype/stock_ledger/stock_ledger.py
@@ -114,7 +114,8 @@
 	def update_serial_purchase_details(self, obj, d, serial_no, is_submit, purpose = '', rejected=None):
 		exists = webnotes.conn.sql("select name, status, docstatus from `tabSerial No` where name = '%s'" % (serial_no))
 		if is_submit:
-			if exists and exists[0][2] != 2 and purpose not in ['Material Transfer', 'Sales Return']:
+			if exists and exists[0][2] != 2 and \
+					purpose not in ['Material Transfer', "Material Receipt", 'Sales Return']:
 				msgprint("Serial No: %s already %s" % (serial_no, exists and exists[0][1]), raise_exception = 1)
 			elif exists:
 				s = Document('Serial No', exists and exists[0][0])
diff --git a/stock/doctype/warehouse/test_warehouse.py b/stock/doctype/warehouse/test_warehouse.py
index 26501be..f3a0458 100644
--- a/stock/doctype/warehouse/test_warehouse.py
+++ b/stock/doctype/warehouse/test_warehouse.py
@@ -2,7 +2,8 @@
 	[{
 		"doctype": "Warehouse",
 		"warehouse_name": "_Test Warehouse",
-		"warehouse_type": "_Test Warehouse Type"
+		"warehouse_type": "_Test Warehouse Type",
+		"company": "_Test Company"
 	}],
 	[{
 		"doctype": "Warehouse",
diff --git a/website/doctype/website_settings/website_settings.txt b/website/doctype/website_settings/website_settings.txt
index 615c0a5..9c15480 100644
--- a/website/doctype/website_settings/website_settings.txt
+++ b/website/doctype/website_settings/website_settings.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-03-26 06:51:18", 
+  "creation": "2013-04-30 12:58:46", 
   "docstatus": 0, 
-  "modified": "2013-04-17 11:51:30", 
+  "modified": "2013-05-02 15:51:14", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -219,13 +219,16 @@
   "reqd": 0
  }, 
  {
-  "description": "Enter domain names associated to this website, each on a new line", 
   "doctype": "DocField", 
-  "fieldname": "domain_list", 
-  "fieldtype": "Text", 
-  "hidden": 1, 
-  "label": "Domain List", 
-  "reqd": 0
+  "fieldname": "column_break_28", 
+  "fieldtype": "Column Break"
+ }, 
+ {
+  "description": "Disable Customer Signup link in Login page", 
+  "doctype": "DocField", 
+  "fieldname": "disable_signup", 
+  "fieldtype": "Check", 
+  "label": "Disable Signup"
  }, 
  {
   "create": 1,