Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/accounts/doctype/account/account.py b/accounts/doctype/account/account.py
index ed374b1..70c55e7 100644
--- a/accounts/doctype/account/account.py
+++ b/accounts/doctype/account/account.py
@@ -14,19 +14,15 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import flt, fmt_money
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
+from webnotes import msgprint
 
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
 
 class DocType:
 	def __init__(self,d,dl):
@@ -49,11 +45,6 @@
 			msgprint("Message: Please enter Master Name once the account is created.")
 
 			
-	# Rate is mandatory for tax account	 
-	def validate_rate_for_tax(self):
-		if self.doc.account_type == 'Tax' and not self.doc.tax_rate:
-			msgprint("Please Enter Rate", raise_exception=1)
-
 	# Fetch Parent Details and validation for account not to be created under ledger
 	def validate_parent(self):
 		if self.doc.parent_account:
@@ -135,7 +126,6 @@
 
 	def validate(self): 
 		self.validate_master_name()
-		self.validate_rate_for_tax()
 		self.validate_parent()
 		self.validate_duplicate_account()
 		self.validate_root_details()
diff --git a/accounts/doctype/bank_reconciliation/bank_reconciliation.py b/accounts/doctype/bank_reconciliation/bank_reconciliation.py
index 2314e14..35db6fb 100644
--- a/accounts/doctype/bank_reconciliation/bank_reconciliation.py
+++ b/accounts/doctype/bank_reconciliation/bank_reconciliation.py
@@ -14,24 +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/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr, flt, getdate, now, nowdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
+from webnotes.model.doc import addchild
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/accounts/doctype/budget_control/budget_control.py b/accounts/doctype/budget_control/budget_control.py
index 2f0a3f5..75c938c 100644
--- a/accounts/doctype/budget_control/budget_control.py
+++ b/accounts/doctype/budget_control/budget_control.py
@@ -14,24 +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/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr, flt, getdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/accounts/doctype/c_form/c_form.py b/accounts/doctype/c_form/c_form.py
index d2c9093..a1cc9e8 100644
--- a/accounts/doctype/c_form/c_form.py
+++ b/accounts/doctype/c_form/c_form.py
@@ -14,17 +14,14 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
-from webnotes.utils import add_days, cint, cstr, date_diff, default_fields, flt, getdate, now, nowdate
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
+from webnotes.utils import flt, getdate
+from webnotes.model.doc import make_autoname
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj
-from webnotes import  msgprint, errprint
+from webnotes import  msgprint
 
 sql = webnotes.conn.sql	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/accounts/doctype/form_16a/form_16a.py b/accounts/doctype/form_16a/form_16a.py
index d661f38..4afd361 100644
--- a/accounts/doctype/form_16a/form_16a.py
+++ b/accounts/doctype/form_16a/form_16a.py
@@ -14,24 +14,18 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr, flt, now
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
+from webnotes.model.doc import addchild, make_autoname
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.code import get_obj
+from webnotes import form, msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 from utilities.transaction_base import TransactionBase
 
 class DocType(TransactionBase):
diff --git a/accounts/doctype/gl_control/gl_control.py b/accounts/doctype/gl_control/gl_control.py
index ef6093d..9dec4d5 100644
--- a/accounts/doctype/gl_control/gl_control.py
+++ b/accounts/doctype/gl_control/gl_control.py
@@ -14,22 +14,18 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr, flt, get_defaults, now, sendmail
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist, clone
+from webnotes.model.doc import Document, addchild
+from webnotes.model.wrapper import getlist, copy_doclist
 from webnotes.model.code import get_obj
-from webnotes import session, form, msgprint, errprint
+from webnotes import msgprint
 from webnotes.utils.email_lib import sendmail
 
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 
-# -----------------------------------------------------------------------------------------
 from utilities.transaction_base import TransactionBase
 
 class DocType:
@@ -192,7 +188,7 @@
 
 		# check total debit / credit
 		# Due to old wrong entries (total debit != total credit) some voucher could be cancelled
-		if abs(self.td - self.tc) > 0.01 and not cancel:
+		if abs(self.td - self.tc) > 0.004 and not cancel:
 			msgprint("Debit and Credit not equal for this voucher: Diff (Debit) is %s" % (self.td-self.tc))
 			raise Exception
 
@@ -397,194 +393,3 @@
 			fy_obj = get_obj('Fiscal Year', fy[0])
 			for a in set(ac_list):
 				fy_obj.repost(a)
-
-
-def manage_recurring_invoices():
-	""" 
-		Create recurring invoices on specific date by copying the original one
-		and notify the concerned people
-	"""	
-	rv = webnotes.conn.sql("""select name, recurring_id from `tabSales Invoice` \
-		where ifnull(convert_into_recurring_invoice, 0) = 1 and next_date = %s \
-		and next_date <= ifnull(end_date, '2199-12-31') and docstatus=1""", nowdate())
-	
-	
-	exception_list = []
-	for d in rv:
-		if not webnotes.conn.sql("""select name from `tabSales Invoice` \
-			where posting_date = %s and recurring_id = %s and docstatus=1""", (nowdate(), d[1])):
-			try:
-				prev_rv = get_obj('Sales Invoice', d[0], with_children=1)
-				new_rv = create_new_invoice(prev_rv)
-
-				send_notification(new_rv)
-				webnotes.conn.commit()
-			except Exception, e:
-				webnotes.conn.rollback()
-
-				webnotes.conn.begin()
-				webnotes.conn.sql("update `tabSales Invoice` set \
-					convert_into_recurring_invoice = 0 where name = %s", d[0])
-				notify_errors(d[0], prev_rv.doc.owner)
-				webnotes.conn.commit()
-
-				exception_list.append(e)
-			finally:
-				webnotes.conn.begin()
-			
-	if exception_list:
-		exception_message = "\n\n".join([cstr(d) for d in exception_list])
-		raise Exception, exception_message
-		
-		
-def notify_errors(inv, owner):
-	import webnotes
-	import website
-		
-	exception_msg = """
-		Dear User,
-
-		An error occured while creating recurring invoice from %s (at %s).
-
-		May be there are some invalid email ids mentioned in the invoice.
-
-		To stop sending repetitive error notifications from the system, we have unchecked
-		"Convert into Recurring" field in the invoice %s.
-
-
-		Please correct the invoice and make the invoice recurring again. 
-
-		<b>It is necessary to take this action today itself for the above mentioned recurring invoice \
-		to be generated. If delayed, you will have to manually change the "Repeat on Day of Month" field \
-		of this invoice for generating the recurring invoice.</b>
-
-		Regards,
-		Administrator
-		
-	""" % (inv, website.get_site_address(), inv)
-	subj = "[Urgent] Error while creating recurring invoice from %s" % inv
-
-	from webnotes.profile import get_system_managers
-	recipients = get_system_managers()
-	owner_email = webnotes.conn.get_value("Profile", owner, "email")
-	if not owner_email in recipients:
-		recipients.append(owner_email)
-
-	assign_task_to_owner(inv, exception_msg, recipients)
-	sendmail(recipients, subject=subj, msg = exception_msg)
-	
-	
-
-def assign_task_to_owner(inv, msg, users):
-	for d in users:
-		if d.lower() == 'administrator':
-			d = webnotes.conn.sql("select ifnull(email_id, '') \
-				from `tabProfile` where name = 'Administrator'")[0][0]
-		from webnotes.widgets.form import assign_to
-		args = {
-			'assign_to' 	:	d,
-			'doctype'		:	'Sales Invoice',
-			'name'			:	inv,
-			'description'	:	msg,
-			'priority'		:	'Urgent'
-		}
-		assign_to.add(args)
-
-
-def create_new_invoice(prev_rv):
-	# clone rv
-	new_rv = clone(prev_rv)
-
-	mdict = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12}
-	mcount = mdict[prev_rv.doc.recurring_type]
-
-	# update new rv 
-
-	new_rv.doc.posting_date = new_rv.doc.next_date
-	new_rv.doc.aging_date = new_rv.doc.next_date
-	new_rv.doc.due_date = add_days(new_rv.doc.next_date, cint(date_diff(prev_rv.doc.due_date, prev_rv.doc.posting_date)))
-	new_rv.doc.invoice_period_from_date = get_next_date(new_rv.doc.invoice_period_from_date, mcount)
-	new_rv.doc.invoice_period_to_date = get_next_date(new_rv.doc.invoice_period_to_date, mcount)
-	new_rv.doc.owner = prev_rv.doc.owner
-	new_rv.doc.save()
-
-	# submit and after submit
-	new_rv.submit()
-	new_rv.update_after_submit()
-
-	return new_rv
-
-def get_next_date(dt, mcount):
-	import datetime
-	m = getdate(dt).month + mcount
-	y = getdate(dt).year
-	d = getdate(dt).day
-	if m > 12:
-		m, y = m-12, y+1
-	try:
-		next_month_date = datetime.date(y, m, d)
-	except:
-		import calendar
-		last_day = calendar.monthrange(y, m)[1]
-		next_month_date = datetime.date(y, m, last_day)
-	return next_month_date.strftime("%Y-%m-%d")
-
-
-def send_notification(new_rv):
-	"""Notify concerned persons about recurring invoice generation"""
-	subject = "Invoice : " + new_rv.doc.name
-
-	com = new_rv.doc.company   # webnotes.conn.get_value('Control Panel', '', 'letter_head')
-
-	hd = '''<div><h2>%s</h2></div>
-			<div><h3>Invoice: %s</h3></div>
-			<table cellspacing= "5" cellpadding="5"  width = "100%%">
-				<tr>
-					<td width = "50%%"><b>Customer</b><br>%s<br>%s</td>
-					<td width = "50%%">Invoice Date	   : %s<br>Invoice Period : %s to %s <br>Due Date	   : %s</td>
-				</tr>
-			</table>
-		''' % (com, new_rv.doc.name, new_rv.doc.customer_name, new_rv.doc.address_display, getdate(new_rv.doc.posting_date).strftime("%d-%m-%Y"), \
-		getdate(new_rv.doc.invoice_period_from_date).strftime("%d-%m-%Y"), getdate(new_rv.doc.invoice_period_to_date).strftime("%d-%m-%Y"),\
-		getdate(new_rv.doc.due_date).strftime("%d-%m-%Y"))
-	
-	
-	tbl = '''<table border="1px solid #CCC" width="100%%" cellpadding="0px" cellspacing="0px">
-				<tr>
-					<td width = "15%%" bgcolor="#CCC" align="left"><b>Item</b></td>
-					<td width = "40%%" bgcolor="#CCC" align="left"><b>Description</b></td>
-					<td width = "15%%" bgcolor="#CCC" align="center"><b>Qty</b></td>
-					<td width = "15%%" bgcolor="#CCC" align="center"><b>Rate</b></td>
-					<td width = "15%%" bgcolor="#CCC" align="center"><b>Amount</b></td>
-				</tr>
-		'''
-	for d in getlist(new_rv.doclist, 'entries'):
-		tbl += '<tr><td>' + d.item_code +'</td><td>' + d.description+'</td><td>' + cstr(d.qty) +'</td><td>' + cstr(d.basic_rate) +'</td><td>' + cstr(d.amount) +'</td></tr>'
-	tbl += '</table>'
-
-	totals =''' <table cellspacing= "5" cellpadding="5"  width = "100%%">
-					<tr>
-						<td width = "50%%"></td>
-						<td width = "50%%">
-							<table width = "100%%">
-								<tr>
-									<td width = "50%%">Net Total: </td><td>%s </td>
-								</tr><tr>
-									<td width = "50%%">Total Tax: </td><td>%s </td>
-								</tr><tr>
-									<td width = "50%%">Grand Total: </td><td>%s</td>
-								</tr><tr>
-									<td width = "50%%">In Words: </td><td>%s</td>
-								</tr>
-							</table>
-						</td>
-					</tr>
-					<tr><td>Terms and Conditions:</td></tr>
-					<tr><td>%s</td></tr>
-				</table>
-			''' % (new_rv.doc.net_total, new_rv.doc.other_charges_total,new_rv.doc.grand_total, new_rv.doc.in_words,new_rv.doc.terms)
-
-
-	msg = hd + tbl + totals
-	recipients = new_rv.doc.notification_email_address.replace('\n', '').replace(' ', '').split(",")
-	sendmail(recipients, subject=subject, msg = msg)
diff --git a/accounts/doctype/gl_entry/gl_entry.py b/accounts/doctype/gl_entry/gl_entry.py
index e0de53d..4e20f1b 100644
--- a/accounts/doctype/gl_entry/gl_entry.py
+++ b/accounts/doctype/gl_entry/gl_entry.py
@@ -14,24 +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/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import flt, fmt_money, get_first_day, get_last_day, getdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/accounts/doctype/journal_voucher/journal_voucher.py b/accounts/doctype/journal_voucher/journal_voucher.py
index c9d76cd..450b8b8 100644
--- a/accounts/doctype/journal_voucher/journal_voucher.py
+++ b/accounts/doctype/journal_voucher/journal_voucher.py
@@ -14,24 +14,18 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.	If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import cint, cstr, flt, fmt_money, formatdate, getTraceback, get_defaults, getdate, has_common, month_name, now, nowdate, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cint, cstr, flt, fmt_money, formatdate, getdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
+from webnotes.model.doc import addchild, make_autoname
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.code import get_obj
+from webnotes import form, msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 from utilities.transaction_base import TransactionBase
 
 class DocType:
diff --git a/accounts/doctype/journal_voucher/test_journal_voucher.py b/accounts/doctype/journal_voucher/test_journal_voucher.py
index 3f32dfa..e043e9f 100644
--- a/accounts/doctype/journal_voucher/test_journal_voucher.py
+++ b/accounts/doctype/journal_voucher/test_journal_voucher.py
@@ -14,7 +14,6 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 
 from __future__ import unicode_literals
 import unittest
diff --git a/accounts/doctype/mis_control/mis_control.py b/accounts/doctype/mis_control/mis_control.py
index e25c585..a860c82 100644
--- a/accounts/doctype/mis_control/mis_control.py
+++ b/accounts/doctype/mis_control/mis_control.py
@@ -14,22 +14,15 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.	If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cint, cstr, flt, get_defaults, get_first_day, get_last_day, has_common
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
+from webnotes import session, msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 
 from accounts.utils import get_balance_on, get_fiscal_year
 
diff --git a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py
index 7ffc8e4..005b981 100644
--- a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py
+++ b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py
@@ -14,24 +14,18 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import flt
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
+from webnotes.model.doc import addchild
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/accounts/doctype/period_closing_voucher/period_closing_voucher.py b/accounts/doctype/period_closing_voucher/period_closing_voucher.py
index e751a75..80e993a 100644
--- a/accounts/doctype/period_closing_voucher/period_closing_voucher.py
+++ b/accounts/doctype/period_closing_voucher/period_closing_voucher.py
@@ -14,24 +14,18 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.	If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr, flt, getdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.doc import Document
+from webnotes.model.wrapper import copy_doclist
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/accounts/doctype/pos_setting/pos_setting.py b/accounts/doctype/pos_setting/pos_setting.py
index 4a2cc1f..7f820fe 100755
--- a/accounts/doctype/pos_setting/pos_setting.py
+++ b/accounts/doctype/pos_setting/pos_setting.py
@@ -14,24 +14,15 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py
index fc1d332..cf34cf6 100644
--- a/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -14,24 +14,18 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import add_days, cint, cstr, flt, formatdate, get_defaults
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
+from webnotes.model.doc import Document, make_autoname
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.code import get_obj
+from webnotes import form, msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 from utilities.transaction_base import TransactionBase
 
diff --git a/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.py b/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.py
index b40873a..faf06fd 100644
--- a/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.py
+++ b/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.py
@@ -14,24 +14,15 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
+from webnotes.model.code import get_obj
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/accounts/doctype/sales_invoice/sales_invoice.js b/accounts/doctype/sales_invoice/sales_invoice.js
index ad774fe..e763440 100644
--- a/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/accounts/doctype/sales_invoice/sales_invoice.js
@@ -25,7 +25,6 @@
 wn.require('app/selling/doctype/sales_common/sales_common.js');
 wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js');
 wn.require('app/utilities/doctype/sms_control/sms_control.js');
-wn.require('app/setup/doctype/notification_control/notification_control.js');
 
 // On Load
 // -------
@@ -94,8 +93,6 @@
 		for(f in item_flds_normal) cur_frm.fields_dict['entries'].grid.set_column_disp(item_flds_normal[f], true);
 		for(f in item_flds_pos) cur_frm.fields_dict['entries'].grid.set_column_disp(item_flds_pos[f], false);
 	}
-	if (doc.docstatus==1) unhide_field('recurring_invoice');
-	else hide_field('recurring_invoice');
 
 	if(doc.customer) unhide_field('contact_section');
 	else hide_field('contact_section');
@@ -499,25 +496,34 @@
 	wn.set_route('Report', 'GL Entry', 'General Ledger', 'Voucher No='+cur_frm.doc.name);
 }
 
-// Default values for recurring invoices
-cur_frm.cscript.convert_into_recurring_invoice = function(doc, dt, dn) {
-	if (doc.convert_into_recurring_invoice)
-		get_server_fields('set_default_recurring_values','','',doc, dt, dn, 0);
+cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
+	if(cint(wn.boot.notification_settings.sales_invoice)) {
+		cur_frm.email_doc(wn.boot.notification_settings.sales_invoice);
+	}
 }
 
-cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
-	var args = {
-		type: 'Sales Invoice',
-		doctype: 'Sales Invoice'
+cur_frm.cscript.convert_into_recurring_invoice = function(doc, dt, dn) {
+	// set default values for recurring invoices
+	if(doc.convert_into_recurring_invoice) {
+		var owner_email = doc.owner=="Administrator"
+			? wn.user_info("Administrator").email
+			: doc.owner;
+		
+		doc.notification_email_address = $.map([cstr(owner_email),
+			cstr(doc.contact_email)], function(v) { return v || null; }).join(", ");
+		doc.repeat_on_day_of_month = wn.datetime.str_to_obj(doc.posting_date).getDate();
 	}
-	cur_frm.cscript.notify(doc, args);
+		
+	refresh_many(["notification_email_address", "repeat_on_day_of_month"]);
 }
 
 cur_frm.cscript.invoice_period_from_date = function(doc, dt, dn) {
+	// set invoice_period_to_date
 	if(doc.invoice_period_from_date) {
-		var recurring_type_map = { 'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12 };
+		var recurring_type_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6,
+			'Yearly': 12};
 
-		var months = $(recurring_type_map).attr(doc.recurring_type);
+		var months = recurring_type_map[doc.recurring_type];
 		if(months) {
 			var to_date = wn.datetime.add_months(doc.invoice_period_from_date,
 				months);
@@ -525,4 +531,4 @@
 			refresh_field('invoice_period_to_date');
 		}
 	}
-}
\ No newline at end of file
+}
diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py
index 3763abb..eb7268b 100644
--- a/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/accounts/doctype/sales_invoice/sales_invoice.py
@@ -14,22 +14,23 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr,date_diff, default_fields, flt, fmt_money, formatdate,getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common,month_name, now, nowdate, replace_newlines, sendmail, set_default,str_esc_quote, user_format, validate_email_add
-from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.utils import add_days, cint, cstr, date_diff, flt, getTraceback, getdate, now, nowdate, sendmail, validate_email_add
 
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
+from webnotes.utils import comma_and
+from webnotes import _
+from webnotes.model import db_exists
+from webnotes.model.doc import make_autoname
+from webnotes.model.wrapper import getlist, copy_doclist
+from webnotes.model.code import get_obj
+from webnotes import session, form, msgprint
+
 session = webnotes.session
 
-# -----------------------------------------------------------------------------------------
+month_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12}
+
 
 from utilities.transaction_base import TransactionBase
 
@@ -40,10 +41,92 @@
 		self.tname = 'Sales Invoice Item'
 		self.fname = 'entries'
 
-
 	def autoname(self):
 		self.doc.name = make_autoname(self.doc.naming_series+ '.#####')
+		
+	def validate(self):
+		self.so_dn_required()
+		self.validate_proj_cust()
+		sales_com_obj = get_obj('Sales Common')
+		sales_com_obj.check_stop_sales_order(self)
+		sales_com_obj.check_active_sales_items(self)
+		sales_com_obj.check_conversion_rate(self)
+		sales_com_obj.validate_max_discount(self, 'entries')	 #verify whether rate is not greater than tolerance
+		sales_com_obj.get_allocated_sum(self)	# this is to verify that the allocated % of sales persons is 100%
+		sales_com_obj.validate_fiscal_year(self.doc.fiscal_year,self.doc.posting_date,'Posting Date')
+		self.validate_customer()
+		self.validate_customer_account()
+		self.validate_debit_acc()
+		self.validate_fixed_asset_account()
+		self.add_remarks()
+		if cint(self.doc.is_pos):
+			self.validate_pos()
+			self.validate_write_off_account()
+			if cint(self.doc.update_stock):
+				sl = get_obj('Stock Ledger')
+				sl.validate_serial_no(self, 'entries')
+				sl.validate_serial_no(self, 'packing_details')
+				self.validate_item_code()
+				self.update_current_stock()
+				self.validate_delivery_note()
+		self.set_in_words()
+		if not self.doc.is_opening:
+			self.doc.is_opening = 'No'
+		self.set_aging_date()
+		self.clear_advances()
+		self.set_against_income_account()
+		self.validate_c_form()
+		self.validate_recurring_invoice()
+		
+	def on_submit(self):
+		if cint(self.doc.is_pos) == 1:
+			if cint(self.doc.update_stock) == 1:
+				sl_obj = get_obj("Stock Ledger")
+				sl_obj.validate_serial_no_warehouse(self, 'entries')
+				sl_obj.validate_serial_no_warehouse(self, 'packing_details')
+				
+				sl_obj.update_serial_record(self, 'entries', is_submit = 1, is_incoming = 0)
+				sl_obj.update_serial_record(self, 'packing_details', is_submit = 1, is_incoming = 0)
+				
+				self.update_stock_ledger(update_stock=1)
+		else:
+			# Check for Approving Authority
+			if not self.doc.recurring_id:
+				get_obj('Authorization Control').validate_approving_authority(self.doc.doctype, self.doc.company, self.doc.grand_total, self)
 
+		self.check_prev_docstatus()
+		get_obj("Sales Common").update_prevdoc_detail(1,self)
+		
+		# this sequence because outstanding may get -ve		
+		self.make_gl_entries()
+
+		if not cint(self.doc.is_pos) == 1:
+			self.update_against_document_in_jv()
+
+		self.update_c_form()
+		
+		self.convert_to_recurring()
+
+
+	def on_cancel(self):
+		if cint(self.doc.is_pos) == 1:
+			if cint(self.doc.update_stock) == 1:
+				sl = get_obj('Stock Ledger')
+				sl.update_serial_record(self, 'entries', is_submit = 0, is_incoming = 0)
+				sl.update_serial_record(self, 'packing_details', is_submit = 0, is_incoming = 0)
+				
+				self.update_stock_ledger(update_stock = -1)
+		
+		sales_com_obj = get_obj(dt = 'Sales Common')
+		sales_com_obj.check_stop_sales_order(self)
+		self.check_next_docstatus()
+		sales_com_obj.update_prevdoc_detail(0, self)
+
+		self.make_gl_entries(is_cancel=1)
+
+	def on_update_after_submit(self):
+		self.validate_recurring_invoice()
+		self.convert_to_recurring()
 
 	def set_pos_fields(self):
 		"""Set retail related fields from pos settings"""
@@ -428,40 +511,6 @@
 			d.projected_qty = bin and flt(bin[0]['projected_qty']) or 0
 	 
 	
-	def validate(self):
-		self.so_dn_required()
-		self.validate_proj_cust()
-		sales_com_obj = get_obj('Sales Common')
-		sales_com_obj.check_stop_sales_order(self)
-		sales_com_obj.check_active_sales_items(self)
-		sales_com_obj.check_conversion_rate(self)
-		sales_com_obj.validate_max_discount(self, 'entries')	 #verify whether rate is not greater than tolerance
-		sales_com_obj.get_allocated_sum(self)	# this is to verify that the allocated % of sales persons is 100%
-		sales_com_obj.validate_fiscal_year(self.doc.fiscal_year,self.doc.posting_date,'Posting Date')
-		self.validate_customer()
-		self.validate_customer_account()
-		self.validate_debit_acc()
-		self.validate_fixed_asset_account()
-		self.add_remarks()
-		if cint(self.doc.is_pos):
-			self.validate_pos()
-			self.validate_write_off_account()
-			if cint(self.doc.update_stock):
-				sl = get_obj('Stock Ledger')
-				sl.validate_serial_no(self, 'entries')
-				sl.validate_serial_no(self, 'packing_details')
-				self.validate_item_code()
-				self.update_current_stock()
-				self.validate_delivery_note()
-		self.set_in_words()
-		if not self.doc.is_opening:
-			self.doc.is_opening = 'No'
-		self.set_aging_date()
-		self.clear_advances()
-		self.set_against_income_account()
-		self.validate_c_form()
-
-
 	def get_warehouse(self):
 		w = webnotes.conn.sql("select warehouse from `tabPOS Setting` where ifnull(user,'') = '%s' and company = '%s'" % (session['user'], self.doc.company))
 		w = w and w[0][0] or ''
@@ -598,114 +647,255 @@
 		if submit_jv:
 			msgprint("Journal Voucher : " + cstr(submit_jv[0][0]) + " has been created against " + cstr(self.doc.doctype) + ". So " + cstr(self.doc.doctype) + " cannot be Cancelled.")
 			raise Exception, "Validation Error."
-
-
-	def on_submit(self):
-		if cint(self.doc.is_pos) == 1:
-			if cint(self.doc.update_stock) == 1:
-				sl_obj = get_obj("Stock Ledger")
-				sl_obj.validate_serial_no_warehouse(self, 'entries')
-				sl_obj.validate_serial_no_warehouse(self, 'packing_details')
-				
-				sl_obj.update_serial_record(self, 'entries', is_submit = 1, is_incoming = 0)
-				sl_obj.update_serial_record(self, 'packing_details', is_submit = 1, is_incoming = 0)
-				
-				self.update_stock_ledger(update_stock=1)
-		else:
-			# Check for Approving Authority
+	
+	@property
+	def meta(self):
+		if not hasattr(self, "_meta"):
+			self._meta = webnotes.get_doctype(self.doc.doctype)
+		return self._meta
+	
+	def validate_recurring_invoice(self):
+		if self.doc.convert_into_recurring_invoice:
+			self.validate_notification_email_id()
+		
+			if not self.doc.recurring_type:
+				msgprint(_("Please select: ") + self.meta.get_label("recurring_type"),
+				raise_exception=1)
+		
+			elif not (self.doc.invoice_period_from_date and \
+					self.doc.invoice_period_to_date):
+				msgprint(comma_and([self.meta.get_label("invoice_period_from_date"),
+					self.meta.get_label("invoice_period_to_date")])
+					+ _(": Mandatory for a Recurring Invoice."),
+					raise_exception=True)
+	
+	def convert_to_recurring(self):
+		if self.doc.convert_into_recurring_invoice:
 			if not self.doc.recurring_id:
-				get_obj('Authorization Control').validate_approving_authority(self.doc.doctype, self.doc.company, self.doc.grand_total, self)
+				webnotes.conn.set(self.doc, "recurring_id",
+					make_autoname("RECINV/.#####"))
+			
+			self.set_next_date()
 
-		self.check_prev_docstatus()
-		get_obj("Sales Common").update_prevdoc_detail(1,self)
-		
-		# this sequence because outstanding may get -ve		
-		self.make_gl_entries()
-
-		if not cint(self.doc.is_pos) == 1:
-			self.update_against_document_in_jv()
-
-		self.update_c_form()
-
-
-	def on_cancel(self):
-		if cint(self.doc.is_pos) == 1:
-			if cint(self.doc.update_stock) == 1:
-				sl = get_obj('Stock Ledger')
-				sl.update_serial_record(self, 'entries', is_submit = 0, is_incoming = 0)
-				sl.update_serial_record(self, 'packing_details', is_submit = 0, is_incoming = 0)
-				
-				self.update_stock_ledger(update_stock = -1)
-		
-		sales_com_obj = get_obj(dt = 'Sales Common')
-		sales_com_obj.check_stop_sales_order(self)
-		self.check_next_docstatus()
-		sales_com_obj.update_prevdoc_detail(0, self)
-
-		self.make_gl_entries(is_cancel=1)
-
-	def set_default_recurring_values(self):
-		from webnotes.utils import cstr
-
-		owner_email = self.doc.owner
-		if owner_email.lower() == 'administrator':
-			owner_email = cstr(webnotes.conn.get_value("Profile", "Administrator", "email"))
-		
-		ret = {
-			'repeat_on_day_of_month' : getdate(self.doc.posting_date).day,
-			'notification_email_address' : ', '.join([owner_email, cstr(self.doc.contact_email)]),
-		}
-		return ret
-		
+		elif self.doc.recurring_id:
+			webnotes.conn.sql("""update `tabSales Invoice`
+				set convert_into_recurring_invoice = 0
+				where recurring_id = %s""", (self.doc.recurring_id,))
+			
 	def validate_notification_email_id(self):
 		if self.doc.notification_email_address:
+			email_list = filter(None, [cstr(email).strip() for email in
+				self.doc.notification_email_address.replace("\n", "").split(",")])
+			
 			from webnotes.utils import validate_email_add
-			for add in self.doc.notification_email_address.replace('\n', '').replace(' ', '').split(","):
-				if add and not validate_email_add(add):
-					msgprint("%s is not a valid email address" % add, raise_exception=1)
+			for email in email_list:
+				if not validate_email_add(email):
+					msgprint(self.meta.get_label("notification_email_address") \
+						+ " - " + _("Invalid Email Address") + ": \"%s\"" % email,
+						raise_exception=1)
+					
 		else:
 			msgprint("Notification Email Addresses not specified for recurring invoice",
 				raise_exception=1)
-		
-		
-	def on_update_after_submit(self):
-		self.convert_into_recurring()
-		
-		
-	def convert_into_recurring(self):
-		if self.doc.convert_into_recurring_invoice:
-			self.validate_notification_email_id()
-			
-			if not self.doc.recurring_type:
-				msgprint("Please select recurring type", raise_exception=1)
-			elif not self.doc.invoice_period_from_date or not self.doc.invoice_period_to_date:
-				msgprint("Invoice period from date and to date is mandatory for recurring invoice", raise_exception=1)
-			self.set_next_date()
-			if not self.doc.recurring_id:
-				webnotes.conn.set(self.doc, 'recurring_id', make_autoname('RECINV/.#####'))
-		elif self.doc.recurring_id:
-			webnotes.conn.sql("""update `tabSales Invoice` set convert_into_recurring_invoice = 0 where recurring_id = %s""", self.doc.recurring_id)
-
+				
 	def set_next_date(self):
 		""" Set next date on which auto invoice will be created"""
-
 		if not self.doc.repeat_on_day_of_month:
-			msgprint("""Please enter 'Repeat on Day of Month' field value. \nThe day of the month on which auto invoice 
-						will be generated e.g. 05, 28 etc.""", raise_exception=1)
-
-		import datetime
-		mcount = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12}
-		m = getdate(self.doc.posting_date).month + mcount[self.doc.recurring_type]
-		y = getdate(self.doc.posting_date).year
-		if m > 12:
-			m, y = m-12, y+1
-		try:
-			next_date = datetime.date(y, m, cint(self.doc.repeat_on_day_of_month))
-		except:
-			import calendar
-			last_day = calendar.monthrange(y, m)[1]
-			next_date = datetime.date(y, m, last_day)
-		next_date = next_date.strftime("%Y-%m-%d")
-
+			msgprint("""Please enter 'Repeat on Day of Month' field value. 
+				The day of the month on which auto invoice 
+				will be generated e.g. 05, 28 etc.""", raise_exception=1)
+		
+		next_date = get_next_date(self.doc.posting_date,
+			month_map[self.doc.recurring_type], cint(self.doc.repeat_on_day_of_month))
 		webnotes.conn.set(self.doc, 'next_date', next_date)
+	
+def get_next_date(dt, mcount, day=None):
+	import datetime
+	month = getdate(dt).month + mcount
+	year = getdate(dt).year
+	if not day:
+		day = getdate(dt).day
+	if month > 12:
+		month, year = m-12, y+1
+	try:
+		next_month_date = datetime.date(year, month, day)
+	except:
+		import calendar
+		last_day = calendar.monthrange(year, month)[1]
+		next_month_date = datetime.date(year, month, last_day)
+	return next_month_date.strftime("%Y-%m-%d")
+
+def manage_recurring_invoices():
+	""" 
+		Create recurring invoices on specific date by copying the original one
+		and notify the concerned people
+	"""
+	recurring_invoices = webnotes.conn.sql("""select name, recurring_id
+		from `tabSales Invoice` where ifnull(convert_into_recurring_invoice, 0)=1
+		and docstatus=1 and next_date=%s
+		and next_date <= ifnull(end_date, '2199-12-31')""", nowdate())
+	
+	exception_list = []
+	for ref_invoice, recurring_id in recurring_invoices:
+		if not webnotes.conn.sql("""select name from `tabSales Invoice`
+				where posting_date=%s and recurring_id=%s and docstatus=1""",
+				(nowdate(), recurring_id)):
+			try:
+				ref_wrapper = webnotes.model_wrapper('Sales Invoice', ref_invoice)
+				new_invoice_wrapper = make_new_invoice(ref_wrapper)
+				send_notification(new_invoice_wrapper)
+				webnotes.conn.commit()
+			except Exception, e:
+				webnotes.conn.rollback()
+
+				webnotes.conn.begin()
+				webnotes.conn.sql("update `tabSales Invoice` set \
+					convert_into_recurring_invoice = 0 where name = %s", ref_invoice)
+				notify_errors(ref_invoice, ref_wrapper.doc.owner)
+				webnotes.conn.commit()
+
+				exception_list.append(webnotes.getTraceback())
+			finally:
+				webnotes.conn.begin()
+			
+	if exception_list:
+		exception_message = "\n\n".join([cstr(d) for d in exception_list])
+		raise Exception, exception_message
+
+def make_new_invoice(ref_wrapper):
+	from webnotes.model.wrapper import clone
+	new_invoice = clone(ref_wrapper)
+	
+	mcount = month_map[ref_wrapper.doc.recurring_type]
+	
+	today = nowdate()
+	
+	new_invoice.doc.fields.update({
+		"posting_date": today,
+		"aging_date": today,
+		
+		"due_date": add_days(today, cint(date_diff(ref_wrapper.doc.due_date,
+			ref_wrapper.doc.posting_date))),
+			
+		"invoice_period_from_date": \
+			get_next_date(ref_wrapper.doc.invoice_period_from_date, mcount),
+			
+		"invoice_period_to_date": \
+			get_next_date(ref_wrapper.doc.invoice_period_to_date, mcount),
+		
+		"owner": ref_wrapper.doc.owner,
+	})
+	
+	new_invoice.submit()
+	
+	return new_invoice
+	
+def send_notification(new_rv):
+	"""Notify concerned persons about recurring invoice generation"""
+	subject = "Invoice : " + new_rv.doc.name
+
+	com = new_rv.doc.company   # webnotes.conn.get_value('Control Panel', '', 'letter_head')
+
+	hd = '''<div><h2>%s</h2></div>
+			<div><h3>Invoice: %s</h3></div>
+			<table cellspacing= "5" cellpadding="5"  width = "100%%">
+				<tr>
+					<td width = "50%%"><b>Customer</b><br>%s<br>%s</td>
+					<td width = "50%%">Invoice Date	   : %s<br>Invoice Period : %s to %s <br>Due Date	   : %s</td>
+				</tr>
+			</table>
+		''' % (com, new_rv.doc.name, new_rv.doc.customer_name, new_rv.doc.address_display, getdate(new_rv.doc.posting_date).strftime("%d-%m-%Y"), \
+		getdate(new_rv.doc.invoice_period_from_date).strftime("%d-%m-%Y"), getdate(new_rv.doc.invoice_period_to_date).strftime("%d-%m-%Y"),\
+		getdate(new_rv.doc.due_date).strftime("%d-%m-%Y"))
+	
+	
+	tbl = '''<table border="1px solid #CCC" width="100%%" cellpadding="0px" cellspacing="0px">
+				<tr>
+					<td width = "15%%" bgcolor="#CCC" align="left"><b>Item</b></td>
+					<td width = "40%%" bgcolor="#CCC" align="left"><b>Description</b></td>
+					<td width = "15%%" bgcolor="#CCC" align="center"><b>Qty</b></td>
+					<td width = "15%%" bgcolor="#CCC" align="center"><b>Rate</b></td>
+					<td width = "15%%" bgcolor="#CCC" align="center"><b>Amount</b></td>
+				</tr>
+		'''
+	for d in getlist(new_rv.doclist, 'entries'):
+		tbl += '<tr><td>' + d.item_code +'</td><td>' + d.description+'</td><td>' + cstr(d.qty) +'</td><td>' + cstr(d.basic_rate) +'</td><td>' + cstr(d.amount) +'</td></tr>'
+	tbl += '</table>'
+
+	totals ='''<table cellspacing= "5" cellpadding="5"  width = "100%%">
+					<tr>
+						<td width = "50%%"></td>
+						<td width = "50%%">
+							<table width = "100%%">
+								<tr>
+									<td width = "50%%">Net Total: </td><td>%s </td>
+								</tr><tr>
+									<td width = "50%%">Total Tax: </td><td>%s </td>
+								</tr><tr>
+									<td width = "50%%">Grand Total: </td><td>%s</td>
+								</tr><tr>
+									<td width = "50%%">In Words: </td><td>%s</td>
+								</tr>
+							</table>
+						</td>
+					</tr>
+					<tr><td>Terms and Conditions:</td></tr>
+					<tr><td>%s</td></tr>
+				</table>
+			''' % (new_rv.doc.net_total,
+			new_rv.doc.other_charges_total,new_rv.doc.grand_total,
+			new_rv.doc.in_words,new_rv.doc.terms)
+
+
+	msg = hd + tbl + totals
+	
+	sendmail(new_rv.doc.notification_email_address, subject=subject, msg = msg)
+		
+def notify_errors(inv, owner):
+	import webnotes
+	import website
+		
+	exception_msg = """
+		Dear User,
+
+		An error occured while creating recurring invoice from %s (at %s).
+
+		May be there are some invalid email ids mentioned in the invoice.
+
+		To stop sending repetitive error notifications from the system, we have unchecked
+		"Convert into Recurring" field in the invoice %s.
+
+
+		Please correct the invoice and make the invoice recurring again. 
+
+		<b>It is necessary to take this action today itself for the above mentioned recurring invoice \
+		to be generated. If delayed, you will have to manually change the "Repeat on Day of Month" field \
+		of this invoice for generating the recurring invoice.</b>
+
+		Regards,
+		Administrator
+		
+	""" % (inv, website.get_site_address(), inv)
+	subj = "[Urgent] Error while creating recurring invoice from %s" % inv
+
+	from webnotes.profile import get_system_managers
+	recipients = get_system_managers()
+	owner_email = webnotes.conn.get_value("Profile", owner, "email")
+	if not owner_email in recipients:
+		recipients.append(owner_email)
+
+	assign_task_to_owner(inv, exception_msg, recipients)
+	sendmail(recipients, subject=subj, msg = exception_msg)
+
+def assign_task_to_owner(inv, msg, users):
+	for d in users:
+		from webnotes.widgets.form import assign_to
+		args = {
+			'assign_to' 	:	d,
+			'doctype'		:	'Sales Invoice',
+			'name'			:	inv,
+			'description'	:	msg,
+			'priority'		:	'Urgent'
+		}
+		assign_to.add(args)
 
diff --git a/accounts/doctype/sales_invoice/sales_invoice.txt b/accounts/doctype/sales_invoice/sales_invoice.txt
index 4790bc6..8851951 100644
--- a/accounts/doctype/sales_invoice/sales_invoice.txt
+++ b/accounts/doctype/sales_invoice/sales_invoice.txt
@@ -2,12 +2,13 @@
  {
   "owner": "Administrator", 
   "docstatus": 0, 
-  "creation": "2012-10-10 10:52:22", 
+  "creation": "2012-09-10 12:22:26", 
   "modified_by": "Administrator", 
-  "modified": "2012-09-07 11:56:59"
+  "modified": "2012-11-30 16:39:08"
  }, 
  {
   "is_submittable": 1, 
+  "autoname": "naming_series:", 
   "allow_attach": 1, 
   "default_print_format": "Standard", 
   "search_fields": "posting_date, due_date, debit_to, fiscal_year, grand_total, outstanding_amount", 
@@ -35,6 +36,15 @@
   "doctype": "DocType"
  }, 
  {
+  "print_hide": 1, 
+  "oldfieldtype": "Section Break", 
+  "doctype": "DocField", 
+  "label": "Basic Info", 
+  "fieldname": "basic_info", 
+  "fieldtype": "Section Break", 
+  "permlevel": 0
+ }, 
+ {
   "print_hide": 0, 
   "oldfieldtype": "Column Break", 
   "doctype": "DocField", 
@@ -217,9 +227,9 @@
   "permlevel": 0
  }, 
  {
-  "allow_on_submit": 1, 
   "oldfieldtype": "Table", 
   "colour": "White:FFF", 
+  "allow_on_submit": 1, 
   "doctype": "DocField", 
   "label": "Entries", 
   "oldfieldname": "entries", 
@@ -428,9 +438,9 @@
   "permlevel": 0
  }, 
  {
-  "allow_on_submit": 1, 
   "oldfieldtype": "Table", 
   "colour": "White:FFF", 
+  "allow_on_submit": 1, 
   "doctype": "DocField", 
   "label": "Taxes and Charges1", 
   "oldfieldname": "other_charges", 
@@ -1174,6 +1184,7 @@
  }, 
  {
   "print_hide": 1, 
+  "depends_on": "eval:doc.docstatus<2", 
   "colour": "White:FFF", 
   "doctype": "DocField", 
   "label": "Recurring Invoice", 
@@ -1193,7 +1204,7 @@
   "print_hide": 1, 
   "description": "Check if recurring invoice, uncheck to stop recurring or put proper End Date", 
   "no_copy": 1, 
-  "depends_on": "eval:doc.docstatus==1", 
+  "depends_on": "eval:doc.docstatus<2", 
   "colour": "White:FFF", 
   "allow_on_submit": 1, 
   "doctype": "DocField", 
@@ -1205,23 +1216,24 @@
  }, 
  {
   "print_hide": 1, 
-  "allow_on_submit": 1, 
   "description": "Select the period when the invoice will be generated automatically", 
   "no_copy": 1, 
   "depends_on": "eval:doc.convert_into_recurring_invoice==1", 
+  "colour": "White:FFF", 
+  "allow_on_submit": 1, 
   "doctype": "DocField", 
   "label": "Recurring Type", 
-  "options": "Monthly\nQuarterly\nHalf-yearly\nYearly", 
+  "permlevel": 0, 
   "fieldname": "recurring_type", 
   "fieldtype": "Select", 
-  "permlevel": 0
+  "options": "Monthly\nQuarterly\nHalf-yearly\nYearly"
  }, 
  {
   "print_hide": 1, 
-  "allow_on_submit": 1, 
   "description": "The day of the month on which auto invoice will be generated e.g. 05, 28 etc ", 
   "no_copy": 1, 
   "depends_on": "eval:doc.convert_into_recurring_invoice==1", 
+  "allow_on_submit": 1, 
   "doctype": "DocField", 
   "label": "Repeat on Day of Month", 
   "fieldname": "repeat_on_day_of_month", 
@@ -1230,11 +1242,11 @@
  }, 
  {
   "print_hide": 1, 
-  "allow_on_submit": 1, 
-  "description": "Start date of the invoice period", 
+  "description": "Start date of current invoice's period", 
   "no_copy": 1, 
   "depends_on": "eval:doc.convert_into_recurring_invoice==1", 
   "colour": "White:FFF", 
+  "allow_on_submit": 1, 
   "doctype": "DocField", 
   "label": "Invoice Period From Date", 
   "fieldname": "invoice_period_from_date", 
@@ -1243,10 +1255,11 @@
  }, 
  {
   "print_hide": 1, 
-  "allow_on_submit": 1, 
-  "description": "End date of the invoice period", 
+  "description": "End date of current invoice's period", 
   "no_copy": 1, 
   "depends_on": "eval:doc.convert_into_recurring_invoice==1", 
+  "colour": "White:FFF", 
+  "allow_on_submit": 1, 
   "doctype": "DocField", 
   "label": "Invoice Period To Date", 
   "fieldname": "invoice_period_to_date", 
@@ -1264,10 +1277,10 @@
  }, 
  {
   "print_hide": 1, 
-  "allow_on_submit": 1, 
   "description": "Enter email id separated by commas, invoice will be mailed automatically on particular date", 
   "no_copy": 1, 
   "depends_on": "eval:doc.convert_into_recurring_invoice==1", 
+  "allow_on_submit": 1, 
   "doctype": "DocField", 
   "label": "Notification Email Address", 
   "fieldname": "notification_email_address", 
@@ -1276,9 +1289,10 @@
  }, 
  {
   "print_hide": 1, 
-  "description": "The unique id for tracking all recurring invoices ", 
+  "description": "The unique id for tracking all recurring invoices.\u00a0It is generated on submit.", 
   "no_copy": 1, 
   "depends_on": "eval:doc.convert_into_recurring_invoice==1", 
+  "colour": "White:FFF", 
   "doctype": "DocField", 
   "label": "Recurring Id", 
   "fieldname": "recurring_id", 
@@ -1287,9 +1301,10 @@
  }, 
  {
   "print_hide": 1, 
-  "description": "The date on which next invoice will be generated ", 
+  "description": "The date on which next invoice will be generated. It is generated on submit.\n", 
   "no_copy": 1, 
   "depends_on": "eval:doc.convert_into_recurring_invoice==1", 
+  "colour": "White:FFF", 
   "doctype": "DocField", 
   "label": "Next Date", 
   "fieldname": "next_date", 
@@ -1298,10 +1313,10 @@
  }, 
  {
   "print_hide": 1, 
-  "allow_on_submit": 1, 
   "description": "The date on which recurring invoice will be stop", 
   "no_copy": 1, 
   "depends_on": "eval:doc.convert_into_recurring_invoice==1", 
+  "allow_on_submit": 1, 
   "doctype": "DocField", 
   "label": "End Date", 
   "fieldname": "end_date", 
diff --git a/accounts/doctype/tds_category/tds_category.py b/accounts/doctype/tds_category/tds_category.py
index c64d4bb..3b23c38 100644
--- a/accounts/doctype/tds_category/tds_category.py
+++ b/accounts/doctype/tds_category/tds_category.py
@@ -14,24 +14,14 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/accounts/doctype/tds_control/tds_control.py b/accounts/doctype/tds_control/tds_control.py
index d9c654b..1aaa2e5 100644
--- a/accounts/doctype/tds_control/tds_control.py
+++ b/accounts/doctype/tds_control/tds_control.py
@@ -14,24 +14,16 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr, flt, getdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/accounts/doctype/tds_payment/tds_payment.py b/accounts/doctype/tds_payment/tds_payment.py
index b367b0d..a3b0080 100644
--- a/accounts/doctype/tds_payment/tds_payment.py
+++ b/accounts/doctype/tds_payment/tds_payment.py
@@ -14,24 +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/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr, flt, now
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
+from webnotes.model.doc import addchild, make_autoname
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/accounts/doctype/trend_analyzer_control/trend_analyzer_control.py b/accounts/doctype/trend_analyzer_control/trend_analyzer_control.py
index e10d2cb..f43542f 100755
--- a/accounts/doctype/trend_analyzer_control/trend_analyzer_control.py
+++ b/accounts/doctype/trend_analyzer_control/trend_analyzer_control.py
@@ -14,24 +14,15 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import add_days, add_months, cint, cstr, month_name
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 class DocType:
         def __init__(self, d, dl):
diff --git a/accounts/page/accounts_browser/accounts_browser.js b/accounts/page/accounts_browser/accounts_browser.js
index 3ef5045..323135b 100644
--- a/accounts/page/accounts_browser/accounts_browser.js
+++ b/accounts/page/accounts_browser/accounts_browser.js
@@ -185,9 +185,9 @@
 		// tax rate if tax
 		$(fd.account_type.input).change(function() {
 			if($(this).val()=='Tax') {
-				$(fd.tax_rate.wrapper).toggle(true);				
+				$(fd.tax_rate.wrapper).toggle(true);
 			} else {
-				$(fd.tax_rate.wrapper).toggle(false);				
+				$(fd.tax_rate.wrapper).toggle(false);
 			}
 		})
 		
@@ -214,6 +214,7 @@
 		// show
 		d.onshow = function() {
 			$(fd.group_or_ledger.input).change();
+			$(fd.account_type.input).change();
 		}
 		d.show();
 	},
diff --git a/accounts/page/voucher_import_tool/voucher_import_tool.py b/accounts/page/voucher_import_tool/voucher_import_tool.py
index 41d0a9f..5f66c7a 100644
--- a/accounts/page/voucher_import_tool/voucher_import_tool.py
+++ b/accounts/page/voucher_import_tool/voucher_import_tool.py
@@ -1,14 +1,14 @@
 from __future__ import unicode_literals
 import webnotes
-from webnotes.utils import formatdate, flt
+from webnotes.utils import flt
 
 @webnotes.whitelist()
 def get_template():
 	"""download template"""
 	template_type = webnotes.form_dict.get('type')
-	from webnotes.model.doctype import get_field_property
-	naming_options = get_field_property("Journal Voucher", "naming_series", "options")
-	voucher_type = get_field_property("Journal Voucher", "voucher_type", "options")
+	from webnotes.model.doctype import get_property
+	naming_options = get_property("Journal Voucher", "naming_series", "options")
+	voucher_type = get_property("Journal Voucher", "voucher_type", "options")
 	if template_type=="Two Accounts":
 		extra_note = ""
 		columns = '''"Naming Series","Voucher Type","Posting Date","Amount","Debit Account","Credit Account","Cost Center","Against Sales Invoice","Against Purchase Invoice","Against Journal Voucher","Remarks","Due Date","Ref Number","Ref Date"'''
@@ -64,7 +64,6 @@
 def import_vouchers(common_values, data, start_idx, import_type):
 	from webnotes.model.doc import Document
 	from webnotes.model.wrapper import ModelWrapper
-	from webnotes.model.code import get_obj
 	from accounts.utils import get_fiscal_year
 	from webnotes.utils.dateutils import parse_date
 
diff --git a/accounts/search_criteria/purchase_register/purchase_register.py b/accounts/search_criteria/purchase_register/purchase_register.py
index 9c33e2a..93fc323 100644
--- a/accounts/search_criteria/purchase_register/purchase_register.py
+++ b/accounts/search_criteria/purchase_register/purchase_register.py
@@ -16,7 +16,7 @@
 
 # add expense head columns
 from __future__ import unicode_literals
-from webnotes.utils import flt, cint, cstr
+from webnotes.utils import flt
 
 expense_acc = [c[0] for c in sql("""select distinct expense_head 
 									from `tabPurchase Invoice Item` 
diff --git a/accounts/search_criteria/sales_register/sales_register.py b/accounts/search_criteria/sales_register/sales_register.py
index ef9374a..f9cbc5d 100644
--- a/accounts/search_criteria/sales_register/sales_register.py
+++ b/accounts/search_criteria/sales_register/sales_register.py
@@ -16,7 +16,7 @@
 
 # add additional columns
 from __future__ import unicode_literals
-from webnotes.utils import flt, cint, cstr
+from webnotes.utils import flt
 
 cl = [c[0] for c in sql("""select distinct account_head 
 						   from `tabSales Taxes and Charges` 
diff --git a/accounts/search_criteria/yearly_transaction_summary/yearly_transaction_summary.py b/accounts/search_criteria/yearly_transaction_summary/yearly_transaction_summary.py
index 1e163b3..166d313 100644
--- a/accounts/search_criteria/yearly_transaction_summary/yearly_transaction_summary.py
+++ b/accounts/search_criteria/yearly_transaction_summary/yearly_transaction_summary.py
@@ -30,8 +30,7 @@
   if from_date != "" and to_date != "":
     get_obj('MIS Control').dates(from_fiscal_year,from_date,to_date) # validate dates (i.e. dates should be between particular fiscal year)
 	
-# Add columns based on from and to fiscal year
-# --------------------------------------------------------------------------------------------------
+# Add columns based on from and to fiscal year---------
 columns = []
 columns.append(['ID','Data','150px',''])
 columns.append(['Description','Data','150px',''])
diff --git a/buying/doctype/purchase_common/purchase_common.py b/buying/doctype/purchase_common/purchase_common.py
index 0b57b62..b2634b0 100644
--- a/buying/doctype/purchase_common/purchase_common.py
+++ b/buying/doctype/purchase_common/purchase_common.py
@@ -14,24 +14,18 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import add_days, cint, cstr, flt, getdate, now
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
+from webnotes.model.doc import Document, addchild
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.code import get_obj
+from webnotes import form, msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 from utilities.transaction_base import TransactionBase
 
 class DocType(TransactionBase):
diff --git a/buying/doctype/purchase_order/purchase_order.js b/buying/doctype/purchase_order/purchase_order.js
index 584648d..e31cfd7 100644
--- a/buying/doctype/purchase_order/purchase_order.js
+++ b/buying/doctype/purchase_order/purchase_order.js
@@ -21,7 +21,6 @@
 wn.require('app/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js');
 wn.require('app/buying/doctype/purchase_common/purchase_common.js');
 wn.require('app/utilities/doctype/sms_control/sms_control.js');
-wn.require('app/setup/doctype/notification_control/notification_control.js');
 
 cur_frm.cscript.onload = function(doc, cdt, cdn) {
 	// set missing values in parent doc
@@ -220,9 +219,7 @@
 }
 
 cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
-	var args = {
-		type: 'Purchase Order',
-		doctype: 'Purchase Order'
+	if(cint(wn.boot.notification_settings.purchase_order)) {
+		cur_frm.email_doc(wn.boot.notification_settings.purchase_order);
 	}
-	cur_frm.cscript.notify(doc, args);
 }
diff --git a/buying/doctype/purchase_order/purchase_order.py b/buying/doctype/purchase_order/purchase_order.py
index b09c4b5..c49c054 100644
--- a/buying/doctype/purchase_order/purchase_order.py
+++ b/buying/doctype/purchase_order/purchase_order.py
@@ -14,24 +14,18 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr, date_diff, flt, get_defaults, now
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
+from webnotes.model.doc import addchild, make_autoname
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 from utilities.transaction_base import TransactionBase
 
diff --git a/buying/doctype/purchase_request/purchase_request.py b/buying/doctype/purchase_request/purchase_request.py
index 4a9b96d..f30b722 100644
--- a/buying/doctype/purchase_request/purchase_request.py
+++ b/buying/doctype/purchase_request/purchase_request.py
@@ -14,24 +14,18 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr, date_diff, flt, get_defaults, now
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
+from webnotes.model.doc import make_autoname
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/buying/doctype/quality_inspection/quality_inspection.py b/buying/doctype/quality_inspection/quality_inspection.py
index 8fb373a..981bf43 100644
--- a/buying/doctype/quality_inspection/quality_inspection.py
+++ b/buying/doctype/quality_inspection/quality_inspection.py
@@ -14,24 +14,15 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.	If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.doc import addchild, make_autoname
+from webnotes.model.wrapper import copy_doclist
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/buying/doctype/supplier/supplier.js b/buying/doctype/supplier/supplier.js
index 4fd94f5..1b7f369 100644
--- a/buying/doctype/supplier/supplier.js
+++ b/buying/doctype/supplier/supplier.js
@@ -15,7 +15,6 @@
 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 wn.require('app/setup/doctype/contact_control/contact_control.js');
-wn.require('app/support/doctype/communication/communication.js');
 
 cur_frm.cscript.onload = function(doc,dt,dn){
 
@@ -29,7 +28,6 @@
 	// make contact, history list body
 	//cur_frm.cscript.make_cl_body();
 	cur_frm.cscript.make_hl_body();
-	cur_frm.cscript.make_communication_body();
 }
 
 cur_frm.cscript.refresh = function(doc,dt,dn) {
@@ -46,8 +44,13 @@
 		// make lists
 		cur_frm.cscript.make_address(doc,dt,dn);
 		cur_frm.cscript.make_contact(doc,dt,dn);
-		cur_frm.cscript.render_communication_list(doc, cdt, cdn);
 		cur_frm.cscript.make_history(doc,dt,dn);
+		
+		cur_frm.communication_view = new wn.views.CommunicationList({
+			list: wn.model.get("Communication", {"supplier": doc.name}),
+			parent: cur_frm.fields_dict.communication_html.wrapper,
+			doc: doc
+		})		
   }
 }
 
diff --git a/buying/doctype/supplier/supplier.py b/buying/doctype/supplier/supplier.py
index d7f69d6..0251899 100644
--- a/buying/doctype/supplier/supplier.py
+++ b/buying/doctype/supplier/supplier.py
@@ -14,30 +14,25 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
-from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.utils import cstr, get_defaults
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 
-# -----------------------------------------------------------------------------------------
+from utilities.transaction_base import TransactionBase
 
-class DocType:
+class DocType(TransactionBase):
 	def __init__(self, doc, doclist=[]):
 		self.doc = doc
 		self.doclist = doclist
 
+	def onload(self):
+		self.add_communication_list()
+
 	def autoname(self):
 		#get default naming conventional from control panel
 		supp_master_name = get_defaults()['supp_master_name']
@@ -59,22 +54,17 @@
 		else:
 			self.doc.name = make_autoname(self.doc.naming_series+'.#####')
 
-	# ----------------------------------------
-	# update credit days and limit in account
-	# ----------------------------------------
 	def update_credit_days_limit(self):
 		sql("update tabAccount set credit_days = '%s' where name = '%s'" % (self.doc.credit_days, self.doc.name + " - " + self.get_company_abbr()))
 
-
 	def on_update(self):
 		if not self.doc.naming_series:
 			self.doc.naming_series = ''
 
-	
 		# create address
 		addr_flds = [self.doc.address_line1, self.doc.address_line2, self.doc.city, self.doc.state, self.doc.country, self.doc.pincode]
 		address_line = "\n".join(filter(lambda x : (x!='' and x!=None),addr_flds))
-		set(self.doc,'address', address_line)
+		webnotes.conn.set(self.doc,'address', address_line)
 
 		# create account head
 		self.create_account_head()
@@ -82,12 +72,9 @@
 		# update credit days and limit in account
 		self.update_credit_days_limit()
 
-
 	def check_state(self):
 		return "\n" + "\n".join([i[0] for i in sql("select state_name from `tabState` where `tabState`.country='%s' " % self.doc.country)])
 	
-	# ACCOUNTS
-	# -------------------------------------------
 	def get_payables_group(self):
 		g = sql("select payables_group from tabCompany where name=%s", self.doc.company)
 		g = g and g[0][0] or ''
@@ -116,7 +103,6 @@
 		
 		return self.doc.supplier_type + " - " + abbr
 
-
 	def validate(self):
 		#validation for Naming Series mandatory field...
 		if get_defaults()['supp_master_name'] == 'Naming Series':
@@ -124,9 +110,6 @@
 				msgprint("Series is Mandatory.")
 				raise Exception
 	
-	
-	# create accont head - in tree under zone + territory
-	# -------------------------------------------------------
 	def create_account_head(self):
 		if self.doc.company :
 			abbr = self.get_company_abbr() 
@@ -142,7 +125,6 @@
 		else : 
 			msgprint("Please select Company under which you want to create account head")
 			
-			
 	def get_contacts(self,nm):
 		if nm:
 			contact_details =convert_to_lists(sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where supplier = '%s'"%nm))
@@ -172,16 +154,12 @@
 			from webnotes.model import delete_doc
 			delete_doc('Account', acc[0][0])
 			
-			
 	def on_trash(self):
 		self.delete_supplier_address()
 		self.delete_supplier_contact()
 		self.delete_supplier_communication()
 		self.delete_supplier_account()
 		
-		
-	# on rename
-	# ---------
 	def on_rename(self,newdn,olddn):
 		#update supplier_name if not naming series
 		if get_defaults().get('supp_master_name') == 'Supplier Name':
diff --git a/buying/doctype/supplier/supplier.txt b/buying/doctype/supplier/supplier.txt
index 833c127..a46927b 100644
--- a/buying/doctype/supplier/supplier.txt
+++ b/buying/doctype/supplier/supplier.txt
@@ -2,11 +2,12 @@
  {
   "owner": "Administrator", 
   "docstatus": 0, 
-  "creation": "2012-07-18 20:34:42", 
+  "creation": "2012-11-02 17:17:04", 
   "modified_by": "Administrator", 
-  "modified": "2012-07-18 17:41:49"
+  "modified": "2012-11-30 10:53:32"
  }, 
  {
+  "autoname": "naming_series:", 
   "name": "__common__", 
   "search_fields": "supplier_name,supplier_type", 
   "module": "Buying", 
@@ -33,6 +34,16 @@
   "doctype": "DocType"
  }, 
  {
+  "description": "Note: You Can Manage Multiple Address or Contacts via Addresses & Contacts", 
+  "oldfieldtype": "Section Break", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Basic Info", 
+  "fieldname": "basic_info", 
+  "fieldtype": "Section Break", 
+  "permlevel": 0
+ }, 
+ {
   "no_copy": 1, 
   "oldfieldtype": "Data", 
   "doctype": "DocField", 
@@ -124,7 +135,6 @@
  }, 
  {
   "doctype": "DocField", 
-  "label": "Communication History", 
   "fieldname": "communication_history", 
   "fieldtype": "Section Break", 
   "permlevel": 0
@@ -246,8 +256,7 @@
   "write": 1, 
   "role": "Purchase Master Manager", 
   "cancel": 1, 
-  "permlevel": 0, 
-  "match": ""
+  "permlevel": 0
  }, 
  {
   "amend": 0, 
diff --git a/controllers/tax_controller.py b/controllers/tax_controller.py
new file mode 100644
index 0000000..6df17f5
--- /dev/null
+++ b/controllers/tax_controller.py
@@ -0,0 +1,433 @@
+# 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
+import webnotes.model
+from webnotes import _, msgprint
+from webnotes.utils import cint, flt
+from webnotes.model.utils import round_doc
+import json
+
+from controllers.transaction_controller import TransactionController
+
+class TaxController(TransactionController):
+	def append_taxes(self):
+		"""append taxes as per tax master link field"""
+		# clear tax table
+		self.doclist = self.doclist.get({"parentfield": ["!=",
+			self.fmap.taxes_and_charges]})
+		
+		tax_master_doctype = self.meta.get_options(self.fmap.taxes_and_charges_master)
+		master_tax_list = webnotes.get_doclist(tax_master_doctype,
+			self.doc.fields.get(self.fmap.taxes_and_charges_master)).get(
+			{"parentfield": self.fmap.taxes_and_charges})
+			
+		for base_tax in master_tax_list:
+			tax = DictObj([[field, base_tax.fields.get(field)]
+				for field in base_tax.fields
+				if field not in webnotes.model.default_fields])
+			tax.update({
+				"doctype": self.meta.get_options(self.fmap.taxes_and_charges),
+				"parentfield": self.fmap.taxes_and_charges,
+				"rate": flt(tax.rate, self.precision.tax.rate),
+			})
+			self.doclist.append(tax)
+	
+	def calculate_taxes_and_totals(self):
+		"""
+			Calculates:
+				* amount for each item
+				* valuation_tax_amount for each item, 
+				* tax amount and tax total for each tax
+				* net total
+				* total taxes
+				* grand total
+		"""
+		self.doc.fields[self.fmap.exchange_rate] = \
+			flt(self.doc.fields.get(self.fmap.exchange_rate),
+			self.precision.main[self.fmap.exchange_rate])
+		
+		self.calculate_item_values()
+		
+		self.initialize_taxes()
+		if self.meta.get_field("included_in_print_rate",
+				parentfield=self.fmap.taxes_and_charges):
+			self.determine_exclusive_rate()
+		
+		self.calculate_net_total()
+		self.calculate_taxes()
+		self.calculate_totals()
+		self.set_amount_in_words()
+		
+	def calculate_item_values(self):
+		def _set_base(item, print_field, base_field):
+			"""set values in base currency"""
+			item.fields[base_field] = flt((flt(item.fields[print_field],
+				self.precision.item[print_field]) * \
+				self.doc.fields.get(self.fmap.exchange_rate)),
+				self.precision.item[base_field])
+		
+		for item in self.item_doclist:
+			round_doc(item, self.precision.item)
+			
+			if item.fields.get(self.fmap.discount) == 100:
+				if not item.fields.get(self.fmap.print_ref_rate):
+					item.fields[self.fmap.print_ref_rate] = \
+						item.fields.get(self.fmap.print_rate)
+				item.fields[self.fmap.print_rate] = 0
+			else:
+				if item.fields.get(self.fmap.print_ref_rate):
+					item.fields[self.fmap.print_rate] = \
+						flt(item.fields.get(self.fmap.print_ref_rate) *
+						(1.0 - (item.fields.get(self.fmap.discount) / 100.0)),
+						self.precision.item[self.fmap.print_rate])
+				else:
+					# assume that print rate and discount are specified
+					item.fields[self.fmap.print_ref_rate] = \
+						flt(item.fields.get(self.fmap.print_rate) / 
+						(1.0 - (item.fields.get(self.fmap.discount) / 100.0)),
+						self.precision.item[self.fmap.print_ref_rate])
+						
+			item.fields[self.fmap.print_amount] = \
+				flt(item.fields.get(self.fmap.print_rate) * \
+				item.fields.get(self.fmap.qty),
+				self.precision.item[self.fmap.print_amount])
+				
+			_set_base(item, self.fmap.print_ref_rate, self.fmap.ref_rate)
+			_set_base(item, self.fmap.print_rate, self.fmap.rate)
+			_set_base(item, self.fmap.print_amount, self.fmap.amount)
+			
+	def initialize_taxes(self):
+		for tax in self.tax_doclist:
+			# initialize totals to 0
+			tax.tax_amount = tax.total = tax.total_print = 0
+			tax.grand_total_for_current_item = tax.tax_amount_for_current_item = 0
+			
+			# for actual type, user can mention actual tax amount in tax.tax_amount_print
+			if tax.charge_type != "Actual" or tax.rate:
+				tax.tax_amount_print = 0
+			
+			self.validate_on_previous_row(tax)
+			self.validate_included_tax(tax)
+			
+			# round relevant values
+			round_doc(tax, self.precision.tax)
+			
+	def calculate_net_total(self):
+		self.doc.net_total = 0
+		self.doc.fields[self.fmap.net_total_print] = 0
+		
+		for item in self.item_doclist:
+			self.doc.net_total += item.amount
+			self.doc.fields[self.fmap.net_total_print] += \
+				item.fields.get(self.fmap.print_amount)
+
+		self.doc.net_total = flt(self.doc.net_total, self.precision.main.net_total)
+		self.doc.fields[self.fmap.net_total_print] = \
+			flt(self.doc.fields.get(self.fmap.net_total_print),
+			self.precision.main[self.fmap.net_total_print])
+			
+	def calculate_taxes(self):
+		for item in self.item_doclist:
+			item_tax_map = self._load_item_tax_rate(item.item_tax_rate)
+			item.fields[self.fmap.valuation_tax_amount] = 0
+			
+			for i, tax in enumerate(self.tax_doclist):
+				# tax_amount represents the amount of tax for the current step
+				current_tax_amount = self.get_current_tax_amount(item, tax, item_tax_map)
+				
+				if hasattr(self, "set_valuation_tax_amount"):
+					self.set_valuation_tax_amount(item, tax, current_tax_amount)
+				
+				# case when net total is 0 but there is an actual type charge
+				# in this case add the actual amount to tax.tax_amount
+				# and tax.grand_total_for_current_item for the first such iteration
+				if not (current_tax_amount or self.doc.net_total or tax.tax_amount) and \
+						tax.charge_type=="Actual":
+					zero_net_total_adjustment = flt((tax.tax_amount_print * 
+						self.doc.fields.get(self.fmap.exchange_rate)) or tax.rate, 
+						self.precision.tax.tax_amount)
+					current_tax_amount += zero_net_total_adjustment
+				
+				# store tax_amount for current item as it will be used for
+				# charge type = 'On Previous Row Amount'
+				tax.tax_amount_for_current_item = current_tax_amount
+				
+				# accumulate tax amount into tax.tax_amount
+				tax.tax_amount += tax.tax_amount_for_current_item
+				
+				# accumulate tax_amount_print only if tax is not included
+				# and if tax amount of actual type is entered in 'rate' field
+				if not cint(tax.included_in_print_rate) and (tax.charge_type != "Actual"
+						or tax.rate):
+					tax.tax_amount_print += flt((tax.tax_amount_for_current_item /
+						self.doc.fields.get(self.fmap.exchange_rate)),
+						self.precision.tax.tax_amount_print)
+				
+				if tax.category == "Valuation":
+					# if just for valuation, do not add the tax amount in total
+					# hence, setting it as 0 for further steps
+					current_tax_amount = 0
+				
+				# Calculate tax.total viz. grand total till that step
+				# note: grand_total_for_current_item contains the contribution of 
+				# item's amount, previously applied tax and the current tax on that item
+				if i==0:
+					tax.grand_total_for_current_item = flt(item.amount +
+						current_tax_amount, self.precision.tax.total)
+					
+					# if inclusive pricing, current_tax_amount should not be considered
+					if cint(tax.included_in_print_rate):
+						current_tax_amount = 0
+						
+					tax.grand_total_print_for_current_item = \
+						flt(item.fields.get(self.fmap.print_amount) +
+						(current_tax_amount / self.doc.fields.get(
+							self.fmap.exchange_rate)),
+						self.precision.tax.total_print)
+				else:
+					tax.grand_total_for_current_item = \
+						flt(self.tax_doclist[i-1].grand_total_for_current_item +
+							current_tax_amount, self.precision.tax.total)
+					
+					# if inclusive pricing, current_tax_amount should not be considered
+					if cint(tax.included_in_print_rate):
+						current_tax_amount = 0
+					
+					tax.grand_total_print_for_current_item = \
+						flt(self.tax_doclist[i-1].grand_total_print_for_current_item +
+							(current_tax_amount / self.doc.fields.get(
+								self.fmap.exchange_rate)),
+							self.precision.tax.total_print)
+
+				# in tax.total, accumulate grand total of each item
+				tax.total += tax.grand_total_for_current_item
+				tax.total_print += tax.grand_total_print_for_current_item
+				
+				# TODO store tax_breakup for each item
+				
+	def get_current_tax_amount(self, item, tax, item_tax_map):
+		tax_rate = self._get_tax_rate(tax, item_tax_map)
+
+		if tax.charge_type == "Actual":
+			# distribute the tax amount proportionally to each item row
+			actual = flt(tax.rate or (tax.tax_amount_print * \
+				self.doc.fields.get(self.fmap.exchange_rate)),
+				self.precision.tax.tax_amount)
+			current_tax_amount = (self.doc.net_total
+				and ((item.amount / self.doc.net_total) * actual)
+				or 0)
+		elif tax.charge_type == "On Net Total":
+			current_tax_amount = (tax_rate / 100.0) * item.amount
+		elif tax.charge_type == "On Previous Row Amount":
+			current_tax_amount = (tax_rate / 100.0) * \
+				self.tax_doclist[cint(tax.row_id) - 1].tax_amount_for_current_item
+		elif tax.charge_type == "On Previous Row Total":
+			current_tax_amount = (tax_rate / 100.0) * \
+				self.tax_doclist[cint(tax.row_id) - 1].grand_total_for_current_item
+
+		return flt(current_tax_amount, self.precision.tax.tax_amount)
+		
+	def calculate_totals(self):
+		if self.tax_doclist:
+			self.doc.grand_total = flt(self.tax_doclist[-1].total,
+				self.precision.main.grand_total)
+			self.doc.fields[self.fmap.grand_total_print] = \
+				flt(self.tax_doclist[-1].total_print,
+				self.precision.main[self.fmap.grand_total_print])
+		else:
+			self.doc.grand_total = flt(self.doc.net_total,
+				self.precision.main.grand_total)
+			self.doc.fields[self.fmap.grand_total_print] = \
+				flt(self.doc.fields.get(self.fmap.net_total_print),
+				self.precision.main[self.fmap.grand_total_print])
+		
+		self.doc.fields[self.fmap.taxes_and_charges_total] = \
+			flt(self.doc.grand_total - self.doc.net_total,
+			self.precision.main[self.fmap.taxes_and_charges_total])
+			
+		self.doc.taxes_and_charges_total_print = \
+			flt(self.doc.fields.get(self.fmap.grand_total_print) - \
+			self.doc.fields.get(self.fmap.net_total_print),
+			self.precision.main.taxes_and_charges_total_print)
+		
+		self.doc.rounded_total = round(self.doc.grand_total)
+		self.doc.fields[self.fmap.rounded_total_print] = \
+			round(self.doc.fields.get(self.fmap.grand_total_print))
+		
+	def set_amount_in_words(self):
+		from webnotes.utils import money_in_words
+		base_currency = webnotes.conn.get_value("Company", self.doc.currency,
+			"default_currency")
+		
+		self.doc.fields[self.fmap.grand_total_in_words] = \
+			money_in_words(self.doc.grand_total, base_currency)
+		self.doc.fields[self.fmap.rounded_total_in_words] = \
+			money_in_words(self.doc.rounded_total, base_currency)
+		
+		self.doc.fields[self.fmap.grand_total_in_words_print] = \
+			money_in_words(self.doc.fields.get(self.fmap.grand_total_print),
+			self.doc.currency)
+		self.doc.fields[self.fmap.rounded_total_in_words_print] = \
+			money_in_words(self.doc.fields.get(self.fmap.rounded_total_print),
+			self.doc.currency)
+			
+	def validate_on_previous_row(self, tax):
+		"""
+			validate if a valid row id is mentioned in case of
+			On Previous Row Amount and On Previous Row Total
+		"""
+		if tax.charge_type in ["On Previous Row Amount", "On Previous Row Total"] and \
+				(not tax.row_id or cint(tax.row_id) >= tax.idx):
+			msgprint((_("Row") + " # %(idx)s [%(taxes_doctype)s]: " + \
+				_("Please specify a valid") + " %(row_id_label)s") % {
+					"idx": tax.idx,
+					"taxes_doctype": tax.parenttype,
+					"row_id_label": self.meta.get_label("row_id",
+						parentfield=self.fmap.taxes_and_charges)
+				}, raise_exception=True)
+	
+	def validate_included_tax(self, tax):
+		"""
+			validate conditions related to "Is this Tax Included in Rate?"
+		"""
+		def _on_previous_row_error(tax, row_range):
+			msgprint((_("Row") + " # %(idx)s [%(taxes_doctype)s]: " + \
+				_("If") + " '%(inclusive_label)s' " + _("is checked for") + \
+				" '%(charge_type_label)s' = '%(charge_type)s', " + _("then") + " " + \
+				_("Row") + " # %(row_range)s " + _("should also have") + \
+				" '%(inclusive_label)s' = " + _("checked")) % {
+					"idx": tax.idx,
+					"taxes_doctype": tax.doctype,
+					"inclusive_label": self.meta.get_label("included_in_print_rate",
+						parentfield=self.fmap.taxes_and_charges),
+					"charge_type_label": self.meta.get_label("charge_type",
+						parentfield=self.fmap.taxes_and_charges),
+					"charge_type": tax.charge_type,
+					"row_range": row_range,
+				}, raise_exception=True)
+		
+		if cint(tax.included_in_print_rate):
+			if tax.charge_type == "Actual":
+				# now inclusive rate for type 'Actual'
+				msgprint((_("Row") + " # %(idx)s [%(taxes_doctype)s]: " + \
+					"'%(charge_type_label)s' = '%(charge_type)s' " + \
+					_("cannot be included in item's rate")) % {
+						"idx": tax.idx,
+						"taxes_doctype": self.meta.get_options(
+							self.fmap.taxes_and_charges),
+						"charge_type_label": self.meta.get_label("charge_type",
+							parentfield=self.fmap.taxes_and_charges),
+						"charge_type": tax.charge_type,
+					}, raise_exception=True)
+					
+			elif tax.charge_type == "On Previous Row Amount" and \
+					not cint(self.tax_doclist[cint(tax.row_id) - 1]\
+						.included_in_print_rate):
+				# for an inclusive tax of type "On Previous Row Amount",
+				# dependent row should also be inclusive
+				_on_previous_row_error(tax, tax.row_id)
+				
+			elif tax.charge_type == "On Previous Row Total" and \
+					not all([cint(t.included_in_print_rate) \
+						for t in self.tax_doclist[:tax.idx - 1]]):
+				# for an inclusive tax of type "On Previous Row Total", 
+				# all rows above it should also be inclusive
+				_on_previous_row_error(tax, "1 - %d" % (tax.idx - 1))
+		
+	def determine_exclusive_rate(self):
+		if not any((cint(tax.included_in_print_rate) for tax in self.tax_doclist)):
+			# if no tax is marked as included in print rate, no need to proceed further
+			return
+		
+		for item in self.item_doclist:
+			item_tax_map = self._load_item_tax_rate(item.item_tax_rate)
+			
+			cumulated_tax_fraction = 0
+			
+			for i, tax in enumerate(self.tax_doclist):
+				if cint(tax.included_in_print_rate):
+					tax.tax_fraction_for_current_item = \
+						self.get_current_tax_fraction(tax, item_tax_map)
+				else:
+					tax.tax_fraction_for_current_item = 0
+				
+				if i==0:
+					tax.grand_total_fraction_for_current_item = 1 + \
+						tax.tax_fraction_for_current_item
+				else:
+					tax.grand_total_fraction_for_current_item = \
+						self.tax_doclist[i-1].grand_total_fraction_for_current_item \
+						+ tax.tax_fraction_for_current_item
+						
+				cumulated_tax_fraction += tax.tax_fraction_for_current_item
+			
+			if cumulated_tax_fraction:
+				item.fields[self.fmap.rate] = \
+					flt((item.fields.get(self.fmap.print_rate) * \
+					self.doc.fields.get(self.fmap.exchange_rate)) / 
+					(1 + cumulated_tax_fraction), self.precision.item[self.fmap.rate])
+				
+				item.amount = flt(item.fields.get(self.fmap.rate) * item.qty,
+					self.precision.item.amount)
+				
+				item.fields[self.fmap.ref_rate] = \
+					flt(item.fields.get(self.fmap.rate) / (1 - \
+					(item.fields.get(self.fmap.discount) / 100.0)),
+					self.precision.item[self.fmap.ref_rate])
+		
+				# print item.print_rate, 1+cumulated_tax_fraction, item.rate, item.amount
+				# print "-"*10
+
+	def get_current_tax_fraction(self, tax, item_tax_map):
+		"""
+			Get tax fraction for calculating tax exclusive amount
+			from tax inclusive amount
+		"""
+		current_tax_fraction = 0
+		
+		if cint(tax.included_in_print_rate):
+			tax_rate = self._get_tax_rate(tax, item_tax_map)
+			
+			if tax.charge_type == "On Net Total":
+				current_tax_fraction = tax_rate / 100.0
+			
+			elif tax.charge_type == "On Previous Row Amount":
+				current_tax_fraction = (tax_rate / 100.0) * \
+					self.tax_doclist[cint(tax.row_id) - 1]\
+						.tax_fraction_for_current_item
+			
+			elif tax.charge_type == "On Previous Row Total":
+				current_tax_fraction = (tax_rate / 100.0) * \
+					self.tax_doclist[cint(tax.row_id) - 1]\
+						.grand_total_fraction_for_current_item
+						
+			# print tax.account_head, tax_rate, current_tax_fraction
+
+		return current_tax_fraction
+	
+	def _load_item_tax_rate(self, item_tax_rate):
+		if not item_tax_rate:
+			return {}
+
+		return json.loads(item_tax_rate)
+		
+	def _get_tax_rate(self, tax, item_tax_map):
+		if item_tax_map.has_key(tax.account_head):
+			return flt(item_tax_map.get(tax.account_head), self.precision.tax.rate)
+		else:
+			return tax.rate
diff --git a/controllers/transaction_controller.py b/controllers/transaction_controller.py
new file mode 100644
index 0000000..5d77472
--- /dev/null
+++ b/controllers/transaction_controller.py
@@ -0,0 +1,119 @@
+# 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
+import webnotes.model
+from webnotes import _, DictObj
+from webnotes.utils import cint
+import json
+
+import stock.utils
+
+from webnotes.model.controller import DocListController
+
+class TransactionController(DocListController):
+	def __init__(self, doc, doclist):
+		super(TransactionController, self).__init__(doc, doclist)
+		self.cur_docstatus = cint(webnotes.conn.get_value(self.doc.doctype, 
+			self.doc.name, "docstatus"))
+		
+	@property
+	def precision(self):
+		if not hasattr(self, "_precision"):
+			self._precision = DictObj()
+			self._precision.main = self.meta.get_precision_map()
+			self._precision.item = self.meta.get_precision_map(parentfield = \
+				self.item_table_field)
+			if self.meta.get_field(self.fmap.taxes_and_charges):
+				self._precision.tax = self.meta.get_precision_map(parentfield = \
+					self.fmap.taxes_and_charges)
+		return self._precision
+		
+	@property
+	def item_doclist(self):
+		if not hasattr(self, "_item_doclist"):
+			self._item_doclist = self.doclist.get({"parentfield": self.item_table_field})
+		return self._item_doclist
+
+	@property
+	def tax_doclist(self):
+		if not hasattr(self, "_tax_doclist"):
+			self._tax_doclist = self.doclist.get(
+				{"parentfield": self.fmap.taxes_and_charges})
+		return self._tax_doclist
+	
+	@property
+	def stock_items(self):
+		if not hasattr(self, "_stock_items"):
+			item_codes = list(set(item.item_code for item in self.item_doclist))
+			self._stock_items = [r[0] for r in webnotes.conn.sql("""select name
+				from `tabItem` where name in (%s) and is_stock_item='Yes'""" % \
+				(", ".join((["%s"]*len(item_codes))),), item_codes)]
+
+		return self._stock_items
+	
+	@property
+	def fmap(self):
+		if not hasattr(self, "_fmap"):
+			if self.doc.doctype in ["Lead", "Quotation", "Sales Order", "Sales Invoice",
+					"Delivery Note"]:
+				self._fmap = webnotes.DictObj(	{
+					"exchange_rate": "conversion_rate",
+					"taxes_and_charges": "other_charges",
+					"taxes_and_charges_master": "charge",
+					"taxes_and_charges_total": "other_charges_total",
+					"net_total_print": "net_total_print",
+					"grand_total_print": "grand_total_export",
+					"grand_total_in_words": "grand_total_in_words",
+					"grand_total_in_words_print": "grand_total_in_words_print",
+					"rounded_total_print": "rounded_total_export",
+					"rounded_total_in_words": "in_words",
+					"rounded_total_in_words_print": "in_words_export",
+					"print_ref_rate": "ref_rate",
+					"discount": "adj_rate",
+					"print_rate": "export_rate",
+					"print_amount": "export_amount",
+					"ref_rate": "base_ref_rate",
+					"rate": "basic_rate",
+					
+					"plc_exchange_rate": "plc_conversion_rate",
+					"tax_calculation": "other_charges_calculation",
+				})
+			else:
+				self._fmap = webnotes.DictObj({
+					"exchange_rate": "conversion_rate",
+					"taxes_and_charges": "purchase_tax_details",
+					"taxes_and_charges_master": "purchase_other_charges",
+					"taxes_and_charges_total": "total_tax",
+					"net_total_print": "net_total_import",
+					"grand_total_print": "grand_total_import",
+					"grand_total_in_words": "in_words",
+					"grand_total_in_words_print": "in_words_import",
+					"rounded_total_print": "rounded_total_print",
+					"rounded_total_in_words": "rounded_total_in_words",
+					"rounded_total_in_words_print": "rounded_total_in_words_print",
+					"print_ref_rate": "import_ref_rate",
+					"discount": "discount_rate",
+					"print_rate": "import_rate",
+					"print_amount": "import_amount",
+					"ref_rate": "purchase_ref_rate",
+					"rate": "purchase_rate",
+					
+					"valuation_tax_amount": "item_tax_amount"
+				})
+			
+		return self._fmap or webnotes.DictObj()
\ No newline at end of file
diff --git a/home/doctype/company_control/company_control.py b/home/doctype/company_control/company_control.py
index 8baf910..c18610b 100644
--- a/home/doctype/company_control/company_control.py
+++ b/home/doctype/company_control/company_control.py
@@ -14,24 +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/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cint, cstr
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.doc import Document
+from webnotes.model.wrapper import copy_doclist
+from webnotes import session
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/home/doctype/feed/feed.py b/home/doctype/feed/feed.py
index c6cf506..6e4199b 100644
--- a/home/doctype/feed/feed.py
+++ b/home/doctype/feed/feed.py
@@ -14,24 +14,14 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/home/doctype/home_control/home_control.py b/home/doctype/home_control/home_control.py
index 02be00d..c200109 100644
--- a/home/doctype/home_control/home_control.py
+++ b/home/doctype/home_control/home_control.py
@@ -14,28 +14,24 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes import session, msgprint, errprint
+from webnotes.utils import add_days, cint, cstr, getdate, now, nowdate
+from webnotes.model.doc import Document
+from webnotes import session, msgprint
 
 sql = webnotes.conn.sql
-convert_to_lists = webnotes.conn.convert_to_lists
 
 try: import json
 except: import simplejson as json
 
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
 	def __init__(self,d,dl):
 		self.doc, self.doclist = d,dl
-
-# --------------------------------------------------------------------------------------------------------
+---------------
 # ------------------------------------- Home page module details -----------------------------------------
 	
 	def delete_cache(self):
diff --git a/home/page/latest_updates/latest_updates.js b/home/page/latest_updates/latest_updates.js
index 5429294..24cab01 100644
--- a/home/page/latest_updates/latest_updates.js
+++ b/home/page/latest_updates/latest_updates.js
@@ -1,4 +1,12 @@
 erpnext.updates = [
+	["30th November 2012", [
+		"Auto Notifications: System will prompt user with pre-set message for auto-notification.",
+		"Employee: Users with role Employee will only be able to see their Employee Records.",
+		"Leave Application: Users with role Employee can now apply for leaves. HR User will be able to set Approval or Rejection.",
+	]],
+	["29th November 2012", [
+		"EMail: Form Emails are now via Communication (with Rich Text Etc.).",
+	]],
 	["28th November 2012", [
 		"Profile: Profile Settings (My Settings...) is now the Profile Form.",
 		"Financial Analytics: Show Net Profit/Loss",
diff --git a/hr/doctype/appraisal/appraisal.py b/hr/doctype/appraisal/appraisal.py
index b2d0f96..b4b0e4e 100644
--- a/hr/doctype/appraisal/appraisal.py
+++ b/hr/doctype/appraisal/appraisal.py
@@ -14,11 +14,10 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, cstr, flt, getdate, now, nowdate
+from webnotes.utils import cstr, flt, getdate
 from webnotes.model.wrapper import getlist
 from webnotes.model.code import get_obj
 from webnotes import msgprint
diff --git a/hr/doctype/attendance/attendance.py b/hr/doctype/attendance/attendance.py
index d0f6989..3f45825 100644
--- a/hr/doctype/attendance/attendance.py
+++ b/hr/doctype/attendance/attendance.py
@@ -14,24 +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/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import add_days, getdate, now
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.doc import make_autoname
+from webnotes.model.wrapper import copy_doclist
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/hr/doctype/attendance_control_panel/attendance_control_panel.py b/hr/doctype/attendance_control_panel/attendance_control_panel.py
index 0a28494..bc21f13 100644
--- a/hr/doctype/attendance_control_panel/attendance_control_panel.py
+++ b/hr/doctype/attendance_control_panel/attendance_control_panel.py
@@ -14,24 +14,16 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.	If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cint, cstr, date_diff, formatdate, get_defaults, getdate, now
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
+from webnotes import form, msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/hr/doctype/employee/employee.py b/hr/doctype/employee/employee.py
index 0be6830..c0f7be3 100644
--- a/hr/doctype/employee/employee.py
+++ b/hr/doctype/employee/employee.py
@@ -17,7 +17,7 @@
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import getdate, now, nowdate, validate_email_add
+from webnotes.utils import getdate, validate_email_add
 from webnotes.model.doc import make_autoname
 from webnotes import msgprint
 
@@ -37,6 +37,8 @@
 				self.doc.name = make_autoname(self.doc.naming_series + '.####')
 			elif ret[0][0]=='Employee Number':
 				self.doc.name = make_autoname(self.doc.employee_number)
+
+		self.doc.employee = self.doc.name
 				
 	def get_retirement_date(self):		
 		import datetime
@@ -51,6 +53,7 @@
 		return ret_sal_struct and ret_sal_struct[0][0] or ''
 
 	def validate(self):
+		self.doc.employee = self.doc.name
 		self.validate_date()
 		self.validate_email()
 		self.validate_name()
diff --git a/hr/doctype/employee/employee.txt b/hr/doctype/employee/employee.txt
index f780836..826df84 100644
--- a/hr/doctype/employee/employee.txt
+++ b/hr/doctype/employee/employee.txt
@@ -1,1069 +1,879 @@
-# DocType, Employee
 [
-
-	# These values are common in all dictionaries
-	{
-		u'creation': '2012-07-03 13:30:40',
-		u'docstatus': 0,
-		u'modified': '2012-11-14 16:54:18',
-		u'modified_by': u'Administrator',
-		u'owner': u'Administrator'
-	},
-
-	# These values are common for all DocType
-	{
-		'_last_update': u'1308918132',
-		'allow_attach': 1,
-		'allow_trash': 1,
-		'colour': u'White:FFF',
-		u'doctype': u'DocType',
-		'document_type': u'Master',
-		'module': u'HR',
-		u'name': u'__common__',
-		'search_fields': u'employee_name',
-		'section_style': u'Tabbed',
-		'server_code_error': u' ',
-		'show_in_menu': 0,
-		'subject': u'%(employee_name)s',
-		'tag_fields': u'status',
-		'version': 1
-	},
-
-	# These values are common for all DocField
-	{
-		u'doctype': u'DocField',
-		u'name': u'__common__',
-		'parent': u'Employee',
-		'parentfield': u'fields',
-		'parenttype': u'DocType'
-	},
-
-	# These values are common for all DocPerm
-	{
-		u'doctype': u'DocPerm',
-		u'name': u'__common__',
-		'parent': u'Employee',
-		'parentfield': u'permissions',
-		'parenttype': u'DocType',
-		'read': 1
-	},
-
-	# DocType, Employee
-	{
-		u'doctype': u'DocType',
-		u'name': u'Employee'
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'basic_information',
-		'fieldtype': u'Section Break',
-		'label': u'Basic Information',
-		'oldfieldtype': u'Section Break',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'column_break0',
-		'fieldtype': u'Column Break',
-		'permlevel': 0,
-		'width': u'50%'
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'description': u'<span class="sys_manager">To setup, please go to Setup > Naming Series</span>',
-		u'doctype': u'DocField',
-		'fieldname': u'naming_series',
-		'fieldtype': u'Select',
-		'label': u'Naming Series',
-		'no_copy': 1,
-		'oldfieldname': u'naming_series',
-		'oldfieldtype': u'Select',
-		'options': u'EMP/',
-		'permlevel': 0,
-		'reqd': 0
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		u'doctype': u'DocField',
-		'fieldname': u'salutation',
-		'fieldtype': u'Select',
-		'label': u'Salutation',
-		'oldfieldname': u'salutation',
-		'oldfieldtype': u'Select',
-		'options': u'\nMr\nMs',
-		'permlevel': 0,
-		'search_index': 0,
-		'trigger': u'Client'
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		u'doctype': u'DocField',
-		'fieldname': u'employee_name',
-		'fieldtype': u'Data',
-		'label': u'Full Name',
-		'oldfieldname': u'employee_name',
-		'oldfieldtype': u'Data',
-		'permlevel': 0,
-		'reqd': 1
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'employee_number',
-		'fieldtype': u'Data',
-		'in_filter': 1,
-		'label': u'Employee Number',
-		'oldfieldname': u'employee_number',
-		'oldfieldtype': u'Data',
-		'permlevel': 0,
-		'search_index': 0
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'description': u'System User (login) ID. If set, it will become default for all HR forms.',
-		u'doctype': u'DocField',
-		'fieldname': u'user_id',
-		'fieldtype': u'Link',
-		'label': u'User ID',
-		'options': u'Profile',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'column_break1',
-		'fieldtype': u'Column Break',
-		'permlevel': 0,
-		'width': u'50%'
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		u'doctype': u'DocField',
-		'fieldname': u'date_of_joining',
-		'fieldtype': u'Date',
-		'label': u'Date of Joining',
-		'oldfieldname': u'date_of_joining',
-		'oldfieldtype': u'Date',
-		'permlevel': 0,
-		'reqd': 1
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		u'doctype': u'DocField',
-		'fieldname': u'date_of_birth',
-		'fieldtype': u'Date',
-		'in_filter': 1,
-		'label': u'Date of Birth',
-		'oldfieldname': u'date_of_birth',
-		'oldfieldtype': u'Date',
-		'permlevel': 0,
-		'reqd': 1,
-		'search_index': 0,
-		'trigger': u'Client'
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'gender',
-		'fieldtype': u'Select',
-		'in_filter': 1,
-		'label': u'Gender',
-		'oldfieldname': u'gender',
-		'oldfieldtype': u'Select',
-		'options': u'\nMale\nFemale',
-		'permlevel': 0,
-		'reqd': 1,
-		'search_index': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'company',
-		'fieldtype': u'Select',
-		'in_filter': 1,
-		'label': u'Company',
-		'options': u'link:Company',
-		'permlevel': 0,
-		'print_hide': 1,
-		'reqd': 1
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'employment_details',
-		'fieldtype': u'Section Break',
-		'label': u'Employment Details',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'col_break_21',
-		'fieldtype': u'Column Break',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'default': u'Active',
-		u'doctype': u'DocField',
-		'fieldname': u'status',
-		'fieldtype': u'Select',
-		'in_filter': 1,
-		'label': u'Status',
-		'oldfieldname': u'status',
-		'oldfieldtype': u'Select',
-		'options': u'\nActive\nLeft',
-		'permlevel': 0,
-		'reqd': 1,
-		'search_index': 1
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'employment_type',
-		'fieldtype': u'Link',
-		'in_filter': 1,
-		'label': u'Employment Type',
-		'oldfieldname': u'employment_type',
-		'oldfieldtype': u'Link',
-		'options': u'Employment Type',
-		'permlevel': 0,
-		'search_index': 0
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'description': u'Applicable Holiday List',
-		u'doctype': u'DocField',
-		'fieldname': u'holiday_list',
-		'fieldtype': u'Link',
-		'label': u'Holiday List',
-		'oldfieldname': u'holiday_list',
-		'oldfieldtype': u'Link',
-		'options': u'Holiday List',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'col_break_22',
-		'fieldtype': u'Column Break',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'scheduled_confirmation_date',
-		'fieldtype': u'Date',
-		'in_filter': 1,
-		'label': u'Scheduled Confirmation Date',
-		'oldfieldname': u'scheduled_confirmation_date',
-		'oldfieldtype': u'Date',
-		'permlevel': 0,
-		'search_index': 0
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		u'doctype': u'DocField',
-		'fieldname': u'final_confirmation_date',
-		'fieldtype': u'Date',
-		'label': u'Final Confirmation Date',
-		'oldfieldname': u'final_confirmation_date',
-		'oldfieldtype': u'Date',
-		'permlevel': 0,
-		'search_index': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'contract_end_date',
-		'fieldtype': u'Date',
-		'in_filter': 1,
-		'label': u'Contract End Date',
-		'oldfieldname': u'contract_end_date',
-		'oldfieldtype': u'Date',
-		'permlevel': 0,
-		'search_index': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'date_of_retirement',
-		'fieldtype': u'Date',
-		'label': u'Date Of Retirement',
-		'oldfieldname': u'date_of_retirement',
-		'oldfieldtype': u'Date',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'job_profile',
-		'fieldtype': u'Section Break',
-		'label': u'Job Profile',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'column_break2',
-		'fieldtype': u'Column Break',
-		'permlevel': 0,
-		'width': u'50%'
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		u'doctype': u'DocField',
-		'fieldname': u'branch',
-		'fieldtype': u'Link',
-		'in_filter': 1,
-		'label': u'Branch',
-		'oldfieldname': u'branch',
-		'oldfieldtype': u'Link',
-		'options': u'Branch',
-		'permlevel': 0,
-		'reqd': 0
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		u'doctype': u'DocField',
-		'fieldname': u'department',
-		'fieldtype': u'Link',
-		'in_filter': 1,
-		'label': u'Department',
-		'oldfieldname': u'department',
-		'oldfieldtype': u'Link',
-		'options': u'Department',
-		'permlevel': 0,
-		'reqd': 0
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		u'doctype': u'DocField',
-		'fieldname': u'designation',
-		'fieldtype': u'Link',
-		'in_filter': 1,
-		'label': u'Designation',
-		'oldfieldname': u'designation',
-		'oldfieldtype': u'Link',
-		'options': u'Designation',
-		'permlevel': 0,
-		'reqd': 0,
-		'search_index': 1
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		u'doctype': u'DocField',
-		'fieldname': u'grade',
-		'fieldtype': u'Link',
-		'in_filter': 1,
-		'label': u'Grade',
-		'oldfieldname': u'grade',
-		'oldfieldtype': u'Link',
-		'options': u'Grade',
-		'permlevel': 0,
-		'reqd': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'reports_to',
-		'fieldtype': u'Link',
-		'label': u'Reports to',
-		'oldfieldname': u'reports_to',
-		'oldfieldtype': u'Link',
-		'options': u'Employee',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		'description': u'Provide email id registered in company',
-		u'doctype': u'DocField',
-		'fieldname': u'company_email',
-		'fieldtype': u'Data',
-		'in_filter': 1,
-		'label': u'Email (By company)',
-		'oldfieldname': u'company_email',
-		'oldfieldtype': u'Data',
-		'permlevel': 0,
-		'reqd': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'salary_information',
-		'fieldtype': u'Column Break',
-		'label': u'Salary Information',
-		'oldfieldtype': u'Section Break',
-		'permlevel': 0,
-		'width': u'50%'
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		u'doctype': u'DocField',
-		'fieldname': u'salary_mode',
-		'fieldtype': u'Select',
-		'label': u'Salary Mode',
-		'oldfieldname': u'salary_mode',
-		'oldfieldtype': u'Select',
-		'options': u'\nBank\nCash\nCheque',
-		'permlevel': 0,
-		'trigger': u'Client'
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'depends_on': u"eval:doc.salary_mode == 'Bank'",
-		u'doctype': u'DocField',
-		'fieldname': u'bank_name',
-		'fieldtype': u'Data',
-		'hidden': 0,
-		'in_filter': 1,
-		'label': u'Bank Name',
-		'oldfieldname': u'bank_name',
-		'oldfieldtype': u'Link',
-		'options': u'Suggest',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'depends_on': u"eval:doc.salary_mode == 'Bank'",
-		u'doctype': u'DocField',
-		'fieldname': u'bank_ac_no',
-		'fieldtype': u'Data',
-		'hidden': 0,
-		'label': u'Bank A/C No.',
-		'oldfieldname': u'bank_ac_no',
-		'oldfieldtype': u'Data',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'esic_card_no',
-		'fieldtype': u'Data',
-		'label': u'ESIC CARD No',
-		'oldfieldname': u'esic_card_no',
-		'oldfieldtype': u'Data',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'pf_number',
-		'fieldtype': u'Data',
-		'label': u'PF Number',
-		'oldfieldname': u'pf_number',
-		'oldfieldtype': u'Data',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'gratuity_lic_id',
-		'fieldtype': u'Data',
-		'label': u'Gratuity LIC ID',
-		'oldfieldname': u'gratuity_lic_id',
-		'oldfieldtype': u'Data',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'contact_details',
-		'fieldtype': u'Section Break',
-		'label': u'Contact Details',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'column_break3',
-		'fieldtype': u'Column Break',
-		'permlevel': 0,
-		'width': u'50%'
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'cell_number',
-		'fieldtype': u'Data',
-		'label': u'Cell Number',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'personal_email',
-		'fieldtype': u'Data',
-		'label': u'Personal Email',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'notice_number_of_days',
-		'fieldtype': u'Int',
-		'label': u'Notice - Number of Days',
-		'oldfieldname': u'notice_number_of_days',
-		'oldfieldtype': u'Int',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'emergency_contact_details',
-		'fieldtype': u'HTML',
-		'label': u'Emergency Contact Details',
-		'options': u'<b>Emergency Contact Details</b>',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'person_to_be_contacted',
-		'fieldtype': u'Data',
-		'label': u'Person To Be Contacted',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'relation',
-		'fieldtype': u'Data',
-		'label': u'Relation',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'emergency_phone_number',
-		'fieldtype': u'Data',
-		'label': u'Emergency Phone Number',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'column_break4',
-		'fieldtype': u'Column Break',
-		'permlevel': 0,
-		'width': u'50%'
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'permanent_accommodation_type',
-		'fieldtype': u'Select',
-		'label': u'Permanent Accommodation Type',
-		'options': u'\nRented\nOwned',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'permanent_address',
-		'fieldtype': u'Small Text',
-		'label': u'Permanent Address',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'current_accommodation_type',
-		'fieldtype': u'Select',
-		'label': u'Current Accommodation Type',
-		'options': u'\nRented\nOwned',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'current_address',
-		'fieldtype': u'Small Text',
-		'label': u'Current Address',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'personal_details',
-		'fieldtype': u'Section Break',
-		'label': u'Personal Details',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'column_break5',
-		'fieldtype': u'Column Break',
-		'permlevel': 0,
-		'width': u'50%'
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'pan_number',
-		'fieldtype': u'Data',
-		'label': u'PAN Number',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'passport_number',
-		'fieldtype': u'Data',
-		'label': u'Passport Number',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'date_of_issue',
-		'fieldtype': u'Date',
-		'label': u'Date of Issue',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'valid_upto',
-		'fieldtype': u'Date',
-		'label': u'Valid Upto',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		u'doctype': u'DocField',
-		'fieldname': u'salary_structure',
-		'fieldtype': u'Button',
-		'hidden': 1,
-		'label': u'Salary Structure',
-		'oldfieldtype': u'Button',
-		'permlevel': 0,
-		'trigger': u'Client'
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'place_of_issue',
-		'fieldtype': u'Data',
-		'label': u'Place of Issue',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'marital_status',
-		'fieldtype': u'Select',
-		'label': u'Marital Status',
-		'options': u'\nSingle\nMarried\nDivorced\nWidowed',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'blood_group',
-		'fieldtype': u'Select',
-		'label': u'Blood Group',
-		'options': u'\nA+\nA-\nB+\nB-\nAB+\nAB-\nO+\nO-',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'column_break6',
-		'fieldtype': u'Column Break',
-		'permlevel': 0,
-		'width': u'50%'
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'description': u'Here you can maintain family details like name and occupation of parent, spouse and children',
-		u'doctype': u'DocField',
-		'fieldname': u'family_background',
-		'fieldtype': u'Small Text',
-		'label': u'Family Background',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'description': u'Here you can maintain height, weight, allergies, medical concerns etc',
-		u'doctype': u'DocField',
-		'fieldname': u'health_details',
-		'fieldtype': u'Small Text',
-		'label': u'Health Details',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'educational_qualification',
-		'fieldtype': u'Section Break',
-		'label': u'Educational Qualification',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'educational_qualification_details',
-		'fieldtype': u'Table',
-		'label': u'Educational Qualification Details',
-		'options': u'Employee Education',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'career_history',
-		'fieldtype': u'Section Break',
-		'label': u'Career History',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'previous_work_experience',
-		'fieldtype': u'Section Break',
-		'label': u'Previous Work Experience',
-		'options': u'Simple',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'previous_experience_details',
-		'fieldtype': u'Table',
-		'label': u'Employee External Work History',
-		'options': u'Employee External Work History',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'history_in_company',
-		'fieldtype': u'Section Break',
-		'label': u'History In Company',
-		'options': u'Simple',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'experience_in_company_details',
-		'fieldtype': u'Table',
-		'label': u'Employee Internal Work Historys',
-		'options': u'Employee Internal Work History',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'exit',
-		'fieldtype': u'Section Break',
-		'label': u'Exit',
-		'oldfieldtype': u'Section Break',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'column_break7',
-		'fieldtype': u'Column Break',
-		'permlevel': 0,
-		'width': u'50%'
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'resignation_letter_date',
-		'fieldtype': u'Date',
-		'label': u'Resignation Letter Date',
-		'oldfieldname': u'resignation_letter_date',
-		'oldfieldtype': u'Date',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'relieving_date',
-		'fieldtype': u'Date',
-		'in_filter': 1,
-		'label': u'Relieving Date',
-		'oldfieldname': u'relieving_date',
-		'oldfieldtype': u'Date',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'reason_for_leaving',
-		'fieldtype': u'Data',
-		'label': u'Reason for Leaving',
-		'oldfieldname': u'reason_for_leaving',
-		'oldfieldtype': u'Data',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'leave_encashed',
-		'fieldtype': u'Select',
-		'label': u'Leave Encashed?',
-		'oldfieldname': u'leave_encashed',
-		'oldfieldtype': u'Select',
-		'options': u'\nYes\nNo',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'encashment_date',
-		'fieldtype': u'Date',
-		'label': u'Encashment Date',
-		'oldfieldname': u'encashment_date',
-		'oldfieldtype': u'Date',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'exit_interview_details',
-		'fieldtype': u'Column Break',
-		'label': u'Exit Interview Details',
-		'oldfieldname': u'col_brk6',
-		'oldfieldtype': u'Column Break',
-		'permlevel': 0,
-		'width': u'50%'
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'held_on',
-		'fieldtype': u'Date',
-		'label': u'Held On',
-		'oldfieldname': u'held_on',
-		'oldfieldtype': u'Date',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'reason_for_resignation',
-		'fieldtype': u'Select',
-		'label': u'Reason for Resignation',
-		'oldfieldname': u'reason_for_resignation',
-		'oldfieldtype': u'Select',
-		'options': u'\nBetter Prospects\nHealth Concerns',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'new_workplace',
-		'fieldtype': u'Data',
-		'label': u'New Workplace',
-		'oldfieldname': u'new_workplace',
-		'oldfieldtype': u'Data',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'feedback',
-		'fieldtype': u'Small Text',
-		'label': u'Feedback',
-		'oldfieldname': u'feedback',
-		'oldfieldtype': u'Text',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'file_list',
-		'fieldtype': u'Text',
-		'hidden': 1,
-		'label': u'File List',
-		'permlevel': 0,
-		'print_hide': 1
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'trash_reason',
-		'fieldtype': u'Small Text',
-		'label': u'Trash Reason',
-		'oldfieldname': u'trash_reason',
-		'oldfieldtype': u'Small Text',
-		'permlevel': 1
-	},
-
-	# DocPerm
-	{
-		'amend': 0,
-		'cancel': 0,
-		'create': 0,
-		u'doctype': u'DocPerm',
-		'permlevel': 0,
-		'role': u'Employee',
-		'submit': 0,
-		'write': 0
-	},
-
-	# DocPerm
-	{
-		'amend': 0,
-		'cancel': 0,
-		'create': 0,
-		u'doctype': u'DocPerm',
-		'permlevel': 0,
-		'role': u'Employee',
-		'submit': 0,
-		'write': 0
-	},
-
-	# DocPerm
-	{
-		u'doctype': u'DocPerm',
-		'permlevel': 1,
-		'role': u'All'
-	},
-
-	# DocPerm
-	{
-		'cancel': 1,
-		'create': 1,
-		u'doctype': u'DocPerm',
-		'permlevel': 0,
-		'role': u'HR User',
-		'write': 1
-	},
-
-	# DocPerm
-	{
-		'cancel': 1,
-		'create': 1,
-		u'doctype': u'DocPerm',
-		'permlevel': 0,
-		'role': u'HR Manager',
-		'write': 1
-	},
-
-	# DocPerm
-	{
-		u'doctype': u'DocPerm',
-		'permlevel': 1,
-		'role': u'HR User'
-	},
-
-	# DocPerm
-	{
-		u'doctype': u'DocPerm',
-		'permlevel': 1,
-		'role': u'HR Manager'
-	}
+ {
+  "owner": "Administrator", 
+  "docstatus": 0, 
+  "creation": "2012-11-30 11:49:12", 
+  "modified_by": "Administrator", 
+  "modified": "2012-11-30 11:54:31"
+ }, 
+ {
+  "autoname": "naming_series:", 
+  "allow_attach": 1, 
+  "search_fields": "employee_name", 
+  "module": "HR", 
+  "doctype": "DocType", 
+  "document_type": "Master", 
+  "name": "__common__"
+ }, 
+ {
+  "name": "__common__", 
+  "parent": "Employee", 
+  "doctype": "DocField", 
+  "parenttype": "DocType", 
+  "parentfield": "fields"
+ }, 
+ {
+  "name": "__common__", 
+  "parent": "Employee", 
+  "amend": 0, 
+  "submit": 0, 
+  "doctype": "DocPerm", 
+  "read": 1, 
+  "parenttype": "DocType", 
+  "parentfield": "permissions"
+ }, 
+ {
+  "name": "Employee", 
+  "doctype": "DocType"
+ }, 
+ {
+  "oldfieldtype": "Section Break", 
+  "doctype": "DocField", 
+  "label": "Basic Information", 
+  "fieldname": "basic_information", 
+  "fieldtype": "Section Break", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "width": "50%", 
+  "fieldname": "column_break0", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "print_hide": 1, 
+  "no_copy": 1, 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Employee", 
+  "fieldname": "employee", 
+  "fieldtype": "Data", 
+  "hidden": 1, 
+  "permlevel": 0, 
+  "report_hide": 1
+ }, 
+ {
+  "description": "<span class=\"sys_manager\">To setup, please go to Setup > Naming Series</span>", 
+  "no_copy": 1, 
+  "oldfieldtype": "Select", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Naming Series", 
+  "oldfieldname": "naming_series", 
+  "permlevel": 0, 
+  "fieldname": "naming_series", 
+  "fieldtype": "Select", 
+  "reqd": 0, 
+  "options": "EMP/"
+ }, 
+ {
+  "oldfieldtype": "Select", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Salutation", 
+  "oldfieldname": "salutation", 
+  "trigger": "Client", 
+  "fieldname": "salutation", 
+  "fieldtype": "Select", 
+  "search_index": 0, 
+  "options": "\nMr\nMs", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Data", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Full Name", 
+  "oldfieldname": "employee_name", 
+  "fieldname": "employee_name", 
+  "fieldtype": "Data", 
+  "reqd": 1, 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Data", 
+  "doctype": "DocField", 
+  "label": "Employee Number", 
+  "oldfieldname": "employee_number", 
+  "fieldname": "employee_number", 
+  "fieldtype": "Data", 
+  "search_index": 0, 
+  "permlevel": 0, 
+  "in_filter": 1
+ }, 
+ {
+  "description": "System User (login) ID. If set, it will become default for all HR forms.", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "User ID", 
+  "options": "Profile", 
+  "fieldname": "user_id", 
+  "fieldtype": "Link", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "width": "50%", 
+  "fieldname": "column_break1", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Date", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Date of Joining", 
+  "oldfieldname": "date_of_joining", 
+  "fieldname": "date_of_joining", 
+  "fieldtype": "Date", 
+  "reqd": 1, 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Date", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Date of Birth", 
+  "oldfieldname": "date_of_birth", 
+  "trigger": "Client", 
+  "fieldname": "date_of_birth", 
+  "fieldtype": "Date", 
+  "search_index": 0, 
+  "reqd": 1, 
+  "permlevel": 0, 
+  "in_filter": 1
+ }, 
+ {
+  "oldfieldtype": "Select", 
+  "doctype": "DocField", 
+  "label": "Gender", 
+  "oldfieldname": "gender", 
+  "options": "\nMale\nFemale", 
+  "fieldname": "gender", 
+  "fieldtype": "Select", 
+  "search_index": 0, 
+  "reqd": 1, 
+  "permlevel": 0, 
+  "in_filter": 1
+ }, 
+ {
+  "print_hide": 1, 
+  "doctype": "DocField", 
+  "label": "Company", 
+  "options": "link:Company", 
+  "fieldname": "company", 
+  "fieldtype": "Select", 
+  "reqd": 1, 
+  "permlevel": 0, 
+  "in_filter": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Employment Details", 
+  "fieldname": "employment_details", 
+  "fieldtype": "Section Break", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "col_break_21", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "default": "Active", 
+  "oldfieldtype": "Select", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Status", 
+  "oldfieldname": "status", 
+  "permlevel": 0, 
+  "fieldname": "status", 
+  "fieldtype": "Select", 
+  "search_index": 1, 
+  "reqd": 1, 
+  "options": "\nActive\nLeft", 
+  "in_filter": 1
+ }, 
+ {
+  "oldfieldtype": "Link", 
+  "doctype": "DocField", 
+  "label": "Employment Type", 
+  "oldfieldname": "employment_type", 
+  "options": "Employment Type", 
+  "fieldname": "employment_type", 
+  "fieldtype": "Link", 
+  "search_index": 0, 
+  "permlevel": 0, 
+  "in_filter": 1
+ }, 
+ {
+  "description": "Applicable Holiday List", 
+  "oldfieldtype": "Link", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Holiday List", 
+  "oldfieldname": "holiday_list", 
+  "options": "Holiday List", 
+  "fieldname": "holiday_list", 
+  "fieldtype": "Link", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "col_break_22", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Date", 
+  "doctype": "DocField", 
+  "label": "Scheduled Confirmation Date", 
+  "oldfieldname": "scheduled_confirmation_date", 
+  "fieldname": "scheduled_confirmation_date", 
+  "fieldtype": "Date", 
+  "search_index": 0, 
+  "permlevel": 0, 
+  "in_filter": 1
+ }, 
+ {
+  "oldfieldtype": "Date", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Final Confirmation Date", 
+  "oldfieldname": "final_confirmation_date", 
+  "fieldname": "final_confirmation_date", 
+  "fieldtype": "Date", 
+  "search_index": 0, 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Date", 
+  "doctype": "DocField", 
+  "label": "Contract End Date", 
+  "oldfieldname": "contract_end_date", 
+  "fieldname": "contract_end_date", 
+  "fieldtype": "Date", 
+  "search_index": 0, 
+  "permlevel": 0, 
+  "in_filter": 1
+ }, 
+ {
+  "oldfieldtype": "Date", 
+  "doctype": "DocField", 
+  "label": "Date Of Retirement", 
+  "oldfieldname": "date_of_retirement", 
+  "fieldname": "date_of_retirement", 
+  "fieldtype": "Date", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Job Profile", 
+  "fieldname": "job_profile", 
+  "fieldtype": "Section Break", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "width": "50%", 
+  "fieldname": "column_break2", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Link", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Branch", 
+  "oldfieldname": "branch", 
+  "options": "Branch", 
+  "fieldname": "branch", 
+  "fieldtype": "Link", 
+  "reqd": 0, 
+  "permlevel": 0, 
+  "in_filter": 1
+ }, 
+ {
+  "oldfieldtype": "Link", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Department", 
+  "oldfieldname": "department", 
+  "options": "Department", 
+  "fieldname": "department", 
+  "fieldtype": "Link", 
+  "reqd": 0, 
+  "permlevel": 0, 
+  "in_filter": 1
+ }, 
+ {
+  "oldfieldtype": "Link", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Designation", 
+  "oldfieldname": "designation", 
+  "permlevel": 0, 
+  "fieldname": "designation", 
+  "fieldtype": "Link", 
+  "search_index": 1, 
+  "reqd": 0, 
+  "options": "Designation", 
+  "in_filter": 1
+ }, 
+ {
+  "oldfieldtype": "Link", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Grade", 
+  "oldfieldname": "grade", 
+  "options": "Grade", 
+  "fieldname": "grade", 
+  "fieldtype": "Link", 
+  "reqd": 0, 
+  "permlevel": 0, 
+  "in_filter": 1
+ }, 
+ {
+  "oldfieldtype": "Link", 
+  "doctype": "DocField", 
+  "label": "Reports to", 
+  "oldfieldname": "reports_to", 
+  "options": "Employee", 
+  "fieldname": "reports_to", 
+  "fieldtype": "Link", 
+  "permlevel": 0
+ }, 
+ {
+  "description": "Provide email id registered in company", 
+  "oldfieldtype": "Data", 
+  "doctype": "DocField", 
+  "label": "Email (By company)", 
+  "oldfieldname": "company_email", 
+  "fieldname": "company_email", 
+  "fieldtype": "Data", 
+  "reqd": 0, 
+  "permlevel": 0, 
+  "in_filter": 1
+ }, 
+ {
+  "oldfieldtype": "Section Break", 
+  "doctype": "DocField", 
+  "label": "Salary Information", 
+  "width": "50%", 
+  "fieldname": "salary_information", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Select", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Salary Mode", 
+  "oldfieldname": "salary_mode", 
+  "trigger": "Client", 
+  "fieldname": "salary_mode", 
+  "fieldtype": "Select", 
+  "options": "\nBank\nCash\nCheque", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Link", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Bank Name", 
+  "oldfieldname": "bank_name", 
+  "permlevel": 0, 
+  "fieldname": "bank_name", 
+  "fieldtype": "Data", 
+  "depends_on": "eval:doc.salary_mode == 'Bank'", 
+  "hidden": 0, 
+  "options": "Suggest", 
+  "in_filter": 1
+ }, 
+ {
+  "oldfieldtype": "Data", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Bank A/C No.", 
+  "oldfieldname": "bank_ac_no", 
+  "fieldname": "bank_ac_no", 
+  "fieldtype": "Data", 
+  "depends_on": "eval:doc.salary_mode == 'Bank'", 
+  "hidden": 0, 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Data", 
+  "doctype": "DocField", 
+  "label": "ESIC CARD No", 
+  "oldfieldname": "esic_card_no", 
+  "fieldname": "esic_card_no", 
+  "fieldtype": "Data", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Data", 
+  "doctype": "DocField", 
+  "label": "PF Number", 
+  "oldfieldname": "pf_number", 
+  "fieldname": "pf_number", 
+  "fieldtype": "Data", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Data", 
+  "doctype": "DocField", 
+  "label": "Gratuity LIC ID", 
+  "oldfieldname": "gratuity_lic_id", 
+  "fieldname": "gratuity_lic_id", 
+  "fieldtype": "Data", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Contact Details", 
+  "fieldname": "contact_details", 
+  "fieldtype": "Section Break", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "width": "50%", 
+  "fieldname": "column_break3", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Cell Number", 
+  "fieldname": "cell_number", 
+  "fieldtype": "Data", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Personal Email", 
+  "fieldname": "personal_email", 
+  "fieldtype": "Data", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Int", 
+  "doctype": "DocField", 
+  "label": "Notice - Number of Days", 
+  "oldfieldname": "notice_number_of_days", 
+  "fieldname": "notice_number_of_days", 
+  "fieldtype": "Int", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Emergency Contact Details", 
+  "options": "<b>Emergency Contact Details</b>", 
+  "fieldname": "emergency_contact_details", 
+  "fieldtype": "HTML", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Person To Be Contacted", 
+  "fieldname": "person_to_be_contacted", 
+  "fieldtype": "Data", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Relation", 
+  "fieldname": "relation", 
+  "fieldtype": "Data", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Emergency Phone Number", 
+  "fieldname": "emergency_phone_number", 
+  "fieldtype": "Data", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "width": "50%", 
+  "fieldname": "column_break4", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Permanent Accommodation Type", 
+  "options": "\nRented\nOwned", 
+  "fieldname": "permanent_accommodation_type", 
+  "fieldtype": "Select", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Permanent Address", 
+  "fieldname": "permanent_address", 
+  "fieldtype": "Small Text", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Current Accommodation Type", 
+  "options": "\nRented\nOwned", 
+  "fieldname": "current_accommodation_type", 
+  "fieldtype": "Select", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Current Address", 
+  "fieldname": "current_address", 
+  "fieldtype": "Small Text", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Personal Details", 
+  "fieldname": "personal_details", 
+  "fieldtype": "Section Break", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "width": "50%", 
+  "fieldname": "column_break5", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "PAN Number", 
+  "fieldname": "pan_number", 
+  "fieldtype": "Data", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Passport Number", 
+  "fieldname": "passport_number", 
+  "fieldtype": "Data", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Date of Issue", 
+  "fieldname": "date_of_issue", 
+  "fieldtype": "Date", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Valid Upto", 
+  "fieldname": "valid_upto", 
+  "fieldtype": "Date", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Button", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Salary Structure", 
+  "trigger": "Client", 
+  "fieldname": "salary_structure", 
+  "fieldtype": "Button", 
+  "hidden": 1, 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Place of Issue", 
+  "fieldname": "place_of_issue", 
+  "fieldtype": "Data", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Marital Status", 
+  "options": "\nSingle\nMarried\nDivorced\nWidowed", 
+  "fieldname": "marital_status", 
+  "fieldtype": "Select", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Blood Group", 
+  "options": "\nA+\nA-\nB+\nB-\nAB+\nAB-\nO+\nO-", 
+  "fieldname": "blood_group", 
+  "fieldtype": "Select", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "width": "50%", 
+  "fieldname": "column_break6", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "description": "Here you can maintain family details like name and occupation of parent, spouse and children", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Family Background", 
+  "fieldname": "family_background", 
+  "fieldtype": "Small Text", 
+  "permlevel": 0
+ }, 
+ {
+  "description": "Here you can maintain height, weight, allergies, medical concerns etc", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Health Details", 
+  "fieldname": "health_details", 
+  "fieldtype": "Small Text", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Educational Qualification", 
+  "fieldname": "educational_qualification", 
+  "fieldtype": "Section Break", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Educational Qualification Details", 
+  "options": "Employee Education", 
+  "fieldname": "educational_qualification_details", 
+  "fieldtype": "Table", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Career History", 
+  "fieldname": "career_history", 
+  "fieldtype": "Section Break", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Previous Work Experience", 
+  "options": "Simple", 
+  "fieldname": "previous_work_experience", 
+  "fieldtype": "Section Break", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Employee External Work History", 
+  "options": "Employee External Work History", 
+  "fieldname": "previous_experience_details", 
+  "fieldtype": "Table", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "History In Company", 
+  "options": "Simple", 
+  "fieldname": "history_in_company", 
+  "fieldtype": "Section Break", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Employee Internal Work Historys", 
+  "options": "Employee Internal Work History", 
+  "fieldname": "experience_in_company_details", 
+  "fieldtype": "Table", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Section Break", 
+  "doctype": "DocField", 
+  "label": "Exit", 
+  "fieldname": "exit", 
+  "fieldtype": "Section Break", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "width": "50%", 
+  "fieldname": "column_break7", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Date", 
+  "doctype": "DocField", 
+  "label": "Resignation Letter Date", 
+  "oldfieldname": "resignation_letter_date", 
+  "fieldname": "resignation_letter_date", 
+  "fieldtype": "Date", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Date", 
+  "doctype": "DocField", 
+  "label": "Relieving Date", 
+  "oldfieldname": "relieving_date", 
+  "fieldname": "relieving_date", 
+  "fieldtype": "Date", 
+  "permlevel": 0, 
+  "in_filter": 1
+ }, 
+ {
+  "oldfieldtype": "Data", 
+  "doctype": "DocField", 
+  "label": "Reason for Leaving", 
+  "oldfieldname": "reason_for_leaving", 
+  "fieldname": "reason_for_leaving", 
+  "fieldtype": "Data", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Select", 
+  "doctype": "DocField", 
+  "label": "Leave Encashed?", 
+  "oldfieldname": "leave_encashed", 
+  "options": "\nYes\nNo", 
+  "fieldname": "leave_encashed", 
+  "fieldtype": "Select", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Date", 
+  "doctype": "DocField", 
+  "label": "Encashment Date", 
+  "oldfieldname": "encashment_date", 
+  "fieldname": "encashment_date", 
+  "fieldtype": "Date", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Column Break", 
+  "doctype": "DocField", 
+  "label": "Exit Interview Details", 
+  "oldfieldname": "col_brk6", 
+  "width": "50%", 
+  "fieldname": "exit_interview_details", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Date", 
+  "doctype": "DocField", 
+  "label": "Held On", 
+  "oldfieldname": "held_on", 
+  "fieldname": "held_on", 
+  "fieldtype": "Date", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Select", 
+  "doctype": "DocField", 
+  "label": "Reason for Resignation", 
+  "oldfieldname": "reason_for_resignation", 
+  "options": "\nBetter Prospects\nHealth Concerns", 
+  "fieldname": "reason_for_resignation", 
+  "fieldtype": "Select", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Data", 
+  "doctype": "DocField", 
+  "label": "New Workplace", 
+  "oldfieldname": "new_workplace", 
+  "fieldname": "new_workplace", 
+  "fieldtype": "Data", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Text", 
+  "doctype": "DocField", 
+  "label": "Feedback", 
+  "oldfieldname": "feedback", 
+  "fieldname": "feedback", 
+  "fieldtype": "Small Text", 
+  "permlevel": 0
+ }, 
+ {
+  "print_hide": 1, 
+  "doctype": "DocField", 
+  "label": "File List", 
+  "fieldname": "file_list", 
+  "fieldtype": "Text", 
+  "hidden": 1, 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Small Text", 
+  "doctype": "DocField", 
+  "label": "Trash Reason", 
+  "oldfieldname": "trash_reason", 
+  "fieldname": "trash_reason", 
+  "fieldtype": "Small Text", 
+  "permlevel": 1
+ }, 
+ {
+  "create": 0, 
+  "doctype": "DocPerm", 
+  "write": 0, 
+  "role": "Employee", 
+  "cancel": 0, 
+  "permlevel": 0, 
+  "match": "employee"
+ }, 
+ {
+  "create": 0, 
+  "doctype": "DocPerm", 
+  "write": 0, 
+  "role": "Employee", 
+  "cancel": 0, 
+  "permlevel": 1
+ }, 
+ {
+  "create": 1, 
+  "doctype": "DocPerm", 
+  "write": 1, 
+  "role": "HR User", 
+  "cancel": 1, 
+  "permlevel": 0, 
+  "match": "company"
+ }, 
+ {
+  "create": 1, 
+  "doctype": "DocPerm", 
+  "write": 1, 
+  "role": "HR Manager", 
+  "cancel": 1, 
+  "permlevel": 0
+ }, 
+ {
+  "create": 0, 
+  "doctype": "DocPerm", 
+  "write": 0, 
+  "role": "HR User", 
+  "cancel": 0, 
+  "permlevel": 1
+ }, 
+ {
+  "create": 0, 
+  "doctype": "DocPerm", 
+  "write": 0, 
+  "role": "HR Manager", 
+  "cancel": 0, 
+  "permlevel": 1
+ }
 ]
\ No newline at end of file
diff --git a/hr/doctype/employee_external_work_history/employee_external_work_history.txt b/hr/doctype/employee_external_work_history/employee_external_work_history.txt
index 167675a..8587320 100644
--- a/hr/doctype/employee_external_work_history/employee_external_work_history.txt
+++ b/hr/doctype/employee_external_work_history/employee_external_work_history.txt
@@ -1,120 +1,75 @@
-# DocType, Employee External Work History
 [
-
-	# These values are common in all dictionaries
-	{
-		'creation': '2012-03-27 14:35:59',
-		'docstatus': 0,
-		'modified': '2012-03-27 14:35:59',
-		'modified_by': u'Administrator',
-		'owner': u'Administrator'
-	},
-
-	# These values are common for all DocType
-	{
-		'colour': u'White:FFF',
-		'doctype': 'DocType',
-		'istable': 1,
-		'module': u'HR',
-		'name': '__common__',
-		'section_style': u'Simple',
-		'server_code_error': u' ',
-		'show_in_menu': 0,
-		'version': 3
-	},
-
-	# These values are common for all DocField
-	{
-		'doctype': u'DocField',
-		'name': '__common__',
-		'parent': u'Employee External Work History',
-		'parentfield': u'fields',
-		'parenttype': u'DocType',
-		'permlevel': 0
-	},
-
-	# These values are common for all DocPerm
-	{
-		'create': 1,
-		'doctype': u'DocPerm',
-		'name': '__common__',
-		'parent': u'Employee External Work History',
-		'parentfield': u'permissions',
-		'parenttype': u'DocType',
-		'permlevel': 0,
-		'read': 1,
-		'role': u'All',
-		'write': 1
-	},
-
-	# DocType, Employee External Work History
-	{
-		'doctype': 'DocType',
-		'name': u'Employee External Work History'
-	},
-
-	# DocPerm
-	{
-		'doctype': u'DocPerm'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'company_name',
-		'fieldtype': u'Data',
-		'label': u'Company',
-		'oldfieldname': u'company_name',
-		'oldfieldtype': u'Data'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'designation',
-		'fieldtype': u'Data',
-		'label': u'Designation',
-		'oldfieldname': u'designation',
-		'oldfieldtype': u'Data'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'salary',
-		'fieldtype': u'Currency',
-		'label': u'Salary',
-		'oldfieldname': u'salary',
-		'oldfieldtype': u'Currency'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'address',
-		'fieldtype': u'Small Text',
-		'label': u'Address',
-		'oldfieldname': u'address',
-		'oldfieldtype': u'Small Text'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'contact',
-		'fieldtype': u'Data',
-		'label': u'Contact',
-		'oldfieldname': u'contact',
-		'oldfieldtype': u'Data'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'total_experience',
-		'fieldtype': u'Data',
-		'label': u'Total Experience',
-		'oldfieldname': u'total_experience',
-		'oldfieldtype': u'Data'
-	}
+ {
+  "owner": "Administrator", 
+  "docstatus": 0, 
+  "creation": "2012-07-03 13:29:41", 
+  "modified_by": "Administrator", 
+  "modified": "2012-11-30 11:57:58"
+ }, 
+ {
+  "istable": 1, 
+  "name": "__common__", 
+  "doctype": "DocType", 
+  "module": "HR"
+ }, 
+ {
+  "name": "__common__", 
+  "parent": "Employee External Work History", 
+  "doctype": "DocField", 
+  "parenttype": "DocType", 
+  "permlevel": 0, 
+  "parentfield": "fields"
+ }, 
+ {
+  "name": "Employee External Work History", 
+  "doctype": "DocType"
+ }, 
+ {
+  "oldfieldtype": "Data", 
+  "doctype": "DocField", 
+  "label": "Company", 
+  "oldfieldname": "company_name", 
+  "fieldname": "company_name", 
+  "fieldtype": "Data"
+ }, 
+ {
+  "oldfieldtype": "Data", 
+  "doctype": "DocField", 
+  "label": "Designation", 
+  "oldfieldname": "designation", 
+  "fieldname": "designation", 
+  "fieldtype": "Data"
+ }, 
+ {
+  "oldfieldtype": "Currency", 
+  "doctype": "DocField", 
+  "label": "Salary", 
+  "oldfieldname": "salary", 
+  "fieldname": "salary", 
+  "fieldtype": "Currency"
+ }, 
+ {
+  "oldfieldtype": "Small Text", 
+  "doctype": "DocField", 
+  "label": "Address", 
+  "oldfieldname": "address", 
+  "fieldname": "address", 
+  "fieldtype": "Small Text"
+ }, 
+ {
+  "oldfieldtype": "Data", 
+  "doctype": "DocField", 
+  "label": "Contact", 
+  "oldfieldname": "contact", 
+  "fieldname": "contact", 
+  "fieldtype": "Data"
+ }, 
+ {
+  "oldfieldtype": "Data", 
+  "doctype": "DocField", 
+  "label": "Total Experience", 
+  "oldfieldname": "total_experience", 
+  "fieldname": "total_experience", 
+  "fieldtype": "Data"
+ }
 ]
\ No newline at end of file
diff --git a/hr/doctype/expense_claim/expense_claim.js b/hr/doctype/expense_claim/expense_claim.js
index 5ed0d37..d890102 100644
--- a/hr/doctype/expense_claim/expense_claim.js
+++ b/hr/doctype/expense_claim/expense_claim.js
@@ -100,8 +100,6 @@
 	cur_frm.cscript.calculate_total(doc,cdt,cdn);
 }
 
-wn.require('app/setup/doctype/notification_control/notification_control.js');
-
 cur_frm.cscript.approve = function(doc,cdt,cdn){
 	cur_frm.cscript.calculate_total(doc,cdt,cdn);
 
@@ -248,12 +246,9 @@
 }
 
 cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
-	var args = {
-		type: 'Expense Claim',
-		doctype: 'Expense Claim',
-		send_to: doc.exp_approver
+	if(cint(wn.boot.notification_settings.expense_claim)) {
+		cur_frm.email_doc(wn.boot.notification_settings.expense_claim);
 	}
-	cur_frm.cscript.notify(doc, args);
 }
 
 cur_frm.fields_dict.employee.get_query = erpnext.utils.employee_query;
\ No newline at end of file
diff --git a/hr/doctype/expense_claim/expense_claim.py b/hr/doctype/expense_claim/expense_claim.py
index 64b0da3..66434bb 100644
--- a/hr/doctype/expense_claim/expense_claim.py
+++ b/hr/doctype/expense_claim/expense_claim.py
@@ -14,24 +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/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import add_days, cstr
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.code import get_obj
+from webnotes import form, msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/hr/doctype/holiday_list/holiday_list.py b/hr/doctype/holiday_list/holiday_list.py
index ff342d0..63b1af4 100644
--- a/hr/doctype/holiday_list/holiday_list.py
+++ b/hr/doctype/holiday_list/holiday_list.py
@@ -14,26 +14,19 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import add_days, add_years, cint, getdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.doc import addchild, make_autoname
+from webnotes.model.wrapper import copy_doclist
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 
 import datetime
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/hr/doctype/leave_allocation/leave_allocation.py b/hr/doctype/leave_allocation/leave_allocation.py
index 1772f2c..9e830b9 100755
--- a/hr/doctype/leave_allocation/leave_allocation.py
+++ b/hr/doctype/leave_allocation/leave_allocation.py
@@ -14,12 +14,10 @@
 # You should have received a copy of the GNU General Public License
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 from webnotes.utils import cint, flt
 from webnotes import msgprint
-set = webnotes.conn.set
 sql = webnotes.conn.sql
 	
 class DocType:
diff --git a/hr/doctype/leave_application/leave_application.js b/hr/doctype/leave_application/leave_application.js
index e8952ca..00df476 100755
--- a/hr/doctype/leave_application/leave_application.js
+++ b/hr/doctype/leave_application/leave_application.js
@@ -14,39 +14,49 @@
 // You should have received a copy of the GNU General Public License
 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-// ****************************************** onload ********************************************************
 cur_frm.cscript.onload = function(doc, dt, dn) {
   if(!doc.posting_date) set_multiple(dt,dn,{posting_date:get_today()});
 }
 
+cur_frm.cscript.refresh = function(doc, dt, dn) {
+	cur_frm.set_intro("");
+	if(doc.__islocal && !in_list(user_roles, "HR User")) {
+		cur_frm.set_intro("Fill the form and save it")
+	} else {
+		if(in_list(user_roles, "HR User")) {
+			if(doc.status=="Open") {
+				cur_frm.set_intro("Please Approve (and Submit) or Reject, or re-assign to applicant for further review.");				
+			}
+		} else {
+			if(doc.status=="Open") {
+				cur_frm.set_intro("Leave application is pending approval.");
+			} else if(doc.status=="Approved") {
+				cur_frm.set_intro("Leave application has been approved.");
+			} else if(doc.status=="Rejected") {
+				cur_frm.set_intro("Leave application has been rejected.");
+			}
+		}
+	}
+	
+	if(doc.status=="Approved" && doc.docstatus!=1) {
+		cur_frm.savesubmit()
+	}
+}
 
-// ************************************** client triggers ***************************************************
-// ---------
-// employee
-// ---------
 cur_frm.add_fetch('employee','employee_name','employee_name');
 
 cur_frm.cscript.employee = function (doc, dt, dn){
   get_leave_balance(doc, dt, dn);
 }
 
-// ------------
-// fiscal_year
-// ------------
 cur_frm.cscript.fiscal_year = function (doc, dt, dn){
   get_leave_balance(doc, dt, dn);
 }
 
-// -----------
-// leave type
-// -----------
 cur_frm.cscript.leave_type = function (doc, dt, dn){
   get_leave_balance(doc, dt, dn);
 }
 
-// ---------
-// half day
-// ---------
 cur_frm.cscript.half_day = function(doc, dt, dn) {
   if(doc.from_date) {
     set_multiple(dt,dn,{to_date:doc.from_date});
@@ -54,9 +64,6 @@
   }
 }
 
-// ---------
-// from date
-// ---------
 cur_frm.cscript.from_date = function(doc, dt, dn) {
   if(cint(doc.half_day) == 1){
     set_multiple(dt,dn,{to_date:doc.from_date});
@@ -64,9 +71,6 @@
   calculate_total_days(doc, dt, dn);
 }
 
-// --------
-// to date
-// --------
 cur_frm.cscript.to_date = function(doc, dt, dn) {
   if(cint(doc.half_day) == 1 && cstr(doc.from_date) && doc.from_date != doc.to_date){
     msgprint("To Date should be same as From Date for Half Day leave");
@@ -75,20 +79,11 @@
   calculate_total_days(doc, dt, dn);
 }
 
-
-// ******************************************* utilities ****************************************************
-
-// ------------------
-// get leave balance
-// ------------------
 get_leave_balance = function(doc, dt, dn) {
   if(doc.employee && doc.leave_type && doc.fiscal_year)
     get_server_fields('get_leave_balance', '','', doc, dt, dn, 1);
 }
 
-// ---------------
-// calculate days
-// ---------------
 calculate_total_days = function(doc, dt, dn) {
   if(doc.from_date && doc.to_date){
     if(cint(doc.half_day) == 1) set_multiple(dt,dn,{total_leave_days:0.5});
diff --git a/hr/doctype/leave_application/leave_application.py b/hr/doctype/leave_application/leave_application.py
index e71a26a..dcc5b50 100755
--- a/hr/doctype/leave_application/leave_application.py
+++ b/hr/doctype/leave_application/leave_application.py
@@ -14,36 +14,22 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cint, cstr, date_diff, flt, formatdate, getdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
+from webnotes import form, msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 import datetime
 	
-# -----------------------------------------------------------------------------------------
 class DocType:
 	def __init__(self, doc, doclist):
 		self.doc = doc
 		self.doclist = doclist 
 
-
-# ******************************************** client triggers ***********************************************
-
-	# ------------------
-	# get leave balance
-	# ------------------
 	def get_leave_balance(self):
 		leave_all = sql("select total_leaves_allocated from `tabLeave Allocation` where employee = '%s' and leave_type = '%s' and fiscal_year = '%s' and docstatus = 1" % (self.doc.employee, self.doc.leave_type, self.doc.fiscal_year))
 		leave_all = leave_all and flt(leave_all[0][0]) or 0
@@ -52,10 +38,6 @@
 		ret = {'leave_balance':leave_all - leave_app}
 		return ret
 
-
-# ************************************************ utilities *************************************************
-
-	# -------------------
 	def get_holidays(self):
 		"""
 			get total holidays
@@ -65,10 +47,6 @@
 			tot_hol = sql("select count(*) from `tabHoliday` h1, `tabHoliday List` h2 where h1.parent = h2.name and h1.holiday_date between '%s' and '%s' and ifnull(h2.is_default,0) = 1 and h2.fiscal_year = %s"% (self.doc.from_date, self.doc.to_date, self.doc.fiscal_year))
 		return tot_hol and flt(tot_hol[0][0]) or 0
 
-	
-	# ---------------------
-	# get total leave days
-	# ---------------------
 	def get_total_leave_days(self):
 		"""
 			Calculates total leave days based on input and holidays
@@ -82,27 +60,15 @@
 			}
 		return ret
 
-
-# ************************************************ validate *************************************************
-
-	# -----------------
-	# validate to date
-	# -----------------
 	def validate_to_date(self):
 		if self.doc.from_date and self.doc.to_date and (getdate(self.doc.to_date) < getdate(self.doc.from_date)):
 			msgprint("To date cannot be before from date")
 			raise Exception
-
-	# --------------------------------
-	# check whether leave type is lwp
-	# --------------------------------
+			
 	def is_lwp(self):
 		lwp = sql("select is_lwp from `tabLeave Type` where name = %s", self.doc.leave_type)
 		return lwp and cint(lwp[0][0]) or 0
 
-	# ------------------------
-	# validate balance leaves
-	# ------------------------
 	def validate_balance_leaves(self):
 		if self.doc.from_date and self.doc.to_date and not self.is_lwp():
 			bal = self.get_leave_balance()
@@ -111,12 +77,8 @@
 			set(self.doc,'leave_balance',flt(bal['leave_balance']))
 			set(self.doc,'total_leave_days',flt(tot_leaves['total_leave_days']))
 			if flt(bal['leave_balance']) < flt(tot_leaves['total_leave_days']):
-				msgprint("Employee : %s cannot apply for %s of more than %s days" % (self.doc.employee, self.doc.leave_type, flt(bal['leave_balance'])))
-				raise Exception
+				msgprint("Warning : There is not enough leave balance")
 
-	#
-	# validate overlapping leaves
-	#
 	def validate_leave_overlap(self):
 		for d in sql("""select name, leave_type, posting_date, from_date, to_date 
 			from `tabLeave Application` 
@@ -128,9 +90,6 @@
  
 			msgprint("Employee : %s has already applied for %s between %s and %s on %s. Please refer Leave Application : %s" % (self.doc.employee, cstr(d['leave_type']), formatdate(d['from_date']), formatdate(d['to_date']), formatdate(d['posting_date']), d['name']), raise_exception = 1)
 
-	# ---------------------------------------------------------------------
-	# validate max days for which leave can be applied for particular type
-	# ---------------------------------------------------------------------
 	def validate_max_days(self):
 		max_days = sql("select max_days_allowed from `tabLeave Type` where name = '%s'" %(self.doc.leave_type))
 		max_days = max_days and flt(max_days[0][0]) or 0
@@ -138,12 +97,13 @@
 			msgprint("Sorry ! You cannot apply for %s for more than %s days" % (self.doc.leave_type, max_days))
 			raise Exception
 
-
-	# ---------
-	# validate
-	# ---------
 	def validate(self):
 		self.validate_to_date()
 		self.validate_balance_leaves()
 		self.validate_leave_overlap()
 		self.validate_max_days()
+		
+	def on_submit(self):
+		if self.doc.status != "Approved":
+			webnotes.msgprint("""Only Approved Leave Applications can be Submitted.""",
+				raise_exception=True)
diff --git a/hr/doctype/leave_application/leave_application.txt b/hr/doctype/leave_application/leave_application.txt
index c87c746..6a33df6 100644
--- a/hr/doctype/leave_application/leave_application.txt
+++ b/hr/doctype/leave_application/leave_application.txt
@@ -1,285 +1,239 @@
-# DocType, Leave Application
 [
-
-	# These values are common in all dictionaries
-	{
-		u'creation': '2012-05-15 12:14:45',
-		u'docstatus': 0,
-		u'modified': '2012-10-02 11:19:44',
-		u'modified_by': u'Administrator',
-		u'owner': u'Administrator'
-	},
-
-	# These values are common for all DocType
-	{
-		'_last_update': u'1310019491',
-		'autoname': u'LAP/.#####',
-		'colour': u'White:FFF',
-		u'doctype': u'DocType',
-		'document_type': u'Transaction',
-		'is_submittable': 1,
-		'module': u'HR',
-		u'name': u'__common__',
-		'search_fields': u'employee,employee_name,leave_type,from_date,to_date,total_leave_days,fiscal_year',
-		'section_style': u'Simple',
-		'show_in_menu': 0,
-		'subject': u'From %(employee_name)s, %(designation)s',
-		'tag_fields': u'leave_type',
-		'version': 1
-	},
-
-	# These values are common for all DocField
-	{
-		u'doctype': u'DocField',
-		u'name': u'__common__',
-		'parent': u'Leave Application',
-		'parentfield': u'fields',
-		'parenttype': u'DocType'
-	},
-
-	# These values are common for all DocPerm
-	{
-		u'doctype': u'DocPerm',
-		u'name': u'__common__',
-		'parent': u'Leave Application',
-		'parentfield': u'permissions',
-		'parenttype': u'DocType',
-		'read': 1
-	},
-
-	# DocType, Leave Application
-	{
-		u'doctype': u'DocType',
-		u'name': u'Leave Application'
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'column_break0',
-		'fieldtype': u'Column Break',
-		'permlevel': 0,
-		'width': u'50%'
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'employee',
-		'fieldtype': u'Link',
-		'in_filter': 1,
-		'label': u'Employee',
-		'options': u'Employee',
-		'permlevel': 0,
-		'reqd': 1,
-		'search_index': 1
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'employee_name',
-		'fieldtype': u'Data',
-		'in_filter': 1,
-		'label': u'Employee Name',
-		'permlevel': 1,
-		'search_index': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'leave_type',
-		'fieldtype': u'Select',
-		'in_filter': 1,
-		'label': u'Leave Type',
-		'options': u'link:Leave Type',
-		'permlevel': 0,
-		'reqd': 1,
-		'search_index': 1
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'leave_balance',
-		'fieldtype': u'Currency',
-		'label': u'Leave Balance',
-		'permlevel': 1
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'default': u'Today',
-		u'doctype': u'DocField',
-		'fieldname': u'posting_date',
-		'fieldtype': u'Date',
-		'label': u'Posting Date',
-		'no_copy': 1,
-		'permlevel': 1,
-		'reqd': 1
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'fiscal_year',
-		'fieldtype': u'Select',
-		'in_filter': 1,
-		'label': u'Fiscal Year',
-		'options': u'link:Fiscal Year',
-		'permlevel': 0,
-		'reqd': 1,
-		'search_index': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'column_break1',
-		'fieldtype': u'Column Break',
-		'permlevel': 0,
-		'width': u'50%'
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		u'doctype': u'DocField',
-		'fieldname': u'half_day',
-		'fieldtype': u'Check',
-		'label': u'Half Day',
-		'permlevel': 0,
-		'trigger': u'Client'
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		u'doctype': u'DocField',
-		'fieldname': u'from_date',
-		'fieldtype': u'Date',
-		'label': u'From Date',
-		'permlevel': 0,
-		'search_index': 1,
-		'trigger': u'Client'
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		u'doctype': u'DocField',
-		'fieldname': u'to_date',
-		'fieldtype': u'Date',
-		'label': u'To Date',
-		'permlevel': 0,
-		'search_index': 1,
-		'trigger': u'Client'
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'total_leave_days',
-		'fieldtype': u'Currency',
-		'label': u'Total Leave Days',
-		'permlevel': 1
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'description',
-		'fieldtype': u'Small Text',
-		'label': u'Description',
-		'permlevel': 0,
-		'width': u'300px'
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'letter_head',
-		'fieldtype': u'Link',
-		'label': u'Letter Head',
-		'options': u'Letter Head',
-		'permlevel': 0
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'amended_from',
-		'fieldtype': u'Data',
-		'label': u'Amended From',
-		'permlevel': 1
-	},
-
-	# DocField
-	{
-		u'doctype': u'DocField',
-		'fieldname': u'amendment_date',
-		'fieldtype': u'Date',
-		'label': u'Amendment Date',
-		'permlevel': 1
-	},
-
-	# DocPerm
-	{
-		'amend': 0,
-		'cancel': 0,
-		'create': 0,
-		u'doctype': u'DocPerm',
-		'match': u'owner',
-		'permlevel': 0,
-		'role': u'Employee',
-		'submit': 0,
-		'write': 0
-	},
-
-	# DocPerm
-	{
-		'amend': 1,
-		'cancel': 1,
-		'create': 1,
-		u'doctype': u'DocPerm',
-		'permlevel': 0,
-		'role': u'HR User',
-		'submit': 1,
-		'write': 1
-	},
-
-	# DocPerm
-	{
-		'amend': 1,
-		'cancel': 1,
-		'create': 1,
-		u'doctype': u'DocPerm',
-		'permlevel': 0,
-		'role': u'HR Manager',
-		'submit': 1,
-		'write': 1
-	},
-
-	# DocPerm
-	{
-		u'doctype': u'DocPerm',
-		'permlevel': 1,
-		'role': u'HR User'
-	},
-
-	# DocPerm
-	{
-		u'doctype': u'DocPerm',
-		'permlevel': 1,
-		'role': u'HR Manager'
-	},
-
-	# DocPerm
-	{
-		u'doctype': u'DocPerm',
-		'permlevel': 1,
-		'role': u'Employee'
-	}
+ {
+  "owner": "Administrator", 
+  "docstatus": 0, 
+  "creation": "2012-11-02 17:16:54", 
+  "modified_by": "Administrator", 
+  "modified": "2012-11-30 12:17:27"
+ }, 
+ {
+  "is_submittable": 1, 
+  "autoname": "LAP/.#####", 
+  "name": "__common__", 
+  "search_fields": "employee,employee_name,leave_type,from_date,to_date,total_leave_days,fiscal_year", 
+  "module": "HR", 
+  "doctype": "DocType", 
+  "document_type": "Transaction"
+ }, 
+ {
+  "name": "__common__", 
+  "parent": "Leave Application", 
+  "doctype": "DocField", 
+  "parenttype": "DocType", 
+  "parentfield": "fields"
+ }, 
+ {
+  "name": "__common__", 
+  "parent": "Leave Application", 
+  "read": 1, 
+  "doctype": "DocPerm", 
+  "parenttype": "DocType", 
+  "parentfield": "permissions"
+ }, 
+ {
+  "name": "Leave Application", 
+  "doctype": "DocType"
+ }, 
+ {
+  "default": "Open", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Status", 
+  "options": "Open\nApproved\nRejected", 
+  "fieldname": "status", 
+  "fieldtype": "Select", 
+  "permlevel": 3
+ }, 
+ {
+  "search_index": 1, 
+  "doctype": "DocField", 
+  "label": "Leave Type", 
+  "options": "link:Leave Type", 
+  "fieldname": "leave_type", 
+  "fieldtype": "Select", 
+  "reqd": 1, 
+  "permlevel": 0, 
+  "in_filter": 1
+ }, 
+ {
+  "search_index": 1, 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "From Date", 
+  "trigger": "Client", 
+  "fieldname": "from_date", 
+  "fieldtype": "Date", 
+  "reqd": 1, 
+  "permlevel": 0
+ }, 
+ {
+  "search_index": 1, 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "To Date", 
+  "trigger": "Client", 
+  "fieldname": "to_date", 
+  "fieldtype": "Date", 
+  "reqd": 1, 
+  "permlevel": 0
+ }, 
+ {
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Half Day", 
+  "trigger": "Client", 
+  "fieldname": "half_day", 
+  "fieldtype": "Check", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "width": "50%", 
+  "fieldname": "column_break1", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Leave Balance", 
+  "fieldname": "leave_balance", 
+  "fieldtype": "Currency", 
+  "permlevel": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Total Leave Days", 
+  "fieldname": "total_leave_days", 
+  "fieldtype": "Currency", 
+  "permlevel": 1
+ }, 
+ {
+  "search_index": 1, 
+  "doctype": "DocField", 
+  "label": "Employee", 
+  "options": "Employee", 
+  "fieldname": "employee", 
+  "fieldtype": "Link", 
+  "reqd": 1, 
+  "permlevel": 0, 
+  "in_filter": 1
+ }, 
+ {
+  "search_index": 0, 
+  "doctype": "DocField", 
+  "label": "Employee Name", 
+  "fieldname": "employee_name", 
+  "fieldtype": "Data", 
+  "permlevel": 1, 
+  "in_filter": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "sb10", 
+  "fieldtype": "Section Break", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Reason", 
+  "width": "300px", 
+  "fieldname": "description", 
+  "fieldtype": "Text Editor", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "HR Details", 
+  "fieldname": "sb12", 
+  "fieldtype": "Section Break", 
+  "permlevel": 2
+ }, 
+ {
+  "default": "Today", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Posting Date", 
+  "no_copy": 1, 
+  "fieldname": "posting_date", 
+  "fieldtype": "Date", 
+  "reqd": 1, 
+  "permlevel": 2
+ }, 
+ {
+  "search_index": 0, 
+  "doctype": "DocField", 
+  "label": "Fiscal Year", 
+  "options": "link:Fiscal Year", 
+  "fieldname": "fiscal_year", 
+  "fieldtype": "Select", 
+  "reqd": 1, 
+  "permlevel": 2, 
+  "in_filter": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Letter Head", 
+  "options": "Letter Head", 
+  "fieldname": "letter_head", 
+  "fieldtype": "Link", 
+  "permlevel": 2
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Amended From", 
+  "fieldname": "amended_from", 
+  "fieldtype": "Data", 
+  "permlevel": 2
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Amendment Date", 
+  "fieldname": "amendment_date", 
+  "fieldtype": "Date", 
+  "permlevel": 2
+ }, 
+ {
+  "create": 1, 
+  "doctype": "DocPerm", 
+  "write": 1, 
+  "role": "Employee", 
+  "permlevel": 0, 
+  "match": "employee"
+ }, 
+ {
+  "doctype": "DocPerm", 
+  "role": "All", 
+  "permlevel": 1
+ }, 
+ {
+  "amend": 1, 
+  "create": 1, 
+  "doctype": "DocPerm", 
+  "submit": 1, 
+  "write": 1, 
+  "role": "HR User", 
+  "cancel": 1, 
+  "permlevel": 0
+ }, 
+ {
+  "amend": 0, 
+  "create": 0, 
+  "doctype": "DocPerm", 
+  "submit": 0, 
+  "write": 1, 
+  "role": "HR User", 
+  "cancel": 0, 
+  "permlevel": 2
+ }, 
+ {
+  "doctype": "DocPerm", 
+  "role": "All", 
+  "permlevel": 3
+ }, 
+ {
+  "doctype": "DocPerm", 
+  "write": 1, 
+  "role": "HR User", 
+  "permlevel": 3
+ }
 ]
\ No newline at end of file
diff --git a/hr/doctype/leave_application/leave_application_list.js b/hr/doctype/leave_application/leave_application_list.js
index 4bcbab8..4c80e7f 100644
--- a/hr/doctype/leave_application/leave_application_list.js
+++ b/hr/doctype/leave_application/leave_application_list.js
@@ -3,6 +3,7 @@
 	init: function(d) {
 		this._super(d)
 		this.fields = this.fields.concat([
+			"`tabLeave Application`.status",
 			"`tabLeave Application`.employee_name",
 			"`tabLeave Application`.total_leave_days",
 			"`tabLeave Application`.from_date",
@@ -12,8 +13,21 @@
 		this.stats = this.stats.concat(['company']);
 	},
 
+	label_style: {
+		"status": {
+			"Open": "danger",
+			"Approved": "success",
+			"Rejected": "info",
+		}
+	},
+	
 	prepare_data: function(data) {
 		this._super(data);
+
+		data.label_style = this.label_style.status[data.status];		
+		data.status_html = repl('<span class="label \
+			label-%(label_style)s">%(status)s</span>', data);
+
 		data.from_date = wn.datetime.str_to_user(data.from_date);
 		data.to_date = wn.datetime.str_to_user(data.to_date);
 		data.date_range = (data.from_date === data.to_date)
@@ -28,10 +42,10 @@
 		{width: '3%', content: 'check'},
 		{width: '5%', content:'avatar'},
 		{width: '3%', content:'docstatus'},
+		{width: '15%', content:'status_html'},
 		{width: '12%', content:'name'},
-		{width: '37%', content:'employee_name+tags'},
-		{width: '10%', content:'total_leave_days',
-			css: {'color':'#777'}},
-		{width: '30%', content:'date_range'},
+		{width: '25%', content:'employee_name+tags'},
+		{width: '25%', content:'date_range'},
+		{width: '12%', content:'modified'},
 	]
 });
\ No newline at end of file
diff --git a/hr/doctype/leave_control_panel/leave_control_panel.py b/hr/doctype/leave_control_panel/leave_control_panel.py
index 2e1f13c..cb10e71 100644
--- a/hr/doctype/leave_control_panel/leave_control_panel.py
+++ b/hr/doctype/leave_control_panel/leave_control_panel.py
@@ -14,24 +14,18 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cint, cstr, flt, now, nowdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.doc import Document
+from webnotes.model.wrapper import copy_doclist
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/hr/doctype/salary_manager/salary_manager.py b/hr/doctype/salary_manager/salary_manager.py
index 7dea5d0..d8f1288 100644
--- a/hr/doctype/salary_manager/salary_manager.py
+++ b/hr/doctype/salary_manager/salary_manager.py
@@ -14,23 +14,18 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cint, flt
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
+from webnotes.model.doc import Document
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/hr/doctype/salary_slip/salary_slip.py b/hr/doctype/salary_slip/salary_slip.py
index 3a0396f..7886281 100644
--- a/hr/doctype/salary_slip/salary_slip.py
+++ b/hr/doctype/salary_slip/salary_slip.py
@@ -14,24 +14,18 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import add_days, cint, cstr, flt, getdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
+from webnotes.model.doc import make_autoname
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 from utilities.transaction_base import TransactionBase
 
 class DocType(TransactionBase):
diff --git a/hr/doctype/salary_structure/salary_structure.py b/hr/doctype/salary_structure/salary_structure.py
index d0b4e5b..d07be6e 100644
--- a/hr/doctype/salary_structure/salary_structure.py
+++ b/hr/doctype/salary_structure/salary_structure.py
@@ -14,24 +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/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr, flt
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.doc import addchild, make_autoname
+from webnotes.model.wrapper import copy_doclist
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/patches/april_2012/change_cacheitem_schema.py b/patches/april_2012/change_cacheitem_schema.py
deleted file mode 100644
index 4d46f2c..0000000
--- a/patches/april_2012/change_cacheitem_schema.py
+++ /dev/null
@@ -1,6 +0,0 @@
-from __future__ import unicode_literals
-def execute():
-	import webnotes
-	webnotes.conn.commit()
-	webnotes.conn.sql("alter table __CacheItem modify `value` longtext")
-	webnotes.conn.begin()
diff --git a/patches/before_jan_2012/index_patch.py b/patches/before_jan_2012/index_patch.py
index 2203bac..7971fbf 100644
--- a/patches/before_jan_2012/index_patch.py
+++ b/patches/before_jan_2012/index_patch.py
@@ -21,7 +21,7 @@
 
 import webnotes
 sql = webnotes.conn.sql
-from webnotes.utils import cint, cstr
+from webnotes.utils import cstr
 
 def create_proper_index():
 	from webnotes.modules.export_file import export_to_files
diff --git a/patches/jan_mar_2012/rename_dt.py b/patches/jan_mar_2012/rename_dt.py
index 31a434c..c163b49 100644
--- a/patches/jan_mar_2012/rename_dt.py
+++ b/patches/jan_mar_2012/rename_dt.py
@@ -2,7 +2,6 @@
 import webnotes
 import conf
 import webnotes.model
-from webnotes.model.code import get_obj
 from wnf import replace_code
 from termcolor import colored
 from webnotes.modules import reload_doc
diff --git a/patches/jan_mar_2012/website/feed.py b/patches/jan_mar_2012/website/feed.py
index b815698..eae8871 100644
--- a/patches/jan_mar_2012/website/feed.py
+++ b/patches/jan_mar_2012/website/feed.py
@@ -16,7 +16,6 @@
 
 from __future__ import unicode_literals
 import webnotes
-from webnotes.model.doc import Document
 from webnotes.modules import reload_doc
 
 def execute():
diff --git a/patches/june_2012/cache_item_table.py b/patches/june_2012/cache_item_table.py
deleted file mode 100644
index 771b409..0000000
--- a/patches/june_2012/cache_item_table.py
+++ /dev/null
@@ -1,12 +0,0 @@
-from __future__ import unicode_literals
-def execute():
-	"""drop and create __CacheItem table again"""
-	import webnotes
-	webnotes.conn.commit()
-	webnotes.conn.sql("drop table __CacheItem")
-	webnotes.conn.sql("""create table __CacheItem(
-		`key` VARCHAR(180) NOT NULL PRIMARY KEY,
-		`value` LONGTEXT,
-		`expires_on` DATETIME
-		) ENGINE=MyISAM DEFAULT CHARSET=utf8""")
-	webnotes.conn.begin()
\ No newline at end of file
diff --git a/patches/mar_2012/doctype_get_refactor.py b/patches/mar_2012/doctype_get_refactor.py
index 26cee77..66339db 100644
--- a/patches/mar_2012/doctype_get_refactor.py
+++ b/patches/mar_2012/doctype_get_refactor.py
@@ -116,8 +116,8 @@
 		obj.make_file_list()
 		from webnotes.model.db_schema import updatedb
 		updatedb(obj.doc.name)
-		from webnotes.utils.cache import CacheItem
-		CacheItem(obj.doc.name).clear()
+
+		webnotes.clear_cache(doctype=obj.doc.name)
 
 def change_to_decimal():
 	print "in change to decimal"
diff --git a/patches/may_2012/remove_communication_log.py b/patches/may_2012/remove_communication_log.py
index 28bfca1..e44e673 100644
--- a/patches/may_2012/remove_communication_log.py
+++ b/patches/may_2012/remove_communication_log.py
@@ -50,9 +50,8 @@
 	webnotes.conn.sql("""\
 		delete from `tabProperty Setter`
 		where doc_type='Communication Log'""")
-		
-	from webnotes.utils.cache import CacheItem
-	CacheItem('Communication').clear()
+
+	webnotes.clear_cache(doctype="Communication")
 
 def remove_communication_log():
 	import webnotes
diff --git a/patches/november_2012/add_employee_field_in_employee.py b/patches/november_2012/add_employee_field_in_employee.py
new file mode 100644
index 0000000..c8e5b36
--- /dev/null
+++ b/patches/november_2012/add_employee_field_in_employee.py
@@ -0,0 +1,6 @@
+import webnotes
+
+def execute():
+	webnotes.clear_perms("Employee")
+	webnotes.reload_doc("hr", "doctype", "employee")
+	webnotes.conn.sql("""update tabEmployee set employee=name""")
diff --git a/patches/november_2012/leave_application_cleanup.py b/patches/november_2012/leave_application_cleanup.py
new file mode 100644
index 0000000..18e69cf
--- /dev/null
+++ b/patches/november_2012/leave_application_cleanup.py
@@ -0,0 +1,9 @@
+import webnotes
+
+def execute():
+	webnotes.clear_perms("Leave Application")
+	webnotes.reload_doc("hr", "doctype", "leave_application")
+	webnotes.conn.sql("""update `tabLeave Application` set status='Approved'
+		where docstatus=1""")
+	webnotes.conn.sql("""update `tabLeave Application` set status='Open'
+		where docstatus=0""")		
\ No newline at end of file
diff --git a/patches/november_2012/production_order_patch.py b/patches/november_2012/production_order_patch.py
new file mode 100644
index 0000000..4bc0912
--- /dev/null
+++ b/patches/november_2012/production_order_patch.py
@@ -0,0 +1,12 @@
+def execute():
+	import webnotes
+	
+	webnotes.reload_doc("production", "doctype", "production_order")
+	webnotes.reload_doc("stock", "doctype", "stock_entry")
+	
+	webnotes.conn.sql("""update `tabProduction Order` 
+		set use_multi_level_bom = if(consider_sa_items='Yes', 0, 1)""")
+		
+	webnotes.conn.sql("""update `tabStock Entry` 
+		set use_multi_level_bom = if(consider_sa_items_as_raw_materials='Yes', 0, 1)""")
+	
\ No newline at end of file
diff --git a/patches/patch_list.py b/patches/patch_list.py
index 0bf4d3c..93fc08d 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -280,11 +280,6 @@
 	},
 	{
 		'patch_module': 'patches.april_2012',
-		'patch_file': 'change_cacheitem_schema',
-		'description': 'Modified datatype of `value` column from text to longtext'
-	},
-	{
-		'patch_module': 'patches.april_2012',
 		'patch_file': 'remove_default_from_rv_detail',
 		'description': ''
 	},
@@ -459,11 +454,6 @@
 		'description': "delete depracated doctypes of website module"
 	},
 	{
-		'patch_module': 'patches.june_2012',
-		'patch_file': 'cache_item_table',
-		'description': "create cache item table again"
-	},
-	{
 		'patch_module': 'patches.july_2012',
 		'patch_file': 'reload_pr_po_mapper',
 		'description': "order date should be greater than equal to request date"
@@ -699,4 +689,16 @@
 		'patch_module': 'patches.november_2012',
 		'patch_file': 'add_theme_to_profile',
 	},
+	{
+		'patch_module': 'patches.november_2012',
+		'patch_file': 'add_employee_field_in_employee',
+	},
+	{
+		'patch_module': 'patches.november_2012',
+		'patch_file': 'leave_application_cleanup',
+	},
+	{
+		'patch_module': 'patches.november_2012',
+		'patch_file': 'production_order_patch',
+	},
 ]
\ No newline at end of file
diff --git a/production/doctype/bom/bom.py b/production/doctype/bom/bom.py
index 913e7b6..a413f6a 100644
--- a/production/doctype/bom/bom.py
+++ b/production/doctype/bom/bom.py
@@ -16,17 +16,14 @@
 
 from __future__ import unicode_literals
 import webnotes
-from webnotes.utils import cint, cstr, flt, get_defaults, getdate, now, nowdate
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
+from webnotes.utils import cint, cstr, flt, now, nowdate
+from webnotes.model.doc import Document, addchild
 from webnotes.model.wrapper import getlist
 from webnotes.model.code import get_obj
-from webnotes import msgprint, errprint
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
 
-# -----------------------------------------------------------------------------------------
 
 class DocType:
 	def __init__(self, doc, doclist=[]):
diff --git a/production/doctype/bom_control/bom_control.py b/production/doctype/bom_control/bom_control.py
index c093ec5..27812a8 100644
--- a/production/doctype/bom_control/bom_control.py
+++ b/production/doctype/bom_control/bom_control.py
@@ -14,24 +14,16 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
 from webnotes.utils import cint, flt
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
+from webnotes.model.code import get_obj
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 
-# -----------------------------------------------------------------------------------------
 
 	
 class DocType:
diff --git a/production/doctype/production_control/production_control.py b/production/doctype/production_control/production_control.py
index ef01cb1..b389e69 100644
--- a/production/doctype/production_control/production_control.py
+++ b/production/doctype/production_control/production_control.py
@@ -14,24 +14,18 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr, flt, get_defaults, now, nowdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.doc import Document
+from webnotes.model.wrapper import copy_doclist
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 	
 class DocType:
@@ -73,7 +67,7 @@
 
 
 	#	Raise Production Order
-	def create_production_order(self,company, pp_items):
+	def create_production_order(self, items):
 		"""Create production order. Called from Production Planning Tool"""
 					 
 		default_values = { 
@@ -82,15 +76,20 @@
 			'wip_warehouse'		: '',
 			'fg_warehouse'		: '',
 			'status'			: 'Draft',
-			'company'			: company,
-			'fiscal_year'		: get_defaults()['fiscal_year'] 
+			'fiscal_year'		: get_defaults()['fiscal_year']
 		}
 		pro_list = []
 
-		for d in pp_items:
+		for item_so in items:
+			if item_so[1]:
+				self.validate_production_order_against_so(
+					item_so[0], item_so[1], items[item_so].get("qty"))
+				
 			pro_doc = Document('Production Order')
-			for key in d.keys():
-				pro_doc.fields[key] = d[key]
+			pro_doc.production_item = item_so[0]
+			pro_doc.sales_order = item_so[1]
+			for key in items[item_so]:
+				pro_doc.fields[key] = items[item_so][key]
 
 			for key in default_values:
 				pro_doc.fields[key] = default_values[key]
@@ -100,7 +99,30 @@
 			
 		return pro_list
 
-
+	def validate_production_order_against_so(self, item, sales_order, qty, pro_order=None):
+		# already ordered qty
+		ordered_qty_against_so = webnotes.conn.sql("""select sum(qty) from `tabProduction Order`
+			where production_item = %s and sales_order = %s and name != %s""", 
+			(item, sales_order, cstr(pro_order)))[0][0]
+		# qty including current
+		total_ordered_qty_against_so = flt(ordered_qty_against_so) + flt(qty)
+		
+		# get qty from Sales Order Item table
+		so_item_qty = webnotes.conn.sql("""select sum(qty) from `tabSales Order Item` 
+			where parent = %s and item_code = %s""", (sales_order, item))[0][0]
+		# get qty from Packing Item table
+		dnpi_qty = webnotes.conn.sql("""select sum(qty) from `tabDelivery Note Packing Item` 
+			where parent = %s and parenttype = 'Sales Order' and item_code = %s""", 
+			(sales_order, item))[0][0]
+		# total qty in SO
+		so_qty = flt(so_item_qty) + flt(dnpi_qty)
+		
+		if total_ordered_qty_against_so > so_qty:
+			msgprint("""Total production order qty for item: %s against sales order: %s \
+			 	will be %s, which is greater than sales order qty (%s). 
+				Please reduce qty or remove the item.""" %
+				(item, sales_order, total_ordered_qty_against_so, so_qty), raise_exception=1)
+		
 	def update_bom(self, bom_no):
 		main_bom_list = self.traverse_bom_tree(bom_no, 1)
 		main_bom_list.reverse()
@@ -113,4 +135,4 @@
 				bom_obj.update_flat_bom_engine()
 				bom_obj.doc.docstatus = 1
 				bom_obj.doc.save()
-				self.check_bom_list.append(bom)
+				self.check_bom_list.append(bom)
\ No newline at end of file
diff --git a/production/doctype/production_order/production_order.js b/production/doctype/production_order/production_order.js
index 411f779..7949757 100644
--- a/production/doctype/production_order/production_order.js
+++ b/production/doctype/production_order/production_order.js
@@ -18,15 +18,7 @@
 cur_frm.cscript.onload = function(doc, dt, dn) {
   if (!doc.posting_date) doc.transaction_date = dateutil.obj_to_str(new Date());
   if (!doc.status) doc.status = 'Draft';
-
   cfn_set_fields(doc, dt, dn);
-
-  if (doc.origin != "MRP"){
-    doc.origin = "Manual";
-    set_field_permlevel('production_item', 0);
-    set_field_permlevel('bom_no', 0);
-    set_field_permlevel('consider_sa_items',0);
-  }
 }
 
 // ================================== Refresh ==========================================
@@ -48,15 +40,10 @@
   }
 }
 
-
-// ==================================================================================================
-
 cur_frm.cscript.production_item = function(doc, dt, dn) {
   get_server_fields('get_item_detail',doc.production_item,'',doc,dt,dn,1);
 }
 
-// Stop PRODUCTION ORDER
-//
 cur_frm.cscript['Stop Production Order'] = function() {
   var doc = cur_frm.doc;
   var check = confirm("Do you really want to stop production order: " + doc.name);
@@ -65,8 +52,6 @@
 	}
 }
 
-// Unstop PRODUCTION ORDER
-//
 cur_frm.cscript['Unstop Production Order'] = function() {
   var doc = cur_frm.doc;
   var check = confirm("Do really want to unstop production order: " + doc.name);
@@ -97,8 +82,6 @@
   loaddoc('Stock Entry', se.name);
 }
 
-
-// ==================================================================================================
 cur_frm.fields_dict['production_item'].get_query = function(doc) {
    return 'SELECT DISTINCT `tabItem`.`name`, `tabItem`.`description` FROM `tabItem` WHERE (IFNULL(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life` = "0000-00-00" OR `tabItem`.`end_of_life` > NOW()) AND `tabItem`.docstatus != 2 AND `tabItem`.is_pro_applicable = "Yes" AND `tabItem`.%(key)s LIKE "%s" ORDER BY `tabItem`.`name` LIMIT 50';
 }
diff --git a/production/doctype/production_order/production_order.py b/production/doctype/production_order/production_order.py
index 05eaa75..5314971 100644
--- a/production/doctype/production_order/production_order.py
+++ b/production/doctype/production_order/production_order.py
@@ -14,24 +14,18 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr, flt, now, nowdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.doc import make_autoname
+from webnotes.model.wrapper import copy_doclist
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 
-# -----------------------------------------------------------------------------------------
 	
 
 class DocType:
@@ -72,6 +66,14 @@
 				msgprint("""Incorrect BOM: %s entered. 
 					May be BOM not exists or inactive or not submitted 
 					or for some other item.""" % cstr(self.doc.bom_no), raise_exception=1)
+					
+		if self.doc.sales_order:
+			if not webnotes.conn.sql("""select name from `tabSales Order` 
+					where name=%s and docstatus = 1""", self.doc.sales_order):
+				msgprint("Sales Order: %s is not valid" % self.doc.sales_order, raise_exception=1)
+				
+			get_obj("Production Control").validate_production_order_against_so(
+				self.doc.production_item, self.doc.sales_order, self.doc.qty, self.doc.name)
 
 
 	def stop_unstop(self, status):
diff --git a/production/doctype/production_order/production_order.txt b/production/doctype/production_order/production_order.txt
index c244399..369efd4 100644
--- a/production/doctype/production_order/production_order.txt
+++ b/production/doctype/production_order/production_order.txt
@@ -1,358 +1,324 @@
-# DocType, Production Order
 [
-
-	# These values are common in all dictionaries
-	{
-		'creation': '2012-05-15 12:14:48',
-		'docstatus': 0,
-		'modified': '2012-05-28 19:03:56',
-		'modified_by': u'Administrator',
-		'owner': u'Administrator'
-	},
-
-	# These values are common for all DocType
-	{
-		'_last_update': u'1325837006',
-		'colour': u'White:FFF',
-		'default_print_format': u'Standard',
-		'doctype': 'DocType',
-		'in_create': 0,
-		'is_submittable': 1,
-		'module': u'Production',
-		'name': '__common__',
-		'section_style': u'Tabbed',
-		'server_code_error': u' ',
-		'show_in_menu': 0,
-		'version': 1
-	},
-
-	# These values are common for all DocField
-	{
-		'doctype': u'DocField',
-		'name': '__common__',
-		'parent': u'Production Order',
-		'parentfield': u'fields',
-		'parenttype': u'DocType'
-	},
-
-	# These values are common for all DocPerm
-	{
-		'doctype': u'DocPerm',
-		'name': '__common__',
-		'parent': u'Production Order',
-		'parentfield': u'permissions',
-		'parenttype': u'DocType',
-		'read': 1
-	},
-
-	# DocType, Production Order
-	{
-		'doctype': 'DocType',
-		'name': u'Production Order'
-	},
-
-	# DocPerm
-	{
-		'amend': 1,
-		'cancel': 1,
-		'create': 1,
-		'doctype': u'DocPerm',
-		'permlevel': 0,
-		'role': u'System Manager',
-		'submit': 1,
-		'write': 1
-	},
-
-	# DocPerm
-	{
-		'doctype': u'DocPerm',
-		'permlevel': 1,
-		'role': u'All'
-	},
-
-	# DocPerm
-	{
-		'amend': 1,
-		'cancel': 1,
-		'create': 1,
-		'doctype': u'DocPerm',
-		'permlevel': 0,
-		'role': u'Production Manager',
-		'submit': 1,
-		'write': 1
-	},
-
-	# DocPerm
-	{
-		'amend': 1,
-		'cancel': 1,
-		'create': 1,
-		'doctype': u'DocPerm',
-		'permlevel': 0,
-		'role': u'Production User',
-		'submit': 1,
-		'write': 1
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'column_break0',
-		'fieldtype': u'Column Break',
-		'permlevel': 0,
-		'width': u'50%'
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'description': u'Item for which this Production Order is raised.',
-		'doctype': u'DocField',
-		'fieldname': u'production_item',
-		'fieldtype': u'Link',
-		'in_filter': 1,
-		'label': u'Production Item',
-		'oldfieldname': u'production_item',
-		'oldfieldtype': u'Link',
-		'options': u'Item',
-		'permlevel': 1,
-		'reqd': 1,
-		'trigger': u'Client'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'description',
-		'fieldtype': u'Text',
-		'label': u'Description',
-		'oldfieldname': u'description',
-		'oldfieldtype': u'Text',
-		'permlevel': 0,
-		'width': u'300px'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'stock_uom',
-		'fieldtype': u'Data',
-		'label': u'Stock UOM',
-		'oldfieldname': u'stock_uom',
-		'oldfieldtype': u'Data',
-		'permlevel': 1
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'description': u'Bill of Material which was considered for manufacturing the production item.',
-		'doctype': u'DocField',
-		'fieldname': u'bom_no',
-		'fieldtype': u'Link',
-		'label': u'BOM No',
-		'oldfieldname': u'bom_no',
-		'oldfieldtype': u'Link',
-		'options': u'BOM',
-		'permlevel': 1,
-		'reqd': 1,
-		'trigger': u'Client'
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'description': u'Quantity of item for which Production Order is raised.',
-		'doctype': u'DocField',
-		'fieldname': u'qty',
-		'fieldtype': u'Currency',
-		'label': u'Qty',
-		'oldfieldname': u'qty',
-		'oldfieldtype': u'Currency',
-		'permlevel': 0,
-		'reqd': 1
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'description': u'The warehouse for finished goods where stock of produced items will be updated.',
-		'doctype': u'DocField',
-		'fieldname': u'fg_warehouse',
-		'fieldtype': u'Link',
-		'in_filter': 1,
-		'label': u'FG Warehouse',
-		'oldfieldname': u'fg_warehouse',
-		'oldfieldtype': u'Link',
-		'options': u'Warehouse',
-		'permlevel': 0,
-		'reqd': 1
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'description': u'The work in progress warehouse where raw materials will be operated upon to create finished goods.',
-		'doctype': u'DocField',
-		'fieldname': u'wip_warehouse',
-		'fieldtype': u'Link',
-		'in_filter': 1,
-		'label': u'WIP Warehouse',
-		'oldfieldname': u'wip_warehouse',
-		'oldfieldtype': u'Link',
-		'options': u'Warehouse',
-		'permlevel': 0,
-		'reqd': 1
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'amended_from',
-		'fieldtype': u'Data',
-		'label': u'Amended From',
-		'no_copy': 1,
-		'oldfieldname': u'amended_from',
-		'oldfieldtype': u'Data',
-		'permlevel': 1
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'amendment_date',
-		'fieldtype': u'Date',
-		'label': u'Amendment Date',
-		'no_copy': 1,
-		'oldfieldname': u'amendment_date',
-		'oldfieldtype': u'Date',
-		'permlevel': 1
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'column_break1',
-		'fieldtype': u'Column Break',
-		'oldfieldtype': u'Column Break',
-		'permlevel': 0,
-		'width': u'50%'
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'description': u'The date on which current entry will get or has actually executed.',
-		'doctype': u'DocField',
-		'fieldname': u'posting_date',
-		'fieldtype': u'Date',
-		'label': u'Posting Date',
-		'oldfieldname': u'posting_date',
-		'oldfieldtype': u'Date',
-		'permlevel': 0,
-		'reqd': 1
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'description': u'Select "Yes" if stock is maintained and tracked for sub-assembly items. Select "No" if you want child items of sub-assembly for material transfer.',
-		'doctype': u'DocField',
-		'fieldname': u'consider_sa_items',
-		'fieldtype': u'Select',
-		'in_filter': 1,
-		'label': u'Consider SA Items as raw material',
-		'oldfieldname': u'consider_sa_items',
-		'oldfieldtype': u'Select',
-		'options': u'\nYes\nNo',
-		'permlevel': 1,
-		'reqd': 1
-	},
-
-	# DocField
-	{
-		'description': u'Select name of the project if Production Order need to be created against any project',
-		'doctype': u'DocField',
-		'fieldname': u'project_name',
-		'fieldtype': u'Link',
-		'in_filter': 1,
-		'label': u'Project Name',
-		'oldfieldname': u'project_name',
-		'oldfieldtype': u'Link',
-		'options': u'Project',
-		'permlevel': 0,
-		'trigger': u'Client'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'origin',
-		'fieldtype': u'Select',
-		'in_filter': 1,
-		'label': u'Origin',
-		'no_copy': 1,
-		'oldfieldname': u'origin',
-		'oldfieldtype': u'Select',
-		'options': u'Manual\nMRP',
-		'permlevel': 1,
-		'reqd': 1
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'status',
-		'fieldtype': u'Select',
-		'in_filter': 1,
-		'label': u'Status',
-		'no_copy': 1,
-		'oldfieldname': u'status',
-		'oldfieldtype': u'Select',
-		'options': u'\nDraft\nSubmitted\nStopped\nIn Process\nCompleted\nCancelled',
-		'permlevel': 1,
-		'reqd': 1,
-		'search_index': 1
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'description': u'Updated after finished goods are transferred to FG Warehouse through Stock Entry',
-		'doctype': u'DocField',
-		'fieldname': u'produced_qty',
-		'fieldtype': u'Currency',
-		'label': u'Produced Qty',
-		'no_copy': 1,
-		'oldfieldname': u'produced_qty',
-		'oldfieldtype': u'Currency',
-		'permlevel': 1
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'company',
-		'fieldtype': u'Link',
-		'label': u'Company',
-		'oldfieldname': u'company',
-		'oldfieldtype': u'Link',
-		'options': u'Company',
-		'permlevel': 0,
-		'reqd': 1
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'fiscal_year',
-		'fieldtype': u'Select',
-		'in_filter': 1,
-		'label': u'Fiscal Year',
-		'oldfieldname': u'fiscal_year',
-		'oldfieldtype': u'Select',
-		'options': u'link:Fiscal Year',
-		'permlevel': 0,
-		'reqd': 1
-	}
+ {
+  "owner": "Administrator", 
+  "docstatus": 0, 
+  "creation": "2012-07-03 13:30:03", 
+  "modified_by": "Administrator", 
+  "modified": "2012-11-30 14:28:03"
+ }, 
+ {
+  "is_submittable": 1, 
+  "in_create": 0, 
+  "default_print_format": "Standard", 
+  "doctype": "DocType", 
+  "module": "Production", 
+  "name": "__common__"
+ }, 
+ {
+  "name": "__common__", 
+  "parent": "Production Order", 
+  "doctype": "DocField", 
+  "parenttype": "DocType", 
+  "parentfield": "fields"
+ }, 
+ {
+  "name": "__common__", 
+  "parent": "Production Order", 
+  "read": 1, 
+  "doctype": "DocPerm", 
+  "parenttype": "DocType", 
+  "parentfield": "permissions"
+ }, 
+ {
+  "name": "Production Order", 
+  "doctype": "DocType"
+ }, 
+ {
+  "doctype": "DocField", 
+  "width": "50%", 
+  "fieldname": "column_break0", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "description": "Item for which this Production Order is raised.", 
+  "oldfieldtype": "Link", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Production Item", 
+  "oldfieldname": "production_item", 
+  "permlevel": 0, 
+  "trigger": "Client", 
+  "fieldname": "production_item", 
+  "fieldtype": "Link", 
+  "reqd": 1, 
+  "in_filter": 1, 
+  "options": "Item"
+ }, 
+ {
+  "description": "Bill of Material which was considered for manufacturing the production item.", 
+  "oldfieldtype": "Link", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "BOM No", 
+  "oldfieldname": "bom_no", 
+  "permlevel": 0, 
+  "trigger": "Client", 
+  "fieldname": "bom_no", 
+  "fieldtype": "Link", 
+  "reqd": 1, 
+  "options": "BOM"
+ }, 
+ {
+  "description": "Quantity of item for which Production Order is raised.", 
+  "oldfieldtype": "Currency", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Qty", 
+  "oldfieldname": "qty", 
+  "fieldname": "qty", 
+  "fieldtype": "Currency", 
+  "reqd": 1, 
+  "permlevel": 0
+ }, 
+ {
+  "description": "The date on which current entry will get or has actually executed.", 
+  "oldfieldtype": "Date", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Posting Date", 
+  "oldfieldname": "posting_date", 
+  "fieldname": "posting_date", 
+  "fieldtype": "Date", 
+  "reqd": 1, 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Column Break", 
+  "doctype": "DocField", 
+  "width": "50%", 
+  "fieldname": "column_break1", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "description": "The warehouse for finished goods where stock of produced items will be updated.", 
+  "oldfieldtype": "Link", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "FG Warehouse", 
+  "oldfieldname": "fg_warehouse", 
+  "permlevel": 0, 
+  "fieldname": "fg_warehouse", 
+  "fieldtype": "Link", 
+  "reqd": 1, 
+  "in_filter": 1, 
+  "options": "Warehouse"
+ }, 
+ {
+  "description": "The work in progress warehouse where raw materials will be operated upon to create finished goods.", 
+  "oldfieldtype": "Link", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "WIP Warehouse", 
+  "oldfieldname": "wip_warehouse", 
+  "permlevel": 0, 
+  "fieldname": "wip_warehouse", 
+  "fieldtype": "Link", 
+  "reqd": 1, 
+  "in_filter": 1, 
+  "options": "Warehouse"
+ }, 
+ {
+  "description": "If checked, BOM for sub-assembly items will be considered for getting raw materials. Otherwise, all sub-assembly items will be treated as a raw material.", 
+  "default": "1", 
+  "oldfieldtype": "Select", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Use Multi-Level BOM", 
+  "oldfieldname": "consider_sa_items", 
+  "fieldname": "use_multi_level_bom", 
+  "fieldtype": "Check", 
+  "reqd": 1, 
+  "in_filter": 1, 
+  "permlevel": 0
+ }, 
+ {
+  "description": "Updated after finished goods are transferred to FG Warehouse through Stock Entry", 
+  "no_copy": 1, 
+  "oldfieldtype": "Currency", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Produced Qty", 
+  "oldfieldname": "produced_qty", 
+  "fieldname": "produced_qty", 
+  "fieldtype": "Currency", 
+  "permlevel": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "More Info", 
+  "fieldname": "more_info", 
+  "fieldtype": "Section Break", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "width": "50%", 
+  "fieldname": "column_break2", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "no_copy": 1, 
+  "oldfieldtype": "Select", 
+  "doctype": "DocField", 
+  "label": "Origin", 
+  "oldfieldname": "origin", 
+  "options": "Manual\nMRP", 
+  "fieldname": "origin", 
+  "fieldtype": "Select", 
+  "reqd": 1, 
+  "permlevel": 0, 
+  "in_filter": 1
+ }, 
+ {
+  "no_copy": 1, 
+  "oldfieldtype": "Select", 
+  "doctype": "DocField", 
+  "label": "Status", 
+  "oldfieldname": "status", 
+  "permlevel": 1, 
+  "fieldname": "status", 
+  "fieldtype": "Select", 
+  "search_index": 1, 
+  "reqd": 1, 
+  "options": "\nDraft\nSubmitted\nStopped\nIn Process\nCompleted\nCancelled", 
+  "in_filter": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Sales Order", 
+  "options": "Sales Order", 
+  "fieldname": "sales_order", 
+  "fieldtype": "Link", 
+  "permlevel": 0
+ }, 
+ {
+  "description": "Select name of the project if Production Order need to be created against any project", 
+  "oldfieldtype": "Link", 
+  "label": "Project Name", 
+  "oldfieldname": "project_name", 
+  "trigger": "Client", 
+  "fieldname": "project_name", 
+  "fieldtype": "Link", 
+  "doctype": "DocField", 
+  "options": "Project", 
+  "permlevel": 0, 
+  "in_filter": 1
+ }, 
+ {
+  "oldfieldtype": "Link", 
+  "doctype": "DocField", 
+  "label": "Company", 
+  "oldfieldname": "company", 
+  "options": "Company", 
+  "fieldname": "company", 
+  "fieldtype": "Link", 
+  "reqd": 1, 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Select", 
+  "doctype": "DocField", 
+  "label": "Fiscal Year", 
+  "oldfieldname": "fiscal_year", 
+  "options": "link:Fiscal Year", 
+  "fieldname": "fiscal_year", 
+  "fieldtype": "Select", 
+  "reqd": 1, 
+  "permlevel": 0, 
+  "in_filter": 1
+ }, 
+ {
+  "no_copy": 1, 
+  "oldfieldtype": "Data", 
+  "doctype": "DocField", 
+  "label": "Amended From", 
+  "oldfieldname": "amended_from", 
+  "fieldname": "amended_from", 
+  "fieldtype": "Data", 
+  "permlevel": 1
+ }, 
+ {
+  "no_copy": 1, 
+  "oldfieldtype": "Date", 
+  "doctype": "DocField", 
+  "label": "Amendment Date", 
+  "oldfieldname": "amendment_date", 
+  "fieldname": "amendment_date", 
+  "fieldtype": "Date", 
+  "permlevel": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "width": "50%", 
+  "fieldname": "column_break3", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Data", 
+  "doctype": "DocField", 
+  "label": "Stock UOM", 
+  "oldfieldname": "stock_uom", 
+  "fieldname": "stock_uom", 
+  "fieldtype": "Data", 
+  "permlevel": 1
+ }, 
+ {
+  "oldfieldtype": "Text", 
+  "doctype": "DocField", 
+  "label": "Production Item Description", 
+  "oldfieldname": "description", 
+  "width": "300px", 
+  "fieldname": "description", 
+  "fieldtype": "Text", 
+  "permlevel": 0
+ }, 
+ {
+  "amend": 1, 
+  "create": 1, 
+  "doctype": "DocPerm", 
+  "submit": 1, 
+  "write": 1, 
+  "role": "System Manager", 
+  "cancel": 1, 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocPerm", 
+  "role": "All", 
+  "permlevel": 1
+ }, 
+ {
+  "amend": 1, 
+  "create": 1, 
+  "doctype": "DocPerm", 
+  "submit": 1, 
+  "write": 1, 
+  "role": "Production Manager", 
+  "cancel": 1, 
+  "permlevel": 0
+ }, 
+ {
+  "amend": 1, 
+  "create": 1, 
+  "doctype": "DocPerm", 
+  "submit": 1, 
+  "write": 1, 
+  "role": "Production User", 
+  "cancel": 1, 
+  "permlevel": 0
+ }
 ]
\ No newline at end of file
diff --git a/production/doctype/production_plan_item/production_plan_item.txt b/production/doctype/production_plan_item/production_plan_item.txt
index 8b546a4..cd4507f 100644
--- a/production/doctype/production_plan_item/production_plan_item.txt
+++ b/production/doctype/production_plan_item/production_plan_item.txt
@@ -1,159 +1,109 @@
-# DocType, Production Plan Item
 [
-
-	# These values are common in all dictionaries
-	{
-		'creation': '2012-03-27 14:36:03',
-		'docstatus': 0,
-		'modified': '2012-03-27 14:36:03',
-		'modified_by': u'Administrator',
-		'owner': u'Administrator'
-	},
-
-	# These values are common for all DocType
-	{
-		'autoname': u'PPID/.#####',
-		'colour': u'White:FFF',
-		'default_print_format': u'Standard',
-		'doctype': 'DocType',
-		'istable': 1,
-		'module': u'Production',
-		'name': '__common__',
-		'section_style': u'Simple',
-		'server_code_error': u' ',
-		'show_in_menu': 0,
-		'version': 27
-	},
-
-	# These values are common for all DocField
-	{
-		'doctype': u'DocField',
-		'name': '__common__',
-		'parent': u'Production Plan Item',
-		'parentfield': u'fields',
-		'parenttype': u'DocType'
-	},
-
-	# DocType, Production Plan Item
-	{
-		'doctype': 'DocType',
-		'name': u'Production Plan Item'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'sales_order',
-		'fieldtype': u'Data',
-		'label': u'Sales Order',
-		'oldfieldname': u'source_docname',
-		'oldfieldtype': u'Data',
-		'permlevel': 1
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'doctype': u'DocField',
-		'fieldname': u'item_code',
-		'fieldtype': u'Link',
-		'label': u'Item Code',
-		'oldfieldname': u'item_code',
-		'oldfieldtype': u'Link',
-		'options': u'Item',
-		'permlevel': 0,
-		'reqd': 1,
-		'trigger': u'Client',
-		'width': u'150px'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'bom_no',
-		'fieldtype': u'Link',
-		'label': u'BOM No',
-		'oldfieldname': u'bom_no',
-		'oldfieldtype': u'Link',
-		'options': u'BOM',
-		'permlevel': 0,
-		'reqd': 1,
-		'width': u'100px'
-	},
-
-	# DocField
-	{
-		'default': u'0.00',
-		'doctype': u'DocField',
-		'fieldname': u'so_pending_qty',
-		'fieldtype': u'Currency',
-		'label': u'SO Pending Qty',
-		'oldfieldname': u'prevdoc_reqd_qty',
-		'oldfieldtype': u'Currency',
-		'permlevel': 1,
-		'reqd': 0,
-		'width': u'100px'
-	},
-
-	# DocField
-	{
-		'default': u'0.00',
-		'doctype': u'DocField',
-		'fieldname': u'planned_qty',
-		'fieldtype': u'Currency',
-		'label': u'Planned Qty',
-		'oldfieldname': u'planned_qty',
-		'oldfieldtype': u'Currency',
-		'permlevel': 0,
-		'reqd': 1,
-		'width': u'100px'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'stock_uom',
-		'fieldtype': u'Data',
-		'label': u'UOM',
-		'oldfieldname': u'stock_uom',
-		'oldfieldtype': u'Data',
-		'permlevel': 1,
-		'reqd': 1,
-		'width': u'80px'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'description',
-		'fieldtype': u'Text',
-		'label': u'Description',
-		'oldfieldname': u'description',
-		'oldfieldtype': u'Text',
-		'permlevel': 1,
-		'width': u'200px'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'parent_packing_item',
-		'fieldtype': u'Link',
-		'label': u'Parent Packing Item',
-		'oldfieldname': u'parent_item',
-		'oldfieldtype': u'Link',
-		'options': u'Item',
-		'permlevel': 1
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'is_pro_created',
-		'fieldtype': u'Check',
-		'label': u'Is PRO Created',
-		'oldfieldname': u'pro_created',
-		'oldfieldtype': u'Check',
-		'permlevel': 1
-	}
+ {
+  "owner": "Administrator", 
+  "docstatus": 0, 
+  "creation": "2012-07-03 13:30:04", 
+  "modified_by": "Administrator", 
+  "modified": "2012-11-29 19:02:38"
+ }, 
+ {
+  "istable": 1, 
+  "autoname": "PPID/.#####", 
+  "name": "__common__", 
+  "default_print_format": "Standard", 
+  "doctype": "DocType", 
+  "module": "Production"
+ }, 
+ {
+  "name": "__common__", 
+  "parent": "Production Plan Item", 
+  "doctype": "DocField", 
+  "parenttype": "DocType", 
+  "parentfield": "fields"
+ }, 
+ {
+  "name": "Production Plan Item", 
+  "doctype": "DocType"
+ }, 
+ {
+  "permlevel": 0, 
+  "oldfieldtype": "Link", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Item Code", 
+  "oldfieldname": "item_code", 
+  "width": "150px", 
+  "trigger": "Client", 
+  "fieldname": "item_code", 
+  "fieldtype": "Link", 
+  "reqd": 1, 
+  "options": "Item"
+ }, 
+ {
+  "oldfieldtype": "Link", 
+  "doctype": "DocField", 
+  "label": "BOM No", 
+  "oldfieldname": "bom_no", 
+  "width": "100px", 
+  "options": "BOM", 
+  "fieldname": "bom_no", 
+  "fieldtype": "Link", 
+  "reqd": 1, 
+  "permlevel": 0
+ }, 
+ {
+  "default": "0.00", 
+  "oldfieldtype": "Currency", 
+  "doctype": "DocField", 
+  "label": "Planned Qty", 
+  "oldfieldname": "planned_qty", 
+  "width": "100px", 
+  "fieldname": "planned_qty", 
+  "fieldtype": "Currency", 
+  "reqd": 1, 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Data", 
+  "doctype": "DocField", 
+  "label": "Sales Order", 
+  "oldfieldname": "source_docname", 
+  "options": "Sales Order", 
+  "fieldname": "sales_order", 
+  "fieldtype": "Link", 
+  "permlevel": 1
+ }, 
+ {
+  "default": "0.00", 
+  "oldfieldtype": "Currency", 
+  "doctype": "DocField", 
+  "label": "SO Pending Qty", 
+  "oldfieldname": "prevdoc_reqd_qty", 
+  "width": "100px", 
+  "fieldname": "so_pending_qty", 
+  "fieldtype": "Currency", 
+  "reqd": 0, 
+  "permlevel": 1
+ }, 
+ {
+  "oldfieldtype": "Data", 
+  "doctype": "DocField", 
+  "label": "UOM", 
+  "oldfieldname": "stock_uom", 
+  "width": "80px", 
+  "fieldname": "stock_uom", 
+  "fieldtype": "Data", 
+  "reqd": 1, 
+  "permlevel": 1
+ }, 
+ {
+  "oldfieldtype": "Text", 
+  "doctype": "DocField", 
+  "label": "Description", 
+  "oldfieldname": "description", 
+  "width": "200px", 
+  "fieldname": "description", 
+  "fieldtype": "Text", 
+  "permlevel": 1
+ }
 ]
\ No newline at end of file
diff --git a/production/doctype/production_plan_sales_order/production_plan_sales_order.txt b/production/doctype/production_plan_sales_order/production_plan_sales_order.txt
index 810c140..e42d8d5 100644
--- a/production/doctype/production_plan_sales_order/production_plan_sales_order.txt
+++ b/production/doctype/production_plan_sales_order/production_plan_sales_order.txt
@@ -1,124 +1,84 @@
-# DocType, Production Plan Sales Order
 [
-
-	# These values are common in all dictionaries
-	{
-		'creation': '2012-03-27 14:36:04',
-		'docstatus': 0,
-		'modified': '2012-03-27 14:36:04',
-		'modified_by': u'Administrator',
-		'owner': u'Administrator'
-	},
-
-	# These values are common for all DocType
-	{
-		'autoname': u'PP/.SO/.#####',
-		'colour': u'White:FFF',
-		'default_print_format': u'Standard',
-		'doctype': 'DocType',
-		'istable': 1,
-		'module': u'Production',
-		'name': '__common__',
-		'section_style': u'Simple',
-		'server_code_error': u' ',
-		'show_in_menu': 0,
-		'version': 5
-	},
-
-	# These values are common for all DocField
-	{
-		'doctype': u'DocField',
-		'name': '__common__',
-		'parent': u'Production Plan Sales Order',
-		'parentfield': u'fields',
-		'parenttype': u'DocType'
-	},
-
-	# These values are common for all DocPerm
-	{
-		'doctype': u'DocPerm',
-		'name': '__common__',
-		'parent': u'Production Plan Sales Order',
-		'parentfield': u'permissions',
-		'parenttype': u'DocType',
-		'read': 1,
-		'role': u'System Manager'
-	},
-
-	# DocType, Production Plan Sales Order
-	{
-		'doctype': 'DocType',
-		'name': u'Production Plan Sales Order'
-	},
-
-	# DocPerm
-	{
-		'doctype': u'DocPerm',
-		'permlevel': 0,
-		'write': 1
-	},
-
-	# DocPerm
-	{
-		'doctype': u'DocPerm',
-		'permlevel': 1
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'sales_order',
-		'fieldtype': u'Link',
-		'label': u'Sales Order',
-		'oldfieldname': u'prevdoc_docname',
-		'oldfieldtype': u'Data',
-		'options': u'Sales Order',
-		'permlevel': 0,
-		'width': u'150px'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'sales_order_date',
-		'fieldtype': u'Date',
-		'label': u'Sales Order Date',
-		'oldfieldname': u'document_date',
-		'oldfieldtype': u'Date',
-		'permlevel': 1,
-		'width': u'100px'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'customer',
-		'fieldtype': u'Link',
-		'label': u'Customer',
-		'options': u'Customer',
-		'permlevel': 1,
-		'width': u'150px'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'grand_total',
-		'fieldtype': u'Currency',
-		'label': u'Grand Total',
-		'permlevel': 1,
-		'width': u'100px'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'include_in_plan',
-		'fieldtype': u'Check',
-		'label': u'Include In Plan',
-		'oldfieldname': u'include_in_plan',
-		'oldfieldtype': u'Check',
-		'permlevel': 0,
-		'width': u'100px'
-	}
+ {
+  "owner": "Administrator", 
+  "docstatus": 0, 
+  "creation": "2012-07-03 13:30:04", 
+  "modified_by": "Administrator", 
+  "modified": "2012-11-29 17:49:15"
+ }, 
+ {
+  "istable": 1, 
+  "autoname": "PP/.SO/.#####", 
+  "name": "__common__", 
+  "default_print_format": "Standard", 
+  "doctype": "DocType", 
+  "module": "Production"
+ }, 
+ {
+  "name": "__common__", 
+  "parent": "Production Plan Sales Order", 
+  "doctype": "DocField", 
+  "parenttype": "DocType", 
+  "parentfield": "fields"
+ }, 
+ {
+  "name": "__common__", 
+  "parent": "Production Plan Sales Order", 
+  "read": 1, 
+  "doctype": "DocPerm", 
+  "parenttype": "DocType", 
+  "role": "System Manager", 
+  "parentfield": "permissions"
+ }, 
+ {
+  "name": "Production Plan Sales Order", 
+  "doctype": "DocType"
+ }, 
+ {
+  "oldfieldtype": "Data", 
+  "doctype": "DocField", 
+  "label": "Sales Order", 
+  "oldfieldname": "prevdoc_docname", 
+  "width": "150px", 
+  "options": "Sales Order", 
+  "fieldname": "sales_order", 
+  "fieldtype": "Link", 
+  "permlevel": 0
+ }, 
+ {
+  "oldfieldtype": "Date", 
+  "doctype": "DocField", 
+  "label": "SO Date", 
+  "oldfieldname": "document_date", 
+  "width": "120px", 
+  "fieldname": "sales_order_date", 
+  "fieldtype": "Date", 
+  "permlevel": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Customer", 
+  "width": "150px", 
+  "options": "Customer", 
+  "fieldname": "customer", 
+  "fieldtype": "Link", 
+  "permlevel": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Grand Total", 
+  "width": "120px", 
+  "fieldname": "grand_total", 
+  "fieldtype": "Currency", 
+  "permlevel": 1
+ }, 
+ {
+  "write": 1, 
+  "doctype": "DocPerm", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocPerm", 
+  "permlevel": 1
+ }
 ]
\ No newline at end of file
diff --git a/production/doctype/production_planning_tool/production_planning_tool.js b/production/doctype/production_planning_tool/production_planning_tool.js
index 9caf829..ac4d76d 100644
--- a/production/doctype/production_planning_tool/production_planning_tool.js
+++ b/production/doctype/production_planning_tool/production_planning_tool.js
@@ -14,11 +14,9 @@
 // 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.item_code = function(doc,cdt,cdn) {
-	var d = locals[cdt][cdn];
-	if (d.item_code) {
-		get_server_fields('get_item_details', d.item_code, 'pp_details', doc, cdt, cdn, 1);
-	}
+cur_frm.cscript.onload = function(doc, cdt, cdn) {
+	doc.company = sys_defaults.company;
+	refresh_field("company");
 }
 
 cur_frm.cscript.sales_order = function(doc,cdt,cdn) {
@@ -28,25 +26,35 @@
 	}
 }
 
-
-cur_frm.cscript.download_raw_material = function(doc, cdt, cdn) {
-	var callback = function(r, rt){
-		if (r.message) 
-			$c_obj_csv(make_doclist(cdt, cdn), 'download_raw_materials', '', '');
+cur_frm.cscript.item_code = function(doc,cdt,cdn) {
+	var d = locals[cdt][cdn];
+	if (d.item_code) {
+		get_server_fields('get_item_details', d.item_code, 'pp_details', doc, cdt, cdn, 1);
 	}
-	$c_obj(make_doclist(cdt, cdn), 'validate_data', '', callback)
 }
 
-//-------------------------------------------------------------------------------
-//
+cur_frm.cscript.download_materials_required = function(doc, cdt, cdn) {
+	$c_obj(make_doclist(cdt, cdn), 'validate_data', '', function(r, rt) {
+		if (!r['exc'])
+			$c_obj_csv(make_doclist(cdt, cdn), 'download_raw_materials', '', '');
+	});
+}
 
 cur_frm.fields_dict['pp_details'].grid.get_field('item_code').get_query = function(doc) {
-  return 'SELECT DISTINCT `tabItem`.`name`,`tabItem`.`item_name` FROM `tabItem` WHERE (IFNULL(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life`="0000-00-00" OR `tabItem`.`end_of_life` > NOW()) AND `tabItem`.is_pro_applicable = "Yes" AND tabItem.%(key)s like "%s" ORDER BY `tabItem`.`name` LIMIT 50';
+	return 'SELECT DISTINCT `tabItem`.`name`,`tabItem`.`item_name` \
+		FROM `tabItem` WHERE `tabItem`.is_pro_applicable = "Yes" \
+		AND (IFNULL(`tabItem`.`end_of_life`,"") = "" \
+			OR `tabItem`.`end_of_life`="0000-00-00" OR `tabItem`.`end_of_life` > NOW()) \
+		AND tabItem.%(key)s like "%s" \
+		ORDER BY `tabItem`.`name` LIMIT 50';
 }
 
 cur_frm.fields_dict['pp_details'].grid.get_field('bom_no').get_query = function(doc) {
-  var d = locals[this.doctype][this.docname];
-  return 'SELECT DISTINCT `tabBOM`.`name` FROM `tabBOM` WHERE `tabBOM`.`item` = "' + d.item_code + '" AND `tabBOM`.`is_active` = "Yes" AND `tabBOM`.docstatus = 1 AND `tabBOM`.`name` like "%s" ORDER BY `tabBOM`.`name` LIMIT 50';
+	var d = locals[this.doctype][this.docname];
+  	return 'SELECT DISTINCT `tabBOM`.`name` \
+		FROM `tabBOM` WHERE `tabBOM`.`item` = "' + d.item_code + 
+		'" AND `tabBOM`.`is_active` = "Yes" AND `tabBOM`.docstatus = 1 \
+		AND `tabBOM`.`name` like "%s" ORDER BY `tabBOM`.`name` LIMIT 50';
 }
 
 cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;
diff --git a/production/doctype/production_planning_tool/production_planning_tool.py b/production/doctype/production_planning_tool/production_planning_tool.py
index 68ed4cf..863e254 100644
--- a/production/doctype/production_planning_tool/production_planning_tool.py
+++ b/production/doctype/production_planning_tool/production_planning_tool.py
@@ -16,158 +16,142 @@
 
 from __future__ import unicode_literals
 import webnotes
-from webnotes.utils import cint, cstr, flt, getdate, now, nowdate
+from webnotes.utils import cstr, flt
 from webnotes.model.doc import addchild
 from webnotes.model.wrapper import getlist
 from webnotes.model.code import get_obj
-from webnotes import msgprint, errprint
+from webnotes import msgprint
 
 sql = webnotes.conn.sql
-	
-# -----------------------------------------------------------------------------------------
-
 
 class DocType:
 	def __init__(self, doc, doclist=[]):
 		self.doc = doc
 		self.doclist = doclist
 		self.item_dict = {}
-		
+
+	def get_so_details(self, so):
+		"""Pull other details from so"""
+		so = sql("""select transaction_date, customer, grand_total 
+			from `tabSales Order` where name = %s""", so, as_dict = 1)
+		ret = {
+			'sales_order_date': so and so[0]['transaction_date'] or '',
+			'customer' : so[0]['customer'] or '',
+			'grand_total': so[0]['grand_total']
+		}
+		return ret	
+			
 	def get_item_details(self, item_code):
 		""" Pull other item details from item master"""
 
-		item = sql("""select description, stock_uom, default_bom from `tabItem` where name = %s 
-			and (ifnull(end_of_life,'')='' or end_of_life = '0000-00-00' or end_of_life > now())""", item_code, as_dict =1 )
+		item = sql("""select description, stock_uom, default_bom 
+			from `tabItem` where name = %s""", item_code, as_dict =1)
 		ret = {
 			'description'	: item and item[0]['description'],
 			'stock_uom'		: item and item[0]['stock_uom'],
 			'bom_no'		: item and item[0]['default_bom']
 		}
 		return ret
-	
-
-	def get_so_details(self, so):
-		"""Pull other details from so"""
-		so = sql("select transaction_date, customer, grand_total from `tabSales Order` where name = %s", so, as_dict = 1)
-		ret = {
-			'sales_order_date': so and so[0]['transaction_date'] or '',
-			'customer' : so[0]['customer'] or '',
-			'grand_total': so[0]['grand_total']
-		}
-		return ret
-
 
 	def clear_so_table(self):
-		""" Clears sales order table"""
 		self.doclist = self.doc.clear_table(self.doclist, 'pp_so_details')
 
-
-
 	def clear_item_table(self):
-		""" Clears item table"""
 		self.doclist = self.doc.clear_table(self.doclist, 'pp_details')
-
-
-
-	def get_open_sales_orders(self):
-		""" Pull sales orders  which are pending to deliver based on criteria selected"""
-		cond = self.get_filter_condition()
-		open_so = sql("""
-			select 
-				distinct t1.name, t1.transaction_date, t1.customer, t1.grand_total 
-			from 
-				`tabSales Order` t1, `tabSales Order Item` t2, `tabDelivery Note Packing Item` t3, tabItem t4
-			where 
-				t1.name = t2.parent and t1.name = t3.parent and t3.parenttype = 'Sales Order' and t1.docstatus = 1 and t2.item_code = t3.parent_item 
-				and t4.name = t3.item_code and  t1.status != 'Stopped' and t1.company = '%s' and ifnull(t2.qty, 0) > ifnull(t2.delivered_qty, 0) 
-				and (ifnull(t4.is_pro_applicable, 'No') = 'Yes' or ifnull(t4.is_sub_contracted_item, 'No') = 'Yes') %s
-			order by t1.name desc
-		"""% (self.doc.company, cond), as_dict = 1)
 		
-		self.add_so_in_table(open_so)
-
-
-
 	def validate_company(self):
 		if not self.doc.company:
 			msgprint("Please enter Company", raise_exception=1)
 
-		
-
-	def get_filter_condition(self):
-		self.validate_company()
-
-		cond = ''
+	def get_open_sales_orders(self):
+		""" Pull sales orders  which are pending to deliver based on criteria selected"""
+		so_filter = item_filter = ""
 		if self.doc.from_date:
-			cond += ' and t1.transaction_date >= "' + self.doc.from_date + '"'
+			so_filter += ' and so.transaction_date >= "' + self.doc.from_date + '"'
 		if self.doc.to_date:
-			cond += ' and t1.transaction_date <= "' + self.doc.to_date + '"'
+			so_filter += ' and so.transaction_date <= "' + self.doc.to_date + '"'
 		if self.doc.customer:
-			cond += ' and t1.customer = "' + self.doc.customer + '"'
+			so_filter += ' and so.customer = "' + self.doc.customer + '"'
+			
 		if self.doc.fg_item:
-			cond += ' and t3.item_code = "' + self.doc.fg_item + '"'
-
-		return cond
-
-
+			item_filter += ' and item.name = "' + self.doc.fg_item + '"'
+		
+		open_so = sql("""
+			select distinct so.name, so.transaction_date, so.customer, so.grand_total
+			from `tabSales Order` so, `tabSales Order Item` so_item
+			where so_item.parent = so.name
+				and so.docstatus = 1 and so.status != "Stopped"
+				and so.company = 'Web Notes Technologies Pvt Ltd'
+				and ifnull(so_item.qty, 0) > ifnull(so_item.delivered_qty, 0) %s
+				and (exists (select * from `tabItem` item where item.name=so_item.item_code
+					and (ifnull(item.is_pro_applicable, 'No') = 'Yes' 
+						or ifnull(item.is_sub_contracted_item, 'No') = 'Yes') %s)
+					or exists (select * from `tabDelivery Note Packing Item` dnpi
+						where dnpi.parent = so.name and dnpi.parent_item = so_item.item_code
+							and exists (select * from `tabItem` item where item.name=dnpi.item_code
+								and (ifnull(item.is_pro_applicable, 'No') = 'Yes' 
+									or ifnull(item.is_sub_contracted_item, 'No') = 'Yes') %s)))
+			""" % (so_filter, item_filter, item_filter), as_dict=1)
+		
+		self.add_so_in_table(open_so)
 
 	def add_so_in_table(self, open_so):
 		""" Add sales orders in the table"""
-		so_list = []
-		for d in getlist(self.doclist, 'pp_so_details'):
-			so_list.append(d.sales_order)
+		so_list = [d.sales_order for d in getlist(self.doclist, 'pp_so_details')]
 		for r in open_so:
 			if cstr(r['name']) not in so_list:
-				pp_so = addchild(self.doc, 'pp_so_details', 'Production Plan Sales Order', 1, self.doclist)
+				pp_so = addchild(self.doc, 'pp_so_details', 
+					'Production Plan Sales Order', 1, self.doclist)
 				pp_so.sales_order = r['name']
 				pp_so.sales_order_date = cstr(r['transaction_date'])
 				pp_so.customer = cstr(r['customer'])
 				pp_so.grand_total = flt(r['grand_total'])
 
-
-
 	def get_items_from_so(self):
 		""" Pull items from Sales Order, only proction item
 			and subcontracted item will be pulled from Packing item 
 			and add items in the table
 		"""
-		so = self.get_included_so()
-		items = self.get_packing_items(so)
+		items = self.get_items()
 		self.add_items(items)
 
+	def get_items(self):
+		so_list = filter(None, [d.sales_order for d in getlist(self.doclist, 'pp_so_details')])
+		if not so_list:
+			msgprint("Please enter sales order in the above table", raise_exception=1)
+			
+		items = sql("""select distinct parent, item_code,
+			(qty - ifnull(delivered_qty, 0)) as pending_qty
+			from `tabSales Order Item` so_item
+			where parent in (%s) and docstatus = 1 and ifnull(qty, 0) > ifnull(delivered_qty, 0)
+			and exists (select * from `tabItem` item where item.name=so_item.item_code
+				and (ifnull(item.is_pro_applicable, 'No') = 'Yes' 
+					or ifnull(item.is_sub_contracted_item, 'No') = 'Yes'))""" % \
+			(", ".join(["%s"] * len(so_list))), tuple(so_list), as_dict=1)
+		
+		dnpi_items = sql("""select distinct dnpi.parent, dnpi.item_code,
+			(((so_item.qty - ifnull(so_item.delivered_qty, 0)) * dnpi.qty) / so_item.qty) 
+				as pending_qty
+			from `tabSales Order Item` so_item, `tabDelivery Note Packing Item` dnpi
+			where so_item.parent = dnpi.parent and so_item.docstatus = 1 
+			and dnpi.parent_item = so_item.item_code
+			and so_item.parent in (%s) and ifnull(so_item.qty, 0) > ifnull(so_item.delivered_qty, 0)
+			and exists (select * from `tabItem` item where item.name=dnpi.item_code
+				and (ifnull(item.is_pro_applicable, 'No') = 'Yes' 
+					or ifnull(item.is_sub_contracted_item, 'No') = 'Yes'))""" % \
+			(", ".join(["%s"] * len(so_list))), tuple(so_list), as_dict=1)
 
-	def get_included_so(self):
-		so = "'" + "','".join([cstr(d.sales_order) for d in getlist(self.doclist, 'pp_so_details') if d.include_in_plan]) + "'"
-		return so
-
-
-
-	def get_packing_items(self, so):
-		packing_items = sql("""
-			select 
-				t0.name, t2.parent_item, t2.item_code, 
-				(t1.qty - ifnull(t1.delivered_qty,0)) * (ifnull(t2.qty,0) / ifnull(t1.qty,1)) as 'pending_qty' 
-			from
-				`tabSales Order` t0, `tabSales Order Item` t1, `tabDelivery Note Packing Item` t2, `tabItem` t3
-			where 
-				t0.name = t1.parent and t0.name = t2.parent and t1.name = t2.parent_detail_docname
-				and t0.name in (%s) and t0.docstatus = 1 and t1.qty > ifnull(t1.delivered_qty,0) and t3.name = t2.item_code 
-				and (ifnull(t3.is_pro_applicable, 'No') = 'Yes' or ifnull(t3.is_sub_contracted_item, 'No') = 'Yes')
-		""" % so, as_dict=1)
-		return packing_items
+		return items + dnpi_items
 		
 
+	def add_items(self, items):
+		self.clear_item_table()
 
-	def add_items(self, packing_items):
-		for d in getlist(self.doclist, 'pp_details'):
-			if d.sales_order:
-				d.parent = ''
-
-		for p in packing_items:	
-			item_details = sql("select description, stock_uom, default_bom from tabItem where name=%s", p['item_code'])
+		for p in items:
+			item_details = sql("""select description, stock_uom, default_bom 
+				from tabItem where name=%s""", p['item_code'])
 			pi = addchild(self.doc, 'pp_details', 'Production Plan Item', 1, self.doclist)
-			pi.sales_order				= p['name']
-			pi.parent_packing_item		= p['parent_item']
+			pi.sales_order				= p['parent']
 			pi.item_code				= p['item_code']
 			pi.description				= item_details and item_details[0][0] or ''
 			pi.stock_uom				= item_details and item_details[0][1] or ''
@@ -176,129 +160,112 @@
 			pi.planned_qty				= flt(p['pending_qty'])
 	
 
-
 	def validate_data(self):
 		for d in getlist(self.doclist, 'pp_details'):
-			if not d.pro_created:
-				self.validate_bom_no(d)
-
-				if not flt(d.planned_qty):
-					msgprint("Please Enter Planned Qty for item: %s at row no: %s"% (d.item_code, d.idx), raise_exception=1)
-		return 'validated'
-
+			self.validate_bom_no(d)
+			if not flt(d.planned_qty):
+				msgprint("Please Enter Planned Qty for item: %s at row no: %s" %
+					(d.item_code, d.idx), raise_exception=1)
 				
-
 	def validate_bom_no(self, d):
 		if not d.bom_no:
-			msgprint("Please enter bom no for item: %s at row no: %s" % (d.item_code, d.idx), raise_exception=1)
+			msgprint("Please enter bom no for item: %s at row no: %s" % 
+				(d.item_code, d.idx), raise_exception=1)
 		else:
-			bom = sql("""select name from `tabBOM` where item = %s and docstatus = 1 
-				and name = %s and ifnull(is_active, 'No') = 'Yes'""", (d.item_code, d.bom_no), as_dict = 1)
+			bom = sql("""select name from `tabBOM` where name = %s and item = %s 
+				and docstatus = 1 and ifnull(is_active, 'No') = 'Yes'""", 
+				(d.bom_no, d.item_code), as_dict = 1)
 			if not bom:
 				msgprint("""Incorrect BOM No: %s entered for item: %s at row no: %s
-					May be BOM is inactive or for other item or does not exists in the system"""% (d.bom_no, d.item_doce, d.idx))
+					May be BOM is inactive or for other item or does not exists in the system""" % 
+					(d.bom_no, d.item_doce, d.idx), raise_exception=1)
+
+	def raise_production_order(self):
+		"""It will raise production order (Draft) for all distinct FG items"""
+		self.validate_company()
+		self.validate_data()
+
+		items = self.get_distinct_items_and_boms()[1]
+		pro = get_obj('Production Control').create_production_order(items)
+		if pro:
+			msgprint("Following Production Order has been generated:\n" + '\n'.join(pro))
+		else :
+			msgprint("No Production Order generated.")
 
 
+	def get_distinct_items_and_boms(self):
+		""" Club similar BOM and item for processing"""
+		item_dict, bom_dict = {}, {}
+		for d in self.doclist.get({"parentfield": "pp_details"}):
+			bom_dict[d.bom_no] = bom_dict.get(d.bom_no, 0) + flt(d.planned_qty)
+			item_dict[(d.item_code, d.sales_order)] = {
+				"qty" : flt(item_dict.get((d.item_code, d.sales_order), {}).get("qty")) + \
+				 	flt(d.planned_qty),
+				"bom_no": d.bom_no,
+				"description": d.description,
+				"stock_uom": d.stock_uom,
+				"use_multi_level_bom": self.doc.use_multi_level_bom,
+				"company": self.doc.company,
+			}
+		return bom_dict, item_dict
 
 	def download_raw_materials(self):
 		""" Create csv data for required raw material to produce finished goods"""
-		bom_dict = self.get_distinct_bom(action = 'download_rm')
+		bom_dict = self.get_distinct_items_and_boms()[0]
 		self.get_raw_materials(bom_dict)
 		return self.get_csv()
 
-
-
-	
 	def get_raw_materials(self, bom_dict):
 		""" Get raw materials considering sub-assembly items """
 		for bom in bom_dict:
-			if self.doc.consider_sa_items == 'Yes':
+			if self.doc.use_multi_level_bom:
+				# get all raw materials with sub assembly childs					
+				fl_bom_items = sql("""
+					select 
+						item_code,ifnull(sum(qty_consumed_per_unit),0)*%s as qty, 
+						description, stock_uom
+					from 
+						( 
+							select distinct fb.name, fb.description, fb.item_code,
+							 	fb.qty_consumed_per_unit, fb.stock_uom 
+							from `tabBOM Explosion Item` fb,`tabItem` it 
+							where it.name = fb.item_code 
+							and ifnull(it.is_pro_applicable, 'No') = 'No'
+							and ifnull(it.is_sub_contracted_item, 'No') = 'No' 
+							and fb.docstatus<2 and fb.parent=%s
+						) a
+					group by item_code,stock_uom
+				""" , (flt(bom_dict[bom]), bom))
+			else:
 				# Get all raw materials considering SA items as raw materials, 
 				# so no childs of SA items
 				fl_bom_items = sql("""
-					select item_code, ifnull(sum(qty_consumed_per_unit), 0) * '%s', description, stock_uom 
+					select item_code, ifnull(sum(qty_consumed_per_unit), 0) * '%s', 
+						description, stock_uom 
 					from `tabBOM Item` 
 					where parent = '%s' and docstatus < 2 
 					group by item_code
 				""" % (flt(bom_dict[bom]), bom))
 
-			else:
-				# get all raw materials with sub assembly childs					
-				fl_bom_items = sql("""
-					select 
-						item_code,ifnull(sum(qty_consumed_per_unit),0)*%s as qty, description, stock_uom
-					from 
-						( 
-							select distinct fb.name, fb.description, fb.item_code, fb.qty_consumed_per_unit, fb.stock_uom 
-							from `tabBOM Explosion Item` fb,`tabItem` it 
-							where it.name = fb.item_code and ifnull(it.is_pro_applicable, 'No') = 'No'
-							and ifnull(it.is_sub_contracted_item, 'No') = 'No' and fb.docstatus<2 and fb.parent=%s
-						) a
-					group by item_code,stock_uom
-				""" , (flt(bom_dict[bom]), bom))
-			
 			self.make_items_dict(fl_bom_items)
 
-
-
 	def make_items_dict(self, item_list):
 		for i in item_list:
 			self.item_dict[i[0]] = [(flt(self.item_dict.get(i[0], [0])[0]) + flt(i[1])), i[2], i[3]]
 
 
 	def get_csv(self):
-		item_list = [['Item Code', 'Description', 'Stock UOM', 'Required Qty', 'Warehouse', 'Quantity Requested for Purchase', 'Ordered Qty', 'Actual Qty']]
+		item_list = [['Item Code', 'Description', 'Stock UOM', 'Required Qty', 'Warehouse',
+		 	'Quantity Requested for Purchase', 'Ordered Qty', 'Actual Qty']]
 		for d in self.item_dict:
-			item_list.append([d, self.item_dict[d][1], self.item_dict[d][2], self.item_dict[d][0]]),
-			item_qty= sql("select warehouse, indented_qty, ordered_qty, actual_qty from `tabBin` where item_code = %s", d)
-			i_qty, o_qty, a_qty = 0,0,0
+			item_list.append([d, self.item_dict[d][1], self.item_dict[d][2], self.item_dict[d][0]])
+			item_qty= sql("""select warehouse, indented_qty, ordered_qty, actual_qty 
+				from `tabBin` where item_code = %s""", d)
+			i_qty, o_qty, a_qty = 0, 0, 0
 			for w in item_qty:
 				i_qty, o_qty, a_qty = i_qty + flt(w[1]), o_qty + flt(w[2]), a_qty + flt(w[3])
 				item_list.append(['', '', '', '', w[0], flt(w[1]), flt(w[2]), flt(w[3])])
 			if item_qty:
 				item_list.append(['', '', '', '', 'Total', i_qty, o_qty, a_qty])
 
-		return item_list
-		
-
-
-	def raise_production_order(self):
-		"""It will raise production order (Draft) for all distinct FG items"""
-		self.validate_company()
-		self.validate_data()
-
-		pp_items = self.get_distinct_bom(action = 'raise_pro_order')
-		pro = get_obj(dt = 'Production Control').create_production_order(self.doc.company, pp_items)
-		if pro:
-			for d in getlist(self.doclist, 'pp_details'):
-				d.is_pro_created = 1
-			msgprint("Following Production Order has been generated:\n" + '\n'.join(pro))
-		else :
-			msgprint("No Production Order is generated.")
-
-
-
-	def get_distinct_bom(self, action):
-		""" Club similar BOM and item for processing"""
-
-		bom_dict, item_dict, pp_items = {}, {}, []
-		for d in getlist(self.doclist, 'pp_details'):
-			if action == 'download_rm':
-				bom_dict[d.bom_no] = bom_dict.get(d.bom_no, 0) + flt(d.planned_qty)
-			elif not d.is_pro_created:
-				item_dict[d.item_code] = [
-					(flt(item_dict.get(d.item_code, [0])[0]) + flt(d.planned_qty)),
-					d.bom_no, d.description, d.stock_uom]
-
-		if action == 'raise_pro_order':
-			for d in item_dict:
-				pp_items.append({
-					'production_item'	: d, 
-					'qty'				: item_dict[d][0],
-					'bom_no'			: item_dict[d][1],
-					'description'		: item_dict[d][2],
-					'stock_uom'			: item_dict[d][3],
-					'consider_sa_items' : self.doc.consider_sa_items
-				})
-
-		return action == 'download_rm' and bom_dict or pp_items
+		return item_list
\ No newline at end of file
diff --git a/production/doctype/production_planning_tool/production_planning_tool.txt b/production/doctype/production_planning_tool/production_planning_tool.txt
index 9634f93..42a76f7 100644
--- a/production/doctype/production_planning_tool/production_planning_tool.txt
+++ b/production/doctype/production_planning_tool/production_planning_tool.txt
@@ -1,318 +1,219 @@
-# DocType, Production Planning Tool
 [
-
-	# These values are common in all dictionaries
-	{
-		'creation': '2012-03-27 14:36:05',
-		'docstatus': 0,
-		'modified': '2012-03-27 14:36:05',
-		'modified_by': u'Administrator',
-		'owner': u'jai@webnotestech.com'
-	},
-
-	# These values are common for all DocType
-	{
-		'_last_update': u'1326188323',
-		'colour': u'White:FFF',
-		'default_print_format': u'Standard',
-		'doctype': 'DocType',
-		'in_create': 1,
-		'issingle': 1,
-		'module': u'Production',
-		'name': '__common__',
-		'read_only': 1,
-		'section_style': u'Tabbed',
-		'server_code_error': u' ',
-		'show_in_menu': 1,
-		'version': 106
-	},
-
-	# These values are common for all DocField
-	{
-		'doctype': u'DocField',
-		'name': '__common__',
-		'parent': u'Production Planning Tool',
-		'parentfield': u'fields',
-		'parenttype': u'DocType',
-		'permlevel': 0
-	},
-
-	# These values are common for all DocPerm
-	{
-		'create': 1,
-		'doctype': u'DocPerm',
-		'name': '__common__',
-		'parent': u'Production Planning Tool',
-		'parentfield': u'permissions',
-		'parenttype': u'DocType',
-		'permlevel': 0,
-		'read': 1,
-		'write': 1
-	},
-
-	# DocType, Production Planning Tool
-	{
-		'doctype': 'DocType',
-		'name': u'Production Planning Tool'
-	},
-
-	# DocPerm
-	{
-		'doctype': u'DocPerm',
-		'role': u'System Manager'
-	},
-
-	# DocPerm
-	{
-		'doctype': u'DocPerm',
-		'role': u'Production User'
-	},
-
-	# DocPerm
-	{
-		'doctype': u'DocPerm',
-		'role': u'Production Manager'
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'doctype': u'DocField',
-		'fieldname': u'select_sales_orders',
-		'fieldtype': u'Section Break',
-		'label': u'Select Sales Orders'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'column_break0',
-		'fieldtype': u'Column Break',
-		'width': u'50%'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'from_date',
-		'fieldtype': u'Date',
-		'label': u'From Date'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'to_date',
-		'fieldtype': u'Date',
-		'label': u'To Date'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'fg_item',
-		'fieldtype': u'Link',
-		'label': u'FG Item',
-		'options': u'Item'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'column_break1',
-		'fieldtype': u'Column Break',
-		'width': u'50%'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'customer',
-		'fieldtype': u'Link',
-		'label': u'Customer',
-		'options': u'Customer'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'company',
-		'fieldtype': u'Link',
-		'label': u'Company',
-		'options': u'Company',
-		'reqd': 1
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'section_break0',
-		'fieldtype': u'Section Break',
-		'options': u'Simple'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'column_break2',
-		'fieldtype': u'Column Break',
-		'width': u'50%'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'get_sales_orders',
-		'fieldtype': u'Button',
-		'label': u'Get Sales Orders',
-		'options': u'get_open_sales_orders'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'column_break3',
-		'fieldtype': u'Column Break',
-		'width': u'50%'
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'doctype': u'DocField',
-		'fieldname': u'clear_so_table',
-		'fieldtype': u'Button',
-		'label': u'Clear SO Table',
-		'options': u'clear_so_table',
-		'trigger': u'Client'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'section_break1',
-		'fieldtype': u'Section Break',
-		'options': u'Simple'
-	},
-
-	# DocField
-	{
-		'description': u'Select Sales Orders from which you want to create Production Orders. You can get sales orders based on above criteria.',
-		'doctype': u'DocField',
-		'fieldname': u'pp_so_details',
-		'fieldtype': u'Table',
-		'label': u'Production Plan Sales Orders',
-		'options': u'Production Plan Sales Order'
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'doctype': u'DocField',
-		'fieldname': u'items',
-		'fieldtype': u'Section Break',
-		'label': u'Items'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'get_items_from_so',
-		'fieldtype': u'Button',
-		'label': u'Get Items from SO',
-		'options': u'get_items_from_so'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'column_break4',
-		'fieldtype': u'Column Break',
-		'width': u'50%'
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'doctype': u'DocField',
-		'fieldname': u'clear_item_table',
-		'fieldtype': u'Button',
-		'label': u'Clear Item Table',
-		'options': u'clear_item_table',
-		'trigger': u'Client'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'section_break2',
-		'fieldtype': u'Section Break',
-		'options': u'Simple'
-	},
-
-	# DocField
-	{
-		'description': u'Enter items and planned qty for which you want to raise production orders or download raw materials for analysis. You can pull items (which are pending to deliver) from SO as well by adding SO in plan.',
-		'doctype': u'DocField',
-		'fieldname': u'pp_details',
-		'fieldtype': u'Table',
-		'label': u'Production Plan Items',
-		'options': u'Production Plan Item'
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'default': u'No',
-		'description': u'Select "Yes" if stock is maintained and tracked for sub assembly items.',
-		'doctype': u'DocField',
-		'fieldname': u'consider_sa_items',
-		'fieldtype': u'Select',
-		'label': u'Consider Sub Assemblies as Raw Material',
-		'options': u'No\nYes',
-		'reqd': 1
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'section_break3',
-		'fieldtype': u'Section Break',
-		'options': u'Simple'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'column_break5',
-		'fieldtype': u'Column Break',
-		'width': u'50%'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'raise_production_order',
-		'fieldtype': u'Button',
-		'label': u'Raise Production Order',
-		'options': u'raise_production_order'
-	},
-
-	# DocField
-	{
-		'doctype': u'DocField',
-		'fieldname': u'column_break6',
-		'fieldtype': u'Column Break',
-		'width': u'50%'
-	},
-
-	# DocField
-	{
-		'colour': u'White:FFF',
-		'doctype': u'DocField',
-		'fieldname': u'download_raw_material',
-		'fieldtype': u'Button',
-		'label': u'Download Raw Material',
-		'trigger': u'Client'
-	}
+ {
+  "owner": "jai@webnotestech.com", 
+  "docstatus": 0, 
+  "creation": "2012-07-03 13:30:03", 
+  "modified_by": "Administrator", 
+  "modified": "2012-11-30 14:08:55"
+ }, 
+ {
+  "read_only": 1, 
+  "issingle": 1, 
+  "in_create": 1, 
+  "default_print_format": "Standard", 
+  "doctype": "DocType", 
+  "module": "Production", 
+  "name": "__common__"
+ }, 
+ {
+  "name": "__common__", 
+  "parent": "Production Planning Tool", 
+  "doctype": "DocField", 
+  "parenttype": "DocType", 
+  "permlevel": 0, 
+  "parentfield": "fields"
+ }, 
+ {
+  "name": "__common__", 
+  "parent": "Production Planning Tool", 
+  "read": 1, 
+  "create": 1, 
+  "doctype": "DocPerm", 
+  "write": 1, 
+  "parenttype": "DocType", 
+  "permlevel": 0, 
+  "parentfield": "permissions"
+ }, 
+ {
+  "name": "Production Planning Tool", 
+  "doctype": "DocType"
+ }, 
+ {
+  "description": "Select Sales Orders from which you want to create Production Orders.", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Select Sales Orders", 
+  "fieldname": "select_sales_orders", 
+  "fieldtype": "Section Break"
+ }, 
+ {
+  "doctype": "DocField", 
+  "width": "50%", 
+  "fieldname": "column_break0", 
+  "fieldtype": "Column Break"
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Filter based on item", 
+  "fieldname": "fg_item", 
+  "fieldtype": "Link", 
+  "options": "Item"
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Filter based on customer", 
+  "fieldname": "customer", 
+  "fieldtype": "Link", 
+  "options": "Customer"
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Company", 
+  "reqd": 1, 
+  "fieldname": "company", 
+  "fieldtype": "Link", 
+  "options": "Company"
+ }, 
+ {
+  "doctype": "DocField", 
+  "width": "50%", 
+  "fieldname": "column_break1", 
+  "fieldtype": "Column Break"
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "From Date", 
+  "fieldname": "from_date", 
+  "fieldtype": "Date"
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "To Date", 
+  "fieldname": "to_date", 
+  "fieldtype": "Date"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "section_break1", 
+  "fieldtype": "Section Break", 
+  "options": "Simple"
+ }, 
+ {
+  "description": "Pull sales orders (pending to deliver) based on the above criteria", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Get Sales Orders", 
+  "fieldname": "get_sales_orders", 
+  "fieldtype": "Button", 
+  "options": "get_open_sales_orders"
+ }, 
+ {
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Production Plan Sales Orders", 
+  "fieldname": "pp_so_details", 
+  "fieldtype": "Table", 
+  "options": "Production Plan Sales Order"
+ }, 
+ {
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Clear Table", 
+  "trigger": "Client", 
+  "fieldname": "clear_so_table", 
+  "fieldtype": "Button", 
+  "options": "clear_so_table"
+ }, 
+ {
+  "description": "Enter items and planned qty for which you want to raise production orders or download raw materials for analysis.", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Create Production Orders", 
+  "fieldname": "create_production_orders", 
+  "fieldtype": "Section Break"
+ }, 
+ {
+  "description": "Pull items from Sales Order mentioned in the above table.", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Get Items", 
+  "fieldname": "get_items_from_so", 
+  "fieldtype": "Button", 
+  "options": "get_items_from_so"
+ }, 
+ {
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Production Plan Items", 
+  "fieldname": "pp_details", 
+  "fieldtype": "Table", 
+  "options": "Production Plan Item"
+ }, 
+ {
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Clear Table", 
+  "trigger": "Client", 
+  "fieldname": "clear_item_table", 
+  "fieldtype": "Button", 
+  "options": "clear_item_table"
+ }, 
+ {
+  "description": "If checked, BOM for sub-assembly items will be considered for raw materials. Otherwise, all sub-assembly items will be treated as a raw material.", 
+  "default": "1", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Use Multi-Level BOM", 
+  "reqd": 1, 
+  "fieldname": "use_multi_level_bom", 
+  "fieldtype": "Check"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "section_break3", 
+  "fieldtype": "Section Break", 
+  "options": "Simple"
+ }, 
+ {
+  "doctype": "DocField", 
+  "width": "50%", 
+  "fieldname": "column_break5", 
+  "fieldtype": "Column Break"
+ }, 
+ {
+  "description": "Separate production order will be created for each finished good item.", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Raise Production Order", 
+  "fieldname": "raise_production_order", 
+  "fieldtype": "Button", 
+  "options": "raise_production_order"
+ }, 
+ {
+  "doctype": "DocField", 
+  "width": "50%", 
+  "fieldname": "column_break6", 
+  "fieldtype": "Column Break"
+ }, 
+ {
+  "description": "Download a report containing all raw materials with their latest inventory status", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Download Materials Required", 
+  "trigger": "Client", 
+  "fieldname": "download_materials_required", 
+  "fieldtype": "Button"
+ }, 
+ {
+  "role": "System Manager", 
+  "doctype": "DocPerm"
+ }, 
+ {
+  "role": "Production User", 
+  "doctype": "DocPerm"
+ }, 
+ {
+  "role": "Production Manager", 
+  "doctype": "DocPerm"
+ }
 ]
\ No newline at end of file
diff --git a/production/doctype/workstation/workstation.py b/production/doctype/workstation/workstation.py
index 414efd9..fdd4022 100644
--- a/production/doctype/workstation/workstation.py
+++ b/production/doctype/workstation/workstation.py
@@ -14,24 +14,15 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import flt
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/projects/doctype/project/project.py b/projects/doctype/project/project.py
index 5c0417b..3e334e8 100644
--- a/projects/doctype/project/project.py
+++ b/projects/doctype/project/project.py
@@ -14,24 +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/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import flt, getdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.doc import Document
+from webnotes.model.wrapper import copy_doclist
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/projects/doctype/project_control/project_control.py b/projects/doctype/project_control/project_control.py
index 33a535b..5601837 100644
--- a/projects/doctype/project_control/project_control.py
+++ b/projects/doctype/project_control/project_control.py
@@ -14,24 +14,16 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, set_default, str_esc_quote, user_format, validate_email_add, add_days
+from webnotes.utils import add_days, cint, cstr, date_diff, flt, now, nowdate, add_days
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
+from webnotes import msgprint
 from webnotes.utils.email_lib import sendmail
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/projects/doctype/task/task.py b/projects/doctype/task/task.py
index 89e12cd..c390806 100644
--- a/projects/doctype/task/task.py
+++ b/projects/doctype/task/task.py
@@ -14,21 +14,16 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, set_default, str_esc_quote, user_format, validate_email_add
-from webnotes.utils.email_lib import sendmail
+from webnotes.utils import getdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
+from webnotes import msgprint
 
 sql = webnotes.conn.sql
 
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/projects/doctype/timesheet/timesheet.py b/projects/doctype/timesheet/timesheet.py
index ebabf09..775937e 100644
--- a/projects/doctype/timesheet/timesheet.py
+++ b/projects/doctype/timesheet/timesheet.py
@@ -14,24 +14,16 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cint, cstr, getdate, now, nowdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/public/js/communication.js b/public/js/communication.js
deleted file mode 100644
index 70a08af..0000000
--- a/public/js/communication.js
+++ /dev/null
@@ -1,144 +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/>.
-
-// opts - parent, list, doc, email
-erpnext.CommunicationView = Class.extend({
-	init: function(opts) {
-		this.comm_list = [];
-		$.extend(this, opts);
-		
-		if(this.doc.__islocal) {
-			return;
-		}
-		
-		this.list.sort(function(a, b) { return 
-			(new Date(a.modified) > new Date(b.modified)) 
-			? -1 : 1; })
-				
-		this.make();
-	},
-	make: function() {
-		var me = this;
-		this.make_body();
-
-		if(this.list && this.list.length) {
-			$.each(this.list, function(i, d) {
-				me.prepare(d);
-				me.make_line(d);
-			});			
-			// show first
-			this.comm_list[0].find('.comm-content').toggle(true);			
-		} else {
-			this.body.remove()
-			$("<div class='alert'>No Communication with this " 
-				+ this.doc.doctype +" yet.</div>").appendTo(this.wrapper);
-		}
-		
-	},
-	make_body: function() {
-		$(this.parent)
-			.html("")
-			.css({"margin":"10px 0px"});
-			
-		this.wrapper = $("<div><h4>Communication History</h4>\
-			<div style='margin-bottom: 8px;'>\
-				<button class='btn btn-small' \
-					onclick='cur_frm.communication_view.add_reply()'>\
-				<i class='icon-plus'></i> Add Reply</button></div>\
-			</div>")
-			.appendTo(this.parent);
-			
-		this.body = $("<table class='table table-bordered table-hover table-striped'>")
-			.appendTo(this.wrapper);
-	},
-	add_reply: function() {
-		var me = this;
-		var d = new wn.ui.Dialog({
-			width: 640,
-			title: "Add Reply: " + (this.doc.subject || ""),
-			fields: [
-				{label:"Subject", fieldtype:"Data", reqd: 1},
-				{label:"Message", fieldtype:"Text Editor", reqd: 1, fieldname:"content"},
-				{label:"Send Email", fieldtype:"Check"},
-				{label:"Add Reply", fieldtype:"Button"},
-			]
-		});
-		
-		$(d.fields_dict.send_email.input).attr("checked", "checked")
-		$(d.fields_dict.add_reply.input).click(function() {
-			var args = d.get_values();
-			if(!args) return;
-			$(this).set_working();
-			wn.call({
-				method:"support.doctype.communication.communication.make",
-				args: $.extend(args, {
-					doctype: me.doc.doctype,
-					name: me.doc.name,
-					lead: me.doc.lead,
-					contact: me.doc.contact,
-					recipients: me.email
-				}),
-				callback: function(r) {
-					d.hide();
-					cur_frm.reload_doc();
-				}
-			});
-		});
-		
-		if(me.list.length > 0) {
-			d.fields_dict.content.input.set_input("<p></p>"
-				+ (wn.boot.profile.email_signature || "")
-				+"<p></p>"
-				+"-----In response to-----<p></p>" 
-				+ me.list[0].content)			
-		} else {
-			
-		}
-		$(d.fields_dict.subject.input).val(this.doc.subject || "").change();
-		
-		d.show();
-	},
-
-	prepare: function(doc) {
-		//doc.when = comment_when(this.doc.modified);
-		doc.when = doc.modified;
-		if(doc.content.indexOf("<br>")== -1 && doc.content.indexOf("<p>")== -1) {
-			doc.content = doc.content.replace(/\n/g, "<br>");
-		}
-		if(!doc.sender) doc.sender = "[unknown sender]";
-		doc.sender = doc.sender.replace(/</, "&lt;").replace(/>/, "&gt;");
-		doc.content = doc.content.split("-----In response to-----")[0];
-		doc.content = doc.content.split("-----Original Message-----")[0];
-	},
-	make_line: function(doc) {
-		var me = this;
-		var comm = $(repl('<tr><td title="Click to Expand / Collapse">\
-				<p><b>%(sender)s on %(when)s</b> \
-					<a href="#Form/Communication/%(name)s" style="font-size: 90%">\
-						Show Details</a></p>\
-				<div class="comm-content" style="border-top: 1px solid #ddd; \
-					padding: 10px; overflow-x: auto; display: none;"></div>\
-			</td></tr>', doc))
-			.appendTo(this.body)
-			.css({"cursor":"pointer"})
-			.click(function() {
-				$(this).find(".comm-content").toggle();
-			});
-		
-		this.comm_list.push(comm);
-		comm.find(".comm-content").html(doc.content);
-	}
-})
diff --git a/sandbox/test_leave.py b/sandbox/test_leave.py
index 2094bfd..25601b7 100644
--- a/sandbox/test_leave.py
+++ b/sandbox/test_leave.py
@@ -22,10 +22,7 @@
 webnotes.user = webnotes.profile.Profile()
 
 
-from webnotes.model.doc import Document
 from webnotes.model.code import get_obj
-from webnotes.utils import cstr, flt
-from webnotes.model.wrapper import getlist
 sql = webnotes.conn.sql
 
 from sandbox.testdata import leaves
diff --git a/sandbox/test_stock_entry.py b/sandbox/test_stock_entry.py
index ec47b98..fe28880 100644
--- a/sandbox/test_stock_entry.py
+++ b/sandbox/test_stock_entry.py
@@ -22,10 +22,7 @@
 webnotes.user = webnotes.profile.Profile()
 
 
-from webnotes.model.doc import Document
 from webnotes.model.code import get_obj
-from webnotes.utils import cstr, flt
-from webnotes.model.wrapper import getlist
 sql = webnotes.conn.sql
 
 from sandbox.testdata.masters import *
diff --git a/sandbox/test_stock_reco.py b/sandbox/test_stock_reco.py
index b77401c..ada85b4 100644
--- a/sandbox/test_stock_reco.py
+++ b/sandbox/test_stock_reco.py
@@ -22,10 +22,7 @@
 webnotes.user = webnotes.profile.Profile()
 
 
-from webnotes.model.doc import Document
 from webnotes.model.code import get_obj
-from webnotes.utils import cstr, flt
-from webnotes.model.wrapper import getlist
 sql = webnotes.conn.sql
 
 from sandbox.testdata.masters import *
diff --git a/selling/doctype/customer/customer.js b/selling/doctype/customer/customer.js
index 2031fe8..d20b0c9 100644
--- a/selling/doctype/customer/customer.js
+++ b/selling/doctype/customer/customer.js
@@ -15,9 +15,6 @@
 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 wn.require('app/setup/doctype/contact_control/contact_control.js');
-wn.require('app/support/doctype/communication/communication.js');
-
-/* ********************************* onload ********************************************* */
 
 cur_frm.cscript.onload = function(doc,dt,dn){
 	// history doctypes and scripts
@@ -32,8 +29,6 @@
   	//cur_frm.cscript.make_sl_body();
 
 	cur_frm.cscript.load_defaults(doc, dt, dn);
-	
-	cur_frm.cscript.make_communication_body();
 }
 
 cur_frm.cscript.load_defaults = function(doc, dt, dn) {
@@ -47,8 +42,6 @@
 cur_frm.add_fetch('lead_name', 'company_name', 'customer_name');
 cur_frm.add_fetch('default_sales_partner','commission_rate','default_commission_rate');
 
-/* ********************************* refresh ********************************************* */
-
 cur_frm.cscript.refresh = function(doc,dt,dn) {
 	if(sys_defaults.cust_master_name == 'Customer Name')
 		hide_field('naming_series');
@@ -57,16 +50,18 @@
 
 	if(doc.__islocal){		
 		hide_field(['address_html','contact_html']);
-		//cur_frm.cscript.set_hl_msg(doc);
- 		//cur_frm.cscript.set_sl_msg(doc);
 	}else{
 		unhide_field(['address_html','contact_html']);
 		// make lists
 		cur_frm.cscript.make_address(doc,dt,dn);
 		cur_frm.cscript.make_contact(doc,dt,dn);
 		cur_frm.cscript.make_history(doc,dt,dn);
-		cur_frm.cscript.render_communication_list(doc, cdt, cdn);
-		//cur_frm.cscript.make_shipping_address(doc,dt,dn);
+
+		cur_frm.communication_view = new wn.views.CommunicationList({
+			list: wn.model.get("Communication", {"customer": doc.name}),
+			parent: cur_frm.fields_dict.communication_html.wrapper,
+			doc: doc
+		});
 	}
 }
 
@@ -117,11 +112,6 @@
 
 }
 
-/* ********************************* client triggers ************************************** */
-
-// ---------------
-// customer group
-// ---------------
 cur_frm.fields_dict['customer_group'].get_query = function(doc,dt,dn) {
 	return 'SELECT `tabCustomer Group`.`name`, `tabCustomer Group`.`parent_customer_group` FROM `tabCustomer Group` WHERE `tabCustomer Group`.`is_group` = "No" AND `tabCustomer Group`.`docstatus`!= 2 AND `tabCustomer Group`.%(key)s LIKE "%s" ORDER BY	`tabCustomer Group`.`name` ASC LIMIT 50';
 }
@@ -130,8 +120,6 @@
 cur_frm.fields_dict.lead_name.get_query = erpnext.utils.lead_query;
 
 
-// Transaction History
-// functions called by these functions are defined in communication.js
 cur_frm.cscript.make_qtn_list = function(parent, doc) {
 	cur_frm.cscript.get_common_list_view(parent, doc, 'Quotation');
 }
@@ -173,7 +161,6 @@
 	cur_frm.cscript.render_list(doc, doctype, parent, ListView);
 }
 
-
 cur_frm.cscript.make_si_list = function(parent, doc) {
 	var ListView = wn.views.ListView.extend({
 		init: function(doclistview) {
diff --git a/selling/doctype/customer/customer.py b/selling/doctype/customer/customer.py
index 0bf499b..ee5ef54 100644
--- a/selling/doctype/customer/customer.py
+++ b/selling/doctype/customer/customer.py
@@ -14,28 +14,26 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import cstr, date_diff, flt, formatdate, get_defaults, getdate, has_common, now, nowdate, replace_newlines, sendmail, set_default, user_format, validate_email_add
+from webnotes.utils import cstr, get_defaults
 from webnotes.model.doc import Document, make_autoname
 from webnotes.model.code import get_obj
-from webnotes import msgprint, errprint
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-convert_to_lists = webnotes.conn.convert_to_lists
 
-# -----------------------------------------------------------------------------------------
+from utilities.transaction_base import TransactionBase
 
-class DocType:
+class DocType(TransactionBase):
 	def __init__(self, doc, doclist=[]):
 		self.doc = doc
 		self.doclist = doclist
 	
-# ******************************************************* autoname ***********************************************************
+	def onload(self):
+		self.add_communication_list()
+			
 	def autoname(self):
 		cust_master_name = get_defaults().get('cust_master_name')
 		if cust_master_name == 'Customer Name':
@@ -53,17 +51,9 @@
 		else:
 			self.doc.name = make_autoname(self.doc.naming_series+'.#####')
 
-
-# ******************************************************* triggers ***********************************************************
-	# ----------------
-	# get company abbr
-	# -----------------
 	def get_company_abbr(self):
 		return get_value('Company', self.doc.company, 'abbr')
 
-	# -----------------------------------------------------------------------------------------------------
-	# get parent account(i.e receivables group from company where default account head need to be created)
-	# -----------------------------------------------------------------------------------------------------
 	def get_receivables_group(self):
 		g = sql("select receivables_group from tabCompany where name=%s", self.doc.company)
 		g = g and g[0][0] or '' 
@@ -72,26 +62,15 @@
 			raise Exception
 		return g
 	
-# ******************************************************* validate *********************************************************
-	# ----------------
-	# validate values
-	# ----------------
 	def validate_values(self):
 		# Master name by naming series -> Series field mandatory
 		if get_defaults().get('cust_master_name') == 'Naming Series' and not self.doc.naming_series:
 			msgprint("Series is Mandatory.")
 			raise Exception
 
-	# ---------
-	# validate
-	# ---------
 	def validate(self):
 		self.validate_values()
 
-# ******************************************************* on update *********************************************************
-	# ------------------------
-	# create customer address
-	# ------------------------
 	def create_customer_address(self):
 		addr_flds = [self.doc.address_line1, self.doc.address_line2, self.doc.city, self.doc.state, self.doc.country, self.doc.pincode]
 		address_line = "\n".join(filter(lambda x : (x!='' and x!=None),addr_flds))
@@ -100,15 +79,11 @@
 			address_line = address_line + "\n" + "Phone: " + cstr(self.doc.phone_1)
 		if self.doc.email_id:
 			address_line = address_line + "\n" + "E-mail: " + cstr(self.doc.email_id)
-		set(self.doc,'address', address_line)
+		webnotes.conn.set(self.doc,'address', address_line)
 		
 		telephone = "(O): " + cstr(self.doc.phone_1) +"\n"+ cstr(self.doc.phone_2) + "\n" + "(M): " +	"\n" + "(fax): " + cstr(self.doc.fax_1)
-		set(self.doc,'telephone',telephone)
+		webnotes.conn.set(self.doc,'telephone',telephone)
 
-
-	# ------------------------------------
-	# create primary contact for customer
-	# ------------------------------------
 	def create_p_contact(self,nm,phn_no,email_id,mob_no,fax,cont_addr):
 		c1 = Document('Contact')
 		c1.first_name = nm
@@ -126,10 +101,6 @@
 		c1.customer_group = self.doc.customer_group
 		c1.save(1)
 
-
-	# ------------------------
-	# create customer contact
-	# ------------------------
 	def create_customer_contact(self):
 		contact = sql("select distinct name from `tabContact` where customer_name=%s", (self.doc.customer_name))
 		contact = contact and contact[0][0] or ''
@@ -143,18 +114,10 @@
 				c_detail = sql("select lead_name, company_name, contact_no, mobile_no, email_id, fax, address from `tabLead` where name =%s", self.doc.lead_name, as_dict=1)
 				self.create_p_contact(c_detail and c_detail[0]['lead_name'] or '', c_detail and c_detail[0]['contact_no'] or '', c_detail and c_detail[0]['email_id'] or '', c_detail and c_detail[0]['mobile_no'] or '', c_detail and c_detail[0]['fax'] or '', c_detail and c_detail[0]['address'] or '')
 
-
-	# -------------------
-	# update lead status
-	# -------------------
 	def update_lead_status(self):
 		if self.doc.lead_name:
 			sql("update `tabLead` set status='Converted' where name = %s", self.doc.lead_name)
 
-
-	# -------------------------------------------------------------------------
-	# create accont head - in tree under receivables_group of selected company
-	# -------------------------------------------------------------------------
 	def create_account_head(self):
 		if self.doc.company :
 			abbr = self.get_company_abbr()
@@ -167,15 +130,9 @@
 		else :
 			msgprint("Please Select Company under which you want to create account head")
 
-
-	# ----------------------------------------
-	# update credit days and limit in account
-	# ----------------------------------------
 	def update_credit_days_limit(self):
 		sql("update tabAccount set credit_days = '%s', credit_limit = '%s' where name = '%s'" % (self.doc.credit_days, self.doc.credit_limit, self.doc.name + " - " + self.get_company_abbr()))
 
-
-	#create address and contact from lead
 	def create_lead_address_contact(self):
 		if self.doc.lead_name:
 			details = sql("select name, lead_name, address_line1, address_line2, city, country, state, pincode, phone, mobile_no, fax, email_id from `tabLead` where name = '%s'" %(self.doc.lead_name), as_dict = 1)
@@ -211,9 +168,6 @@
 			except NameError, e:
 				pass
 
-	# ----------
-	# on update
-	# ----------
 	def on_update(self):
 		# create customer addr
 		#self.create_customer_address()
@@ -257,8 +211,6 @@
 		if self.doc.lead_name:
 			sql("update `tabLead` set status='Interested' where name=%s",self.doc.lead_name)
 			
-	# on rename
-	# ---------
 	def on_rename(self,newdn,olddn):
 		#update customer_name if not naming series
 		if get_defaults().get('cust_master_name') == 'Customer Name':
diff --git a/selling/doctype/customer/customer.txt b/selling/doctype/customer/customer.txt
index a20a982..6b174d7 100644
--- a/selling/doctype/customer/customer.txt
+++ b/selling/doctype/customer/customer.txt
@@ -2,11 +2,12 @@
  {
   "owner": "Administrator", 
   "docstatus": 0, 
-  "creation": "2012-10-02 11:27:30", 
+  "creation": "2012-11-02 17:16:46", 
   "modified_by": "Administrator", 
-  "modified": "2012-09-28 12:31:42"
+  "modified": "2012-11-30 10:54:38"
  }, 
  {
+  "autoname": "naming_series:", 
   "name": "__common__", 
   "default_print_format": "Standard", 
   "allow_print": 0, 
@@ -35,6 +36,17 @@
   "doctype": "DocType"
  }, 
  {
+  "description": "Note: You Can Manage Multiple Address or Contacts via Addresses & Contacts", 
+  "oldfieldtype": "Section Break", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Basic Info", 
+  "fieldname": "basic_info", 
+  "fieldtype": "Section Break", 
+  "reqd": 0, 
+  "permlevel": 0
+ }, 
+ {
   "print_hide": 0, 
   "no_copy": 1, 
   "oldfieldtype": "Data", 
@@ -183,7 +195,6 @@
  }, 
  {
   "doctype": "DocField", 
-  "label": "Communication History", 
   "fieldname": "communication_history", 
   "fieldtype": "Section Break", 
   "permlevel": 0
diff --git a/selling/doctype/installation_note/installation_note.py b/selling/doctype/installation_note/installation_note.py
index 5de9557..43f5286 100644
--- a/selling/doctype/installation_note/installation_note.py
+++ b/selling/doctype/installation_note/installation_note.py
@@ -14,24 +14,18 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr, getdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
+from webnotes.model.doc import make_autoname
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 from utilities.transaction_base import TransactionBase
 
diff --git a/selling/doctype/lead/lead.js b/selling/doctype/lead/lead.js
index 39522f8..0c5bf87 100644
--- a/selling/doctype/lead/lead.js
+++ b/selling/doctype/lead/lead.js
@@ -16,7 +16,6 @@
 
 // Module CRM
 
-wn.require("public/app/js/communication.js");
 wn.require('app/utilities/doctype/sms_control/sms_control.js');
 
 cur_frm.cscript.onload = function(doc, cdt, cdn) {
@@ -68,13 +67,12 @@
 	cur_frm.cscript.refresh_custom_buttons(doc);
 	erpnext.hide_naming_series();
 
-	cur_frm.communication_view = new erpnext.CommunicationView({
+	cur_frm.communication_view = new wn.views.CommunicationList({
 		list: wn.model.get("Communication", {"lead": doc.name}),
 		parent: cur_frm.fields_dict.communication_html.wrapper,
 		doc: doc,
 		email: doc.email_id
 	})
-		
 }
 
 
diff --git a/selling/doctype/lead/lead.py b/selling/doctype/lead/lead.py
index be11da4..d844b8d 100644
--- a/selling/doctype/lead/lead.py
+++ b/selling/doctype/lead/lead.py
@@ -14,11 +14,10 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.	If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import cint, cstr, flt, validate_email_add
+from webnotes.utils import cstr, validate_email_add
 from webnotes.model.doc import Document, addchild
 from webnotes import session, msgprint
 
diff --git a/selling/doctype/opportunity/opportunity.js b/selling/doctype/opportunity/opportunity.js
index a729092..3da2ac8 100644
--- a/selling/doctype/opportunity/opportunity.js
+++ b/selling/doctype/opportunity/opportunity.js
@@ -15,7 +15,6 @@
 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 wn.require('app/utilities/doctype/sms_control/sms_control.js');
-wn.require('app/support/doctype/communication/communication.js');
 
 cur_frm.cscript.refresh = function(doc, cdt, cdn){
 	erpnext.hide_naming_series();
@@ -26,7 +25,6 @@
 		cur_frm.add_custom_button('Opportunity Lost', cur_frm.cscript['Declare Opportunity Lost']);
 		cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms);
 	}
-	if(!doc.__islocal) cur_frm.cscript.render_communication_list(doc, cdt, cdn);
 }
 
 // ONLOAD
@@ -48,7 +46,14 @@
 		}
 	} 
 
-	cur_frm.cscript.make_communication_body();
+	if(!doc.__islocal) {
+		cur_frm.communication_view = new wn.views.CommunicationList({
+			list: wn.model.get("Communication", {"opportunity": doc.name}),
+			parent: cur_frm.fields_dict.communication_html.wrapper,
+			doc: doc,
+			email: doc.contact_email
+		});
+	}
 	
 	if(cur_frm.fields_dict.contact_by.df.options.match(/^Profile/)) {
 		cur_frm.fields_dict.contact_by.get_query = erpnext.utils.profile_query;
diff --git a/selling/doctype/opportunity/opportunity.py b/selling/doctype/opportunity/opportunity.py
index 398418a..82a6e8e 100644
--- a/selling/doctype/opportunity/opportunity.py
+++ b/selling/doctype/opportunity/opportunity.py
@@ -14,25 +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/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import add_days, cstr, getdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.doc import Document, addchild
+from webnotes.model.wrapper import getlist
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
-
 from utilities.transaction_base import TransactionBase
 
 class DocType(TransactionBase):
@@ -42,8 +34,8 @@
 		self.fname = 'enq_details'
 		self.tname = 'Opportunity Item'
 
-	def autoname(self):
-		self.doc.name = make_autoname(self.doc.naming_series+'.####')
+	def onload(self):
+		self.add_communication_list()
 		
 	def get_item_details(self, item_code):
 		item = sql("""select item_name, stock_uom, description_html, description, item_group, brand
@@ -94,8 +86,8 @@
 		if self.doc.contact_date and self.doc.contact_date_ref != self.doc.contact_date:
 			if self.doc.contact_by:
 				self.add_calendar_event()
-			set(self.doc, 'contact_date_ref',self.doc.contact_date)
-		set(self.doc, 'status', 'Draft')
+			webnotes.conn.set(self.doc, 'contact_date_ref',self.doc.contact_date)
+		webnotes.conn.set(self.doc, 'status', 'Draft')
 
 	def add_calendar_event(self):
 		desc=''
@@ -169,7 +161,7 @@
 		self.validate_lead_cust()
 
 	def on_submit(self):
-		set(self.doc, 'status', 'Submitted')
+		webnotes.conn.set(self.doc, 'status', 'Submitted')
 	
 	def on_cancel(self):
 		chk = sql("select t1.name from `tabQuotation` t1, `tabQuotation Item` t2 where t2.parent = t1.name and t1.docstatus=1 and (t1.status!='Order Lost' and t1.status!='Cancelled') and t2.prevdoc_docname = %s",self.doc.name)
@@ -177,7 +169,7 @@
 			msgprint("Quotation No. "+cstr(chk[0][0])+" is submitted against this Opportunity. Thus can not be cancelled.")
 			raise Exception
 		else:
-			set(self.doc, 'status', 'Cancelled')
+			webnotes.conn.set(self.doc, 'status', 'Cancelled')
 		
 	def declare_enquiry_lost(self,arg):
 		chk = sql("select t1.name from `tabQuotation` t1, `tabQuotation Item` t2 where t2.parent = t1.name and t1.docstatus=1 and (t1.status!='Order Lost' and t1.status!='Cancelled') and t2.prevdoc_docname = %s",self.doc.name)
@@ -185,6 +177,6 @@
 			msgprint("Quotation No. "+cstr(chk[0][0])+" is submitted against this Opportunity. Thus 'Opportunity Lost' can not be declared against it.")
 			raise Exception
 		else:
-			set(self.doc, 'status', 'Opportunity Lost')
-			set(self.doc, 'order_lost_reason', arg)
+			webnotes.conn.set(self.doc, 'status', 'Opportunity Lost')
+			webnotes.conn.set(self.doc, 'order_lost_reason', arg)
 			return 'true'
diff --git a/selling/doctype/opportunity/opportunity.txt b/selling/doctype/opportunity/opportunity.txt
index f89a5d2..575cc10 100644
--- a/selling/doctype/opportunity/opportunity.txt
+++ b/selling/doctype/opportunity/opportunity.txt
@@ -2,12 +2,13 @@
  {
   "owner": "Administrator", 
   "docstatus": 0, 
-  "creation": "2012-11-28 11:26:19", 
+  "creation": "2012-11-24 17:21:44", 
   "modified_by": "Administrator", 
-  "modified": "2012-11-16 12:27:49"
+  "modified": "2012-11-30 10:54:00"
  }, 
  {
   "is_submittable": 1, 
+  "autoname": "naming_series:", 
   "name": "__common__", 
   "default_print_format": "Standard", 
   "search_fields": "status,transaction_date,customer,lead,enquiry_type,territory,company", 
@@ -35,6 +36,16 @@
   "doctype": "DocType"
  }, 
  {
+  "description": "Enter customer enquiry for which you might raise a quotation in future", 
+  "oldfieldtype": "Section Break", 
+  "colour": "White:FFF", 
+  "doctype": "DocField", 
+  "label": "Basic Info", 
+  "fieldname": "basic_info", 
+  "fieldtype": "Section Break", 
+  "permlevel": 0
+ }, 
+ {
   "description": "To manage multiple series please go to Setup > Manage Series", 
   "no_copy": 1, 
   "oldfieldtype": "Select", 
@@ -154,15 +165,14 @@
   "oldfieldtype": "Section Break", 
   "colour": "White:FFF", 
   "doctype": "DocField", 
-  "label": "Communication History", 
   "fieldname": "communication_history", 
   "fieldtype": "Section Break", 
   "permlevel": 0
  }, 
  {
-  "allow_on_submit": 1, 
   "oldfieldtype": "Table", 
   "colour": "White:FFF", 
+  "allow_on_submit": 1, 
   "doctype": "DocField", 
   "label": "Communication HTML", 
   "oldfieldname": "follow_up", 
diff --git a/selling/doctype/plot_control/plot_control.py b/selling/doctype/plot_control/plot_control.py
index 3bb751f..55d3730 100644
--- a/selling/doctype/plot_control/plot_control.py
+++ b/selling/doctype/plot_control/plot_control.py
@@ -14,24 +14,15 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cint, cstr, get_defaults, now
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/selling/doctype/quotation/quotation.js b/selling/doctype/quotation/quotation.js
index e629975..1b03781 100644
--- a/selling/doctype/quotation/quotation.js
+++ b/selling/doctype/quotation/quotation.js
@@ -24,8 +24,6 @@
 wn.require('app/selling/doctype/sales_common/sales_common.js');
 wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js');
 wn.require('app/utilities/doctype/sms_control/sms_control.js');
-wn.require('app/setup/doctype/notification_control/notification_control.js');
-wn.require('app/support/doctype/communication/communication.js');
 
 // ONLOAD
 // ===================================================================================
@@ -49,7 +47,7 @@
 			hide_field(['customer','customer_address','contact_person', 'customer_name','contact_display', 'customer_group']);
 		}
 	}
-	cur_frm.cscript.make_communication_body();
+	//cur_frm.cscript.make_communication_body();
 	
 	if(cur_frm.fields_dict.contact_by.df.options.match(/^Profile/)) {
 		cur_frm.fields_dict.contact_by.get_query = erpnext.utils.profile_query;
@@ -104,7 +102,14 @@
 	if(doc.customer || doc.lead) $(cur_frm.fields_dict.contact_section.row.wrapper).toggle(true);
 	else $(cur_frm.fields_dict.contact_section.row.wrapper).toggle(false);
 	
-	if (!doc.__islocal) cur_frm.cscript.render_communication_list(doc, cdt, cdn);
+	if (!doc.__islocal) {
+		cur_frm.communication_view = new wn.views.CommunicationList({
+			list: wn.model.get("Communication", {"quotation": doc.name}),
+			parent: cur_frm.fields_dict.communication_html.wrapper,
+			doc: doc,
+			email: doc.contact_email
+		});		
+	}
 }
 
 
@@ -333,9 +338,7 @@
 }
 
 cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
-	var args = {
-		type: 'Quotation',
-		doctype: 'Quotation'
+	if(cint(wn.boot.notification_settings.quotation)) {
+		cur_frm.email_doc(wn.boot.notification_settings.quotation_message);
 	}
-	cur_frm.cscript.notify(doc, args);
 }
\ No newline at end of file
diff --git a/selling/doctype/quotation/quotation.py b/selling/doctype/quotation/quotation.py
index 76b1ef6..3a547a0 100644
--- a/selling/doctype/quotation/quotation.py
+++ b/selling/doctype/quotation/quotation.py
@@ -14,24 +14,18 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, load_json
+from webnotes.utils import cstr, load_json
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren
+from webnotes.model.doc import Document, addchild
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 from utilities.transaction_base import TransactionBase
 
@@ -41,7 +35,10 @@
 		self.doclist = doclist
 		self.tname = 'Quotation Item'
 		self.fname = 'quotation_details'
- 
+
+	def onload(self):
+		self.add_communication_list()
+		 
 	# Pull Opportunity Details
 	# --------------------
 	def pull_enq_details(self):
diff --git a/selling/doctype/sales_common/sales_common.py b/selling/doctype/sales_common/sales_common.py
index 8ea4fe4..7f6ffe6 100644
--- a/selling/doctype/sales_common/sales_common.py
+++ b/selling/doctype/sales_common/sales_common.py
@@ -14,22 +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/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import add_days, cint, cstr, default_fields, flt, getdate, now, nowdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
+from webnotes.model.doc import addchild
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.code import get_obj
+from webnotes import form, msgprint
 
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 from utilities.transaction_base import TransactionBase
 
diff --git a/selling/doctype/sales_order/sales_order.js b/selling/doctype/sales_order/sales_order.js
index f720cfa..6a3dfc4 100644
--- a/selling/doctype/sales_order/sales_order.js
+++ b/selling/doctype/sales_order/sales_order.js
@@ -25,7 +25,6 @@
 wn.require('app/selling/doctype/sales_common/sales_common.js');
 wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js');
 wn.require('app/utilities/doctype/sms_control/sms_control.js');
-wn.require('app/setup/doctype/notification_control/notification_control.js');
 
 
 // ONLOAD
@@ -369,9 +368,7 @@
 }
 
 cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
-	var args = {
-		type: 'Sales Order',
-		doctype: 'Sales Order'
+	if(cint(wn.boot.notification_settings.sales_order)) {
+		cur_frm.email_doc(wn.boot.notification_settings.sales_order);
 	}
-	cur_frm.cscript.notify(doc, args);
 }
diff --git a/selling/doctype/sales_order/sales_order.py b/selling/doctype/sales_order/sales_order.py
index a79c847..410a6e1 100644
--- a/selling/doctype/sales_order/sales_order.py
+++ b/selling/doctype/sales_order/sales_order.py
@@ -14,24 +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/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr, date_diff, flt, getdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 from utilities.transaction_base import TransactionBase
 
@@ -337,9 +330,7 @@
 						
 						#update enquiry
 						self.update_enquiry_status(d.prevdoc_docname, 'Quotation Sent')
-	
-	# Submit
-	# -------
+
 	def on_submit(self):
 		self.check_prev_docstatus()		
 		self.update_stock_ledger(update_stock = 1)
@@ -347,17 +338,11 @@
 		update_customer = sql("update `tabCustomer` set last_sales_order = '%s', modified = '%s' where name = '%s'" %(self.doc.name, self.doc.modified, self.doc.customer))
 		get_obj('Sales Common').check_credit(self,self.doc.grand_total)
 		
-		# Check for Approving Authority
 		get_obj('Authorization Control').validate_approving_authority(self.doc.doctype, self.doc.grand_total, self)
 		
-		#update prevdoc status
 		self.update_prevdoc_status('submit')
-		# set SO status
 		set(self.doc, 'status', 'Submitted')
 	
- 
-# ON CANCEL
-# ===============================================================================================
 	def on_cancel(self):
 		# Cannot cancel stopped SO
 		if self.doc.status == 'Stopped':
@@ -366,13 +351,10 @@
 		self.check_nextdoc_docstatus()
 		self.update_stock_ledger(update_stock = -1)
 		
-		#update prevdoc status
 		self.update_prevdoc_status('cancel')
 		
-		# ::::::::: SET SO STATUS ::::::::::
 		set(self.doc, 'status', 'Cancelled')
 		
-	# CHECK NEXT DOCSTATUS
 	# does not allow to cancel document if DN or RV made against it is SUBMITTED 
 	# ----------------------------------------------------------------------------
 	def check_nextdoc_docstatus(self):
@@ -380,18 +362,28 @@
 		submit_dn = sql("select t1.name from `tabDelivery Note` t1,`tabDelivery Note Item` t2 where t1.name = t2.parent and t2.prevdoc_docname = '%s' and t1.docstatus = 1" % (self.doc.name))
 		if submit_dn:
 			msgprint("Delivery Note : " + cstr(submit_dn[0][0]) + " has been submitted against " + cstr(self.doc.doctype) + ". Please cancel Delivery Note : " + cstr(submit_dn[0][0]) + " first and then cancel "+ cstr(self.doc.doctype), raise_exception = 1)
+			
 		# Checks Sales Invoice
 		submit_rv = sql("select t1.name from `tabSales Invoice` t1,`tabSales Invoice Item` t2 where t1.name = t2.parent and t2.sales_order = '%s' and t1.docstatus = 1" % (self.doc.name))
 		if submit_rv:
 			msgprint("Sales Invoice : " + cstr(submit_rv[0][0]) + " has already been submitted against " +cstr(self.doc.doctype)+ ". Please cancel Sales Invoice : "+ cstr(submit_rv[0][0]) + " first and then cancel "+ cstr(self.doc.doctype), raise_exception = 1)
+			
 		#check maintenance schedule
 		submit_ms = sql("select t1.name from `tabMaintenance Schedule` t1, `tabMaintenance Schedule Item` t2 where t2.parent=t1.name and t2.prevdoc_docname = %s and t1.docstatus = 1",self.doc.name)
 		if submit_ms:
 			msgprint("Maintenance Schedule : " + cstr(submit_ms[0][0]) + " has already been submitted against " +cstr(self.doc.doctype)+ ". Please cancel Maintenance Schedule : "+ cstr(submit_ms[0][0]) + " first and then cancel "+ cstr(self.doc.doctype), raise_exception = 1)
+			
+		# check maintenance visit
 		submit_mv = sql("select t1.name from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2 where t2.parent=t1.name and t2.prevdoc_docname = %s and t1.docstatus = 1",self.doc.name)
 		if submit_mv:
 			msgprint("Maintenance Visit : " + cstr(submit_mv[0][0]) + " has already been submitted against " +cstr(self.doc.doctype)+ ". Please cancel Maintenance Visit : " + cstr(submit_mv[0][0]) + " first and then cancel "+ cstr(self.doc.doctype), raise_exception = 1)
-
+		
+		# check production order
+		pro_order = sql("""select name from `tabProduction Order` where sales_order = %s and docstatus = 1""", self.doc.name)
+		if pro_order:
+			msgprint("""Production Order: %s exists against this sales order. 
+				Please cancel production order first and then cancel this sales order""" % 
+				pro_order[0][0], raise_exception=1)
 
 	def check_modified_date(self):
 		mod_db = sql("select modified from `tabSales Order` where name = '%s'" % self.doc.name)
diff --git a/selling/doctype/sms_center/sms_center.py b/selling/doctype/sms_center/sms_center.py
index afc3a20..416b1ec 100644
--- a/selling/doctype/sms_center/sms_center.py
+++ b/selling/doctype/sms_center/sms_center.py
@@ -14,24 +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/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 # ----------
 
 class DocType:
diff --git a/setup/doctype/authorization_control/authorization_control.py b/setup/doctype/authorization_control/authorization_control.py
index a9aab67..360a4d0 100644
--- a/setup/doctype/authorization_control/authorization_control.py
+++ b/setup/doctype/authorization_control/authorization_control.py
@@ -14,24 +14,16 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add, make_esc
+from webnotes.utils import cstr, flt, has_common, make_esc
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes import session, msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 from utilities.transaction_base import TransactionBase
 
 class DocType(TransactionBase):
diff --git a/setup/doctype/authorization_rule/authorization_rule.py b/setup/doctype/authorization_rule/authorization_rule.py
index dc18143..a3646c0 100644
--- a/setup/doctype/authorization_rule/authorization_rule.py
+++ b/setup/doctype/authorization_rule/authorization_rule.py
@@ -14,24 +14,16 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cint, cstr, flt, has_common
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/setup/doctype/company/company.py b/setup/doctype/company/company.py
index ebf3eae..83c9f83 100644
--- a/setup/doctype/company/company.py
+++ b/setup/doctype/company/company.py
@@ -14,22 +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/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr, get_defaults, set_default
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.doc import Document
+from webnotes.model.wrapper import copy_doclist
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 
 class DocType:
 	def __init__(self,d,dl):
diff --git a/setup/doctype/contact_control/contact_control.py b/setup/doctype/contact_control/contact_control.py
index b89eced..ed90b99 100644
--- a/setup/doctype/contact_control/contact_control.py
+++ b/setup/doctype/contact_control/contact_control.py
@@ -2,20 +2,15 @@
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import set_default
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.doc import Document
+from webnotes.model.wrapper import copy_doclist
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/setup/doctype/customer_group/customer_group.py b/setup/doctype/customer_group/customer_group.py
index 2bcb511..0f68521 100644
--- a/setup/doctype/customer_group/customer_group.py
+++ b/setup/doctype/customer_group/customer_group.py
@@ -14,24 +14,15 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 from webnotes.utils.nestedset import DocTypeNestedSet
 class DocType(DocTypeNestedSet):
 	def __init__(self, doc, doclist=[]):
diff --git a/setup/doctype/email_settings/email_settings.py b/setup/doctype/email_settings/email_settings.py
index e17f55c..b9880d2 100644
--- a/setup/doctype/email_settings/email_settings.py
+++ b/setup/doctype/email_settings/email_settings.py
@@ -18,7 +18,7 @@
 import webnotes
 sql = webnotes.conn.sql
 	
-from webnotes.utils import cint, cstr
+from webnotes.utils import cint
 
 class DocType:
 	def __init__(self,doc,doclist):
diff --git a/setup/doctype/item_group/item_group.py b/setup/doctype/item_group/item_group.py
index 17e10bb..2cec30d 100644
--- a/setup/doctype/item_group/item_group.py
+++ b/setup/doctype/item_group/item_group.py
@@ -17,8 +17,6 @@
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.model.wrapper import getlist
-from webnotes.utils import flt
 
 from webnotes.utils.nestedset import DocTypeNestedSet
 
diff --git a/setup/doctype/naming_series/naming_series.py b/setup/doctype/naming_series/naming_series.py
index 689b409..a259c84 100644
--- a/setup/doctype/naming_series/naming_series.py
+++ b/setup/doctype/naming_series/naming_series.py
@@ -17,8 +17,8 @@
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import cint, cstr
-from webnotes import msgprint, errprint
+from webnotes.utils import cstr
+from webnotes import msgprint
 import webnotes.model.doctype
 
 sql = webnotes.conn.sql
@@ -90,8 +90,7 @@
 
 		self.doc.set_options = "\n".join(options)
 
-		from webnotes.utils.cache import CacheItem
-		CacheItem(doctype).clear()
+		webnotes.clear_cache(doctype=doctype)
 			
 	def check_duplicate(self):
 		from core.doctype.doctype.doctype import DocType
diff --git a/setup/doctype/notification_control/notification_control.js b/setup/doctype/notification_control/notification_control.js
index b52520a..619d417 100644
--- a/setup/doctype/notification_control/notification_control.js
+++ b/setup/doctype/notification_control/notification_control.js
@@ -22,45 +22,5 @@
       refresh_field('custom_message');
     }
     $c_obj(make_doclist(cdt, cdn),'get_message',doc.select_transaction, callback)
-}
-}
-
-cur_frm.cscript.notify = function(doc, args) {
-	var doc = locals[doc.doctype][doc.name];
-	$c_obj(make_doclist(doc.doctype, doc.name), 'get_formatted_message', {
-		type: args['type'],
-		doctype: args['doctype'],
-		contact_name: args['contact_name'] || doc.contact_display
-	}, function(r, rt) {
-		if(!r.exc) {
-			var res = JSON.parse(r.message);
-			var send_from = (function() {
-				if(user!='Administrator') {
-					return user;
-				} else {
-					return (wn.control_panel.auto_email_id || 
-						'ERPNext Notification<automail@erpnext.com>');
-				}
-			})();
-			if(res.send) {
-				var print_heading = (doc.select_print_heading || args['type'])
-				if(validate_email(args['send_to'] || doc.contact_email || '')) {
-					sendmail(
-						args['send_to'] || doc.contact_email,
-						send_from,
-						send_from,
-						doc.company + " - " + print_heading + " - " + doc.name,
-						res.message,
-						res.print_format
-					);
-					msgprint('This ' + print_heading + ' is being sent to <b>'
-						+ (args['send_to'] || doc.contact_email) + '</b><br />...');
-				} else {
-					msgprint('Invalid/Missing Email Address of Contact. Auto notification for ' 
-						+ print_heading + ' not sent.');
-				}
-			}
-		}
-		//console.log(JSON.parse(r.message));
-	});
+  }
 }
diff --git a/setup/doctype/notification_control/notification_control.py b/setup/doctype/notification_control/notification_control.py
index f8b0ee2..d6792f9 100644
--- a/setup/doctype/notification_control/notification_control.py
+++ b/setup/doctype/notification_control/notification_control.py
@@ -14,95 +14,24 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import validate_email_add, cint, cstr
-from webnotes.model.doc import Document
-from webnotes.model.code import get_obj
 from webnotes import msgprint
 
 sql = webnotes.conn.sql
 
-# -----------------------------------------------------------------------------------------
-# Notification control
 class DocType:
 	def __init__(self,d,dl):
 		self.doc, self.doclist = d,dl
 
-	# get message to load in custom text
-	# ----------------------------------
 	def get_message(self, arg):
 		fn = arg.lower().replace(' ', '_') + '_message'
 		v = sql("select value from tabSingles where field=%s and doctype=%s", (fn, 'Notification Control'))
 		return v and v[0][0] or ''
 
-	# set custom text
-	# ---------------
 	def set_message(self, arg = ''):
 		fn = self.doc.select_transaction.lower().replace(' ', '_') + '_message'
 		webnotes.conn.set(self.doc, fn, self.doc.custom_message)
 		msgprint("Custom Message for %s updated!" % self.doc.select_transaction)
 
-	
-	def get_formatted_message(self, args):
-		"""
-			args can contain:
-				* type
-				* doctype
-				* contact_name
-		"""
-		import json
-		args = json.loads(args)
-		res = {
-			'send': 0,
-			'message': self.prepare_message(args),
-			'print_format': self.get_default_print_format(args)
-		}
-
-		dt_small = args.get('doctype').replace(' ', '_').lower()
-		if cint(self.doc.fields.get(dt_small)):
-			res['send'] = 1
-
-		return json.dumps(res)
-
-
-	def prepare_message(self, args):
-		"""
-			Prepares message body
-		"""
-		if args.get('type'):
-			msg_dict = {}
-			msg_dict['message'] = args.get('message') or self.get_message(args.get('type'))
-			msg_dict['company'] = Document('Control Panel', 'Control Panel').company_name
-			msg_dict['salutation'] = "Hi" + (args.get('contact_name') and (" " + args.get('contact_name')) or "")
-			msg_dict['send_from'] = webnotes.conn.sql("""\
-				SELECT CONCAT_WS(' ', first_name, last_name)
-				FROM `tabProfile`
-				WHERE name = %s""", webnotes.session['user'], as_list=1)[0][0] or ''
-			
-			return """\
-				<div>
-					%(salutation)s,
-
-					%(message)s
-					
-					Thanks,
-					%(send_from)s
-					%(company)s
-				</div>""" % msg_dict
-
-		else: return ""
-
-
-	def get_default_print_format(self, args):
-		"""
-			Get default print format from doclayer
-		"""
-		doclayer = get_obj('Customize Form', 'Customize Form')
-		doclayer.doc.doc_type = args.get('doctype')
-		doclayer.get()
-		if doclayer.doc.default_print_format:
-			return doclayer.doc.default_print_format
-		else: return 'Standard'
diff --git a/setup/doctype/permission_control/permission_control.py b/setup/doctype/permission_control/permission_control.py
index 32efe03..8162c39 100644
--- a/setup/doctype/permission_control/permission_control.py
+++ b/setup/doctype/permission_control/permission_control.py
@@ -14,25 +14,16 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cint, cstr, get_defaults, now
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.doc import Document
+from webnotes.model.wrapper import copy_doclist
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
-	
-# -----------------------------------------------------------------------------------------
-
 
 class DocType:
 	def __init__(self, doc, doclist):
@@ -60,7 +51,7 @@
 	# -------------------------------------------------------------------
 	def get_permissions(self,doctype):
 		import webnotes.model.doctype
-		doclist = webnotes.model.doctype.get(doctype, form=0)
+		doclist = webnotes.model.doctype.get(doctype)
 		
 		ptype = [{
 				'role': perm.role,
@@ -195,8 +186,7 @@
 						sql("update tabDocType set modified = %s where name = %s",(now(), parent))
 
 
-		from webnotes.utils.cache import CacheItem
-		CacheItem(parent).clear()		
+		webnotes.clear_cache(doctype=parent)
 
 		msgprint("Permissions Updated")
 				
diff --git a/setup/doctype/print_heading/print_heading.py b/setup/doctype/print_heading/print_heading.py
index 171a152..87d21d7 100644
--- a/setup/doctype/print_heading/print_heading.py
+++ b/setup/doctype/print_heading/print_heading.py
@@ -14,24 +14,14 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/setup/doctype/sales_browser_control/sales_browser_control.py b/setup/doctype/sales_browser_control/sales_browser_control.py
index 5eec24e..331fe78 100644
--- a/setup/doctype/sales_browser_control/sales_browser_control.py
+++ b/setup/doctype/sales_browser_control/sales_browser_control.py
@@ -14,24 +14,18 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.doc import Document
+from webnotes.model.wrapper import copy_doclist
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/setup/doctype/sales_partner/sales_partner.py b/setup/doctype/sales_partner/sales_partner.py
index 5bccd31..f332196 100644
--- a/setup/doctype/sales_partner/sales_partner.py
+++ b/setup/doctype/sales_partner/sales_partner.py
@@ -14,24 +14,14 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/setup/doctype/sales_person/sales_person.py b/setup/doctype/sales_person/sales_person.py
index bf16a0f..41d5042 100644
--- a/setup/doctype/sales_person/sales_person.py
+++ b/setup/doctype/sales_person/sales_person.py
@@ -14,7 +14,6 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
diff --git a/setup/doctype/setup_control/setup_control.py b/setup/doctype/setup_control/setup_control.py
index a71fde9..3d7e11c 100644
--- a/setup/doctype/setup_control/setup_control.py
+++ b/setup/doctype/setup_control/setup_control.py
@@ -17,7 +17,7 @@
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import cint, cstr, flt, getdate, now, nowdate
+from webnotes.utils import cint, cstr, getdate, now, nowdate
 from webnotes.model.doc import Document, addchild
 from webnotes.model.code import get_obj
 from webnotes import session, form, msgprint
diff --git a/setup/doctype/territory/territory.py b/setup/doctype/territory/territory.py
index 284bd26..59c0b3a 100644
--- a/setup/doctype/territory/territory.py
+++ b/setup/doctype/territory/territory.py
@@ -14,7 +14,6 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.	If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
diff --git a/setup/doctype/workflow_engine/workflow_engine.py b/setup/doctype/workflow_engine/workflow_engine.py
index 82c2c70..f9e2cef 100644
--- a/setup/doctype/workflow_engine/workflow_engine.py
+++ b/setup/doctype/workflow_engine/workflow_engine.py
@@ -14,24 +14,16 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.code import get_obj
+from webnotes import form, msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/setup/doctype/workflow_rule/workflow_rule.py b/setup/doctype/workflow_rule/workflow_rule.py
index 571adc4..24b2add 100644
--- a/setup/doctype/workflow_rule/workflow_rule.py
+++ b/setup/doctype/workflow_rule/workflow_rule.py
@@ -14,24 +14,16 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes import form, msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/startup/event_handlers.py b/startup/event_handlers.py
index 7d1f584..9cd1af9 100644
--- a/startup/event_handlers.py
+++ b/startup/event_handlers.py
@@ -16,7 +16,6 @@
 
 from __future__ import unicode_literals
 import webnotes
-from webnotes.utils import cint
 import home
 
 		
@@ -76,6 +75,8 @@
 		import webnotes.model.doctype
 		bootinfo['docs'] += webnotes.model.doctype.get('Event')
 		bootinfo['docs'] += webnotes.model.doctype.get('Search Criteria')
+		bootinfo['notification_settings'] = webnotes.doc("Notification Control", 
+			"Notification Control").get_values()
 		
 		bootinfo['modules_list'] = webnotes.conn.get_global('modules_list')
 		
diff --git a/startup/schedule_handlers.py b/startup/schedule_handlers.py
index f3eb05a..668c11d 100644
--- a/startup/schedule_handlers.py
+++ b/startup/schedule_handlers.py
@@ -39,7 +39,7 @@
 	run_fn(send)
 
 	# run recurring invoices
-	from accounts.doctype.gl_control.gl_control import manage_recurring_invoices
+	from accounts.doctype.sales_invoice.sales_invoice import manage_recurring_invoices
 	run_fn(manage_recurring_invoices)
 
 	# send bulk emails
diff --git a/stock/doctype/bin/bin.py b/stock/doctype/bin/bin.py
index 039dd75..5e3e74a 100644
--- a/stock/doctype/bin/bin.py
+++ b/stock/doctype/bin/bin.py
@@ -14,16 +14,15 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import add_days, cint, cstr, flt, get_defaults, now, nowdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import msgprint, errprint
+from webnotes.model.doc import Document, addchild
+from webnotes.model.wrapper import copy_doclist
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 sql = webnotes.conn.sql
 
 
diff --git a/stock/doctype/delivery_note/delivery_note.js b/stock/doctype/delivery_note/delivery_note.js
index 4a3910a..6295811 100644
--- a/stock/doctype/delivery_note/delivery_note.js
+++ b/stock/doctype/delivery_note/delivery_note.js
@@ -23,7 +23,6 @@
 wn.require('app/selling/doctype/sales_common/sales_common.js');
 wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js');
 wn.require('app/utilities/doctype/sms_control/sms_control.js');
-wn.require('app/setup/doctype/notification_control/notification_control.js');
 
 // ONLOAD
 // ================================================================================================
@@ -327,9 +326,7 @@
 }
 
 cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
-	var args = {
-		type: 'Delivery Note',
-		doctype: 'Delivery Note'
+	if(cint(wn.boot.notification_settings.delivery_note)) {
+		cur_frm.email_doc(wn.boot.notification_settings.delivery_note);
 	}
-	cur_frm.cscript.notify(doc, args);
 }
\ No newline at end of file
diff --git a/stock/doctype/delivery_note/delivery_note.py b/stock/doctype/delivery_note/delivery_note.py
index e5aa909..5b756cf 100644
--- a/stock/doctype/delivery_note/delivery_note.py
+++ b/stock/doctype/delivery_note/delivery_note.py
@@ -14,24 +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/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr, flt, getdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 
-# -----------------------------------------------------------------------------------------
 
 from utilities.transaction_base import TransactionBase
 
diff --git a/stock/doctype/item/item.py b/stock/doctype/item/item.py
index c906e47..92dc82b 100644
--- a/stock/doctype/item/item.py
+++ b/stock/doctype/item/item.py
@@ -14,24 +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/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr, flt
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
+from webnotes.model.doc import addchild
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/stock/doctype/item/test_item.py b/stock/doctype/item/test_item.py
index 66adb83..f7876a6 100644
--- a/stock/doctype/item/test_item.py
+++ b/stock/doctype/item/test_item.py
@@ -21,7 +21,6 @@
 
 from webnotes.model.wrapper import ModelWrapper
 from webnotes.model.doc import Document
-from webnotes.model.code import get_obj
 from webnotes.utils import flt
 
 sql = webnotes.conn.sql
diff --git a/stock/doctype/landed_cost_wizard/landed_cost_wizard.py b/stock/doctype/landed_cost_wizard/landed_cost_wizard.py
index eb8fd8f..4e8015d 100644
--- a/stock/doctype/landed_cost_wizard/landed_cost_wizard.py
+++ b/stock/doctype/landed_cost_wizard/landed_cost_wizard.py
@@ -17,14 +17,13 @@
 from __future__ import unicode_literals
 import webnotes
 from webnotes.utils import cint, cstr, flt
-from webnotes.model.doc import addchild, getchildren
+from webnotes.model.doc import addchild
 from webnotes.model.wrapper import getlist
 from webnotes.model.code import get_obj
 from webnotes import msgprint
 
 sql = webnotes.conn.sql
 
-# -----------------------------------------------------------------------------------------
 
 class DocType:
 	def __init__(self, doc, doclist=[]):
diff --git a/stock/doctype/purchase_receipt/purchase_receipt.js b/stock/doctype/purchase_receipt/purchase_receipt.js
index b943314..0ab6681 100644
--- a/stock/doctype/purchase_receipt/purchase_receipt.js
+++ b/stock/doctype/purchase_receipt/purchase_receipt.js
@@ -21,7 +21,6 @@
 wn.require('app/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js');
 wn.require('app/buying/doctype/purchase_common/purchase_common.js');
 wn.require('app/utilities/doctype/sms_control/sms_control.js');
-wn.require('app/setup/doctype/notification_control/notification_control.js');
 
 //========================== On Load ================================================================
 cur_frm.cscript.onload = function(doc, cdt, cdn) {
@@ -311,9 +310,7 @@
 }
 
 cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
-	var args = {
-		type: 'Purchase Receipt',
-		doctype: 'Purchase Receipt'
+	if(cint(wn.boot.notification_settings.purchase_receipt)) {
+		cur_frm.email_doc(wn.boot.notification_settings.purchase_receipt);
 	}
-	cur_frm.cscript.notify(doc, args);
 }
diff --git a/stock/doctype/purchase_receipt/purchase_receipt.py b/stock/doctype/purchase_receipt/purchase_receipt.py
index 51b7272..84cf47b 100644
--- a/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -14,24 +14,18 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr, flt, get_defaults, getdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
+from webnotes.model.doc import addchild, make_autoname
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 
-# -----------------------------------------------------------------------------------------
 
 from utilities.transaction_base import TransactionBase
 
diff --git a/stock/doctype/sales_and_purchase_return_tool/sales_and_purchase_return_tool.py b/stock/doctype/sales_and_purchase_return_tool/sales_and_purchase_return_tool.py
index c55bf03..92fa63e 100644
--- a/stock/doctype/sales_and_purchase_return_tool/sales_and_purchase_return_tool.py
+++ b/stock/doctype/sales_and_purchase_return_tool/sales_and_purchase_return_tool.py
@@ -14,24 +14,16 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import flt
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.doc import addchild
+from webnotes.model.wrapper import copy_doclist
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 class DocType :
   def __init__(self, doc, doclist=[]):
diff --git a/stock/doctype/serial_no/serial_no.py b/stock/doctype/serial_no/serial_no.py
index 63b23ca..b6f60f5 100644
--- a/stock/doctype/serial_no/serial_no.py
+++ b/stock/doctype/serial_no/serial_no.py
@@ -14,17 +14,15 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import cint, flt, cstr, getdate, nowdate
+from webnotes.utils import cint, getdate, nowdate
 import datetime
 
 sql = webnotes.conn.sql
 msgprint = webnotes.msgprint
 	
-# -----------------------------------------------------------------------------------------
 
 from utilities.transaction_base import TransactionBase
 
diff --git a/stock/doctype/stock_entry/stock_entry.py b/stock/doctype/stock_entry/stock_entry.py
index cc3acfe..29f58bc 100644
--- a/stock/doctype/stock_entry/stock_entry.py
+++ b/stock/doctype/stock_entry/stock_entry.py
@@ -14,24 +14,18 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr, flt, getdate, now
 from webnotes.model import db_exists, delete_doc
-from webnotes.model.doc import Document, addchild, getchildren
+from webnotes.model.doc import Document, addchild
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 from utilities.transaction_base import TransactionBase
 
 class DocType(TransactionBase):
@@ -154,25 +148,13 @@
 
 
 
-	def get_raw_materials(self, bom_no, fg_qty, consider_sa_items_as_rm):
+	def get_raw_materials(self, bom_no, fg_qty, use_multi_level_bom):
 		""" 
 			get all items from flat bom except 
 			child items of sub-contracted and sub assembly items 
 			and sub assembly items itself.
 		"""
-		if consider_sa_items_as_rm == 'Yes':
-			# Get all raw materials considering SA items as raw materials, 
-			# so no childs of SA items
-			fl_bom_sa_items = sql("""
-				select item_code, ifnull(sum(qty_consumed_per_unit), 0) * '%s', description, stock_uom 
-				from `tabBOM Item` 
-				where parent = '%s' and docstatus < 2 
-				group by item_code
-			""" % (fg_qty, bom_no))
-			
-			self.make_items_dict(fl_bom_sa_items)
-
-		else:
+		if use_multi_level_bom:
 			# get all raw materials with sub assembly childs					
 			fl_bom_sa_child_item = sql("""
 				select 
@@ -187,6 +169,17 @@
 				group by item_code,stock_uom
 			""" , (fg_qty, bom_no))
 			self.make_items_dict(fl_bom_sa_child_item)
+		else:
+			# Get all raw materials considering multi level BOM, 
+			# if multi level bom consider childs of Sub-Assembly items
+			fl_bom_sa_items = sql("""
+				select item_code, ifnull(sum(qty_consumed_per_unit), 0) * '%s', description, stock_uom 
+				from `tabBOM Item` 
+				where parent = '%s' and docstatus < 2 
+				group by item_code
+			""" % (fg_qty, bom_no))
+			
+			self.make_items_dict(fl_bom_sa_items)
 
 		# Update only qty remaining to be issued for production
 		if self.doc.process == 'Material Transfer':
@@ -214,12 +207,8 @@
 		if self.doc.bom_no:
 			if not self.doc.fg_completed_qty:
 				msgprint("Please enter FG Completed Qty", raise_exception=1)
-			if not self.doc.consider_sa_items_as_raw_materials:
-				msgprint("Please confirm whether you want to consider sub assembly item as raw materials", raise_exception=1)	
 
 
-	# get items 
-	#------------------
 	def get_items(self):
 		if self.doc.purpose == 'Production Order':
 			pro_obj = self.doc.production_order and get_obj('Production Order', self.doc.production_order) or ''	
@@ -227,14 +216,14 @@
 
 			bom_no = pro_obj.doc.bom_no
 			fg_qty = (self.doc.process == 'Backflush') and flt(self.doc.fg_completed_qty) or flt(pro_obj.doc.qty)
-			consider_sa_items_as_rm = pro_obj.doc.consider_sa_items
+			use_multi_level_bom = pro_obj.doc.use_multi_level_bom
 		elif self.doc.purpose == 'Other':
 			self.validate_bom_no()
 			bom_no = self.doc.bom_no
 			fg_qty = self.doc.fg_completed_qty
-			consider_sa_items_as_rm = self.doc.consider_sa_items_as_raw_materials
+			use_multi_level_bom = self.doc.use_multi_level_bom
 			
-		self.get_raw_materials(bom_no, fg_qty, consider_sa_items_as_rm)
+		self.get_raw_materials(bom_no, fg_qty, use_multi_level_bom)
 		self.doclist = self.doc.clear_table(self.doclist, 'mtn_details', 1)
 
 		sw = (self.doc.process == 'Backflush') and cstr(pro_obj.doc.wip_warehouse) or ''
diff --git a/stock/doctype/stock_entry/stock_entry.txt b/stock/doctype/stock_entry/stock_entry.txt
index f77808e..24412b8 100644
--- a/stock/doctype/stock_entry/stock_entry.txt
+++ b/stock/doctype/stock_entry/stock_entry.txt
@@ -2,9 +2,9 @@
  {
   "owner": "Administrator", 
   "docstatus": 0, 
-  "creation": "2012-11-02 17:16:56", 
+  "creation": "2012-11-28 11:26:22", 
   "modified_by": "Administrator", 
-  "modified": "2012-11-26 11:51:08"
+  "modified": "2012-11-30 14:10:02"
  }, 
  {
   "is_submittable": 1, 
@@ -195,14 +195,13 @@
   "permlevel": 0
  }, 
  {
-  "description": "Select \"Yes\" if stock is maintained and tracked for sub-assembly items. Select \"No\" if you want child items of sub-assembly for material transfer.", 
+  "description": "If checked, BOM for sub-assembly items will be considered for getting raw materials. Otherwise, all sub-assembly items will be treated as a raw material.", 
   "depends_on": "eval:doc.purpose == 'Other'", 
   "colour": "White:FFF", 
   "doctype": "DocField", 
-  "label": "Consider SA Items as Raw Materials", 
-  "options": "\nNo\nYes", 
-  "fieldname": "consider_sa_items_as_raw_materials", 
-  "fieldtype": "Select", 
+  "label": "Use Multi-Level BOM", 
+  "fieldname": "use_multi_level_bom", 
+  "fieldtype": "Check", 
   "permlevel": 0
  }, 
  {
diff --git a/stock/doctype/stock_ledger/stock_ledger.py b/stock/doctype/stock_ledger/stock_ledger.py
index 5deecdd..3235c32 100644
--- a/stock/doctype/stock_ledger/stock_ledger.py
+++ b/stock/doctype/stock_ledger/stock_ledger.py
@@ -14,24 +14,18 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import add_days, cstr, flt, now, nowdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
+from webnotes.model.doc import Document
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.code import get_obj
+from webnotes import session, msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 
-# -----------------------------------------------------------------------------------------
 
 def get_sr_no_list(sr_nos, qty = 0, item_code = ''):
 	serial_nos = cstr(sr_nos).strip().replace(',', '\n').split('\n')
diff --git a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
index 645b7c9..3214435 100644
--- a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
+++ b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
@@ -14,17 +14,14 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
 from webnotes.utils import cstr, cint, flt, cstr, getdate
 
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
 msgprint = webnotes.msgprint
 
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/stock/doctype/stock_reconciliation/stock_reconciliation.py b/stock/doctype/stock_reconciliation/stock_reconciliation.py
index 9a806f6..7df4b16 100644
--- a/stock/doctype/stock_reconciliation/stock_reconciliation.py
+++ b/stock/doctype/stock_reconciliation/stock_reconciliation.py
@@ -17,11 +17,10 @@
 from __future__ import unicode_literals
 import webnotes
 from webnotes.utils import cstr, flt, get_defaults, nowdate, formatdate
-from webnotes import msgprint, errprint
+from webnotes import msgprint
 from webnotes.model.code import get_obj
 sql = webnotes.conn.sql
 	
-# -----------------------------------------------------------------------------------------
 
 class DocType:
 	def __init__(self, doc, doclist=[]):
diff --git a/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py b/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py
index 0d73634..a02afe9 100644
--- a/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py
+++ b/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py
@@ -14,24 +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/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr, flt, now
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/stock/doctype/valuation_control/valuation_control.py b/stock/doctype/valuation_control/valuation_control.py
index 1318db6..3953f53 100644
--- a/stock/doctype/valuation_control/valuation_control.py
+++ b/stock/doctype/valuation_control/valuation_control.py
@@ -14,7 +14,6 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes, unittest
 
diff --git a/stock/doctype/warehouse/warehouse.py b/stock/doctype/warehouse/warehouse.py
index 5f1a63d..38ba387 100644
--- a/stock/doctype/warehouse/warehouse.py
+++ b/stock/doctype/warehouse/warehouse.py
@@ -14,15 +14,13 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, flt, get_defaults, getdate, has_common, month_name, now, nowdate, set_default, validate_email_add
-from webnotes.model.doc import Document, addchild, getchildren
-from webnotes.model.wrapper import getlist
+from webnotes.utils import cstr, flt, validate_email_add
+from webnotes.model.doc import Document
 from webnotes.model.code import get_obj
-from webnotes import msgprint, errprint
+from webnotes import msgprint
 
 sql = webnotes.conn.sql
 
diff --git a/support/doctype/communication/__init__.py b/support/doctype/communication/__init__.py
deleted file mode 100644
index baffc48..0000000
--- a/support/doctype/communication/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-from __future__ import unicode_literals
diff --git a/support/doctype/communication/communication.js b/support/doctype/communication/communication.js
deleted file mode 100644
index 04e6c80..0000000
--- a/support/doctype/communication/communication.js
+++ /dev/null
@@ -1,142 +0,0 @@
-cur_frm.cscript.onload = function(doc) {
-	cur_frm.fields_dict.user.get_query = function() {
-		return "select name, concat_ws(' ', first_name, middle_name, last_name) \
-			from `tabProfile` where ifnull(enabled, 0)=1 and docstatus < 2 and \
-			(%(key)s like \"%s\" or \
-			concat_ws(' ', first_name, middle_name, last_name) like \"%%%s\") \
-			limit 50";
-	};
-	
-	cur_frm.fields_dict.lead.get_query = function() {
-		return "select name, lead_name from `tabLead` \
-			where docstatus < 2 and \
-			(%(key)s like \"%s\" or lead_name like \"%%%s\" or \
-			company_name like \"%%%s\") \
-			order by lead_name asc limit 50";
-	};
-	
-	cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;
-	cur_frm.fields_dict.supplier.get_query = erpnext.utils.supplier_query;
-}
-
-cur_frm.cscript.refresh = function(doc, dt, dn) {
-	if(!doc.__islocal) {
-		var field_list = ['lead', 'customer', 'supplier', 'contact', 'opportunity',
-			'quotation', 'support_ticket'];
-		var hide_list = [];
-		$.each(field_list, function(i, v) {
-			if(!doc[v]) hide_list.push(v);
-		});
-		
-		if(hide_list.length < field_list.length) hide_field(hide_list);
-	}
-}
-
-
-cur_frm.cscript.make_communication_body = function() {
-	var communication_wrapper = cur_frm.fields_dict.communication_html.wrapper;
-	communication_wrapper.innerHTML = '';
-	cur_frm.communication_html = $a(communication_wrapper, 'div');
-	$(cur_frm.communication_html).css({
-		'min-height': '275px',
-	});
-}
-
-cur_frm.cscript.render_communication_list = function(doc, dt, dn) {
-	var ListView = wn.views.ListView.extend({
-		init: function(doclistview) {
-			this._super(doclistview);
-			this.fields = this.fields.concat([
-				"`tabCommunication`.communication_date",
-				"`tabCommunication`.category",
-				"`tabCommunication`.subject",
-				"`tabCommunication`.content"
-			]);
-			this.order_by = "`tabCommunication`.communication_date desc";
-		},
-
-		prepare_data: function(data) {
-			this._super(data);
-			this.prepare_when(data, data.creation);
-
-			// escape double quote
-			data.content = cstr(data.subject).replace(/"/gi, '\"')
-				+ " | " + cstr(data.content).replace(/"/gi, '\"');
-
-			if(data.content && data.content.length > 50) {
-				data.content = '<span title="'+data.content+'">' +
-					data.content.substr(0,50) + '...</span>';
-			}
-
-		},
-
-		columns: [
-			{width: '3%', content: 'docstatus'},
-			{width: '15%', content: 'name'},
-			{width: '15%', content: 'category'},
-			{width: '55%', content: 'content'},
-			{width: '12%', content:'when',
-				css: {'text-align': 'right', 'color':'#777'}}		
-		],
-		
-	});
-	
-	cur_frm.cscript.render_list(doc, 'Communication', cur_frm.communication_html,
-		ListView, function(doctype) {
-			var new_doc = LocalDB.create(doctype);
-			new_doc = locals[doctype][new_doc];
-			new_doc[doc.doctype.toLowerCase().replace(" ", "_")] = doc.name;
-			loaddoc(new_doc.doctype, new_doc.name);
-		});
-}
-
-
-// Render List
-cur_frm.cscript.render_list = function(doc, doctype, wrapper, ListView, make_new_doc) {
-	wn.model.with_doctype(doctype, function(r) {
-		if((r && r['403']) || wn.boot.profile.all_read.indexOf(doctype)===-1) {
-			return;
-		}
-		var RecordListView = wn.views.RecordListView.extend({
-			default_docstatus: ['0', '1', '2'],
-			default_filters: [
-				[doctype, doc.doctype.toLowerCase().replace(" ", "_"), '=', doc.name],
-			],
-		});
-		
-		if (make_new_doc) {
-			RecordListView = RecordListView.extend({
-				make_new_doc: make_new_doc,
-			});
-		}
-		
-		var record_list_view = new RecordListView(doctype, wrapper, ListView);
-		if (!cur_frm[doctype.toLowerCase().replace(" ", "_") + "_list"]) {
-			cur_frm[doctype.toLowerCase().replace(" ", "_") + "_list"] = record_list_view;
-		}
-	});
-}
-
-
-cur_frm.cscript.contact = function(doc, dt, dn) {
-	if (doc.contact) {
-		wn.call({
-			method: 'support.doctype.communication.communication.get_customer_supplier',
-			args: {
-				contact: doc.contact
-			},
-			callback: function(r, rt) {
-				if (!r.exc && r.message) {
-					doc = locals[doc.doctype][doc.name];
-					doc[r.message['fieldname']] = r.message['value'];
-					refresh_field(r.message['fieldname']);
-				}
-			},
-		});
-	}
-}
-
-cur_frm.cscript.hide_dialog = function() {
-	if(cur_frm.communication_list)
-		cur_frm.communication_list.run();
-}
\ No newline at end of file
diff --git a/support/doctype/communication/communication.py b/support/doctype/communication/communication.py
deleted file mode 100644
index f365fe3..0000000
--- a/support/doctype/communication/communication.py
+++ /dev/null
@@ -1,110 +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 make_autoname
-
-@webnotes.whitelist()
-def get_customer_supplier(args=None):
-	"""
-		Get Customer/Supplier, given a contact, if a unique match exists
-	"""
-	import webnotes
-	if not args: args = webnotes.form_dict
-	if not args.get('contact'):
-		raise Exception, "Please specify a contact to fetch Customer/Supplier"
-	result = webnotes.conn.sql("""\
-		select customer, supplier
-		from `tabContact`
-		where name = %s""", args.get('contact'), as_dict=1)
-	if result and len(result)==1 and (result[0]['customer'] or result[0]['supplier']):
-		return {
-			'fieldname': result[0]['customer'] and 'customer' or 'supplier',
-			'value': result[0]['customer'] or result[0]['supplier']
-		}
-	return {}
-
-@webnotes.whitelist()
-def make(doctype=None, name=None, content=None, subject=None, 
-	sender=None, recipients=None, contact=None, lead=None, 
-	communication_medium="Email", send_email=False):
-	# add to Communication
-
-	sent_via = None
-	
-	d = webnotes.doc('Communication')
-	d.subject = subject
-	d.content = content
-	d.sender = sender or webnotes.conn.get_value("Profile", webnotes.session.user, "email")
-	d.recipients = recipients
-	d.lead = lead
-	d.contact = contact
-	if doctype:
-		sent_via = webnotes.get_obj(doctype, name)
-		d.fields[doctype.replace(" ", "_").lower()] = name
-		
-	set_lead_and_contact(d)
-	d.communication_medium = communication_medium
-	if send_email:
-		send_comm_email(d, sent_via)
-	d.save(1)
-
-def send_comm_email(d, sent_via=None):
-	from webnotes.utils.email_lib import sendmail
-	
-	if sent_via:
-		if hasattr(sent_via, "get_sender"):
-			d.sender = sent_via.get_sender(d)
-		if hasattr(sent_via, "get_subject"):
-			d.subject = sent_via.get_subject(d)
-		if hasattr(sent_via, "get_content"):
-			d.content = sent_via.get_content(d)
-	
-	sendmail(\
-		recipients = d.recipients.split(","), \
-		sender = d.sender, \
-		subject = d.subject, \
-		msg= d.content)
-		
-	if sent_via and hasattr(sent_via, 'on_communication_sent'):
-		sent_via.on_communication_sent(d)
-
-def set_lead_and_contact(d):
-	import email.utils
-	email_addr = email.utils.parseaddr(d.sender)
-	# set contact
-	if not d.contact:
-		d.contact = webnotes.conn.get_value("Contact", {"email_id": email_addr[1]}, "name") or None
-
-	if not d.lead:
-		d.lead = webnotes.conn.get_value("Lead", {"email_id": email_addr[1]}, "name") or None
-
-	if not d.lead and not d.contact:
-		d.lead = make_lead(d, email_addr[0])
-
-def make_lead(d, real_name):
-	lead = webnotes.doc("Lead")
-	lead.lead_name = real_name or d.sender
-	lead.email_id = d.sender
-	lead.source = "Email"
-	lead.save(1)
-	return lead.name
-
-class DocType():
-	def __init__(self, doc, doclist=[]):
-		self.doc = doc
-		self.doclist = doclist
diff --git a/support/doctype/communication/communication.txt b/support/doctype/communication/communication.txt
deleted file mode 100644
index 87ceb18..0000000
--- a/support/doctype/communication/communication.txt
+++ /dev/null
@@ -1,340 +0,0 @@
-[
- {
-  "owner": "Administrator", 
-  "docstatus": 0, 
-  "creation": "2012-11-28 11:26:11", 
-  "modified_by": "Administrator", 
-  "modified": "2012-11-27 18:51:01"
- }, 
- {
-  "autoname": "naming_series:", 
-  "allow_attach": 1, 
-  "name": "__common__", 
-  "doctype": "DocType", 
-  "module": "Support", 
-  "in_dialog": 0, 
-  "document_type": "Master", 
-  "description": "Keep a track of all communications"
- }, 
- {
-  "name": "__common__", 
-  "parent": "Communication", 
-  "doctype": "DocField", 
-  "parenttype": "DocType", 
-  "parentfield": "fields"
- }, 
- {
-  "name": "__common__", 
-  "parent": "Communication", 
-  "read": 1, 
-  "doctype": "DocPerm", 
-  "write": 1, 
-  "parenttype": "DocType", 
-  "parentfield": "permissions"
- }, 
- {
-  "name": "Communication", 
-  "doctype": "DocType"
- }, 
- {
-  "default": "COMM-", 
-  "colour": "White:FFF", 
-  "doctype": "DocField", 
-  "label": "Naming Series", 
-  "options": "COMM-", 
-  "fieldname": "naming_series", 
-  "fieldtype": "Select", 
-  "hidden": 1, 
-  "permlevel": 0
- }, 
- {
-  "colour": "White:FFF", 
-  "doctype": "DocField", 
-  "label": "Subject", 
-  "fieldname": "subject", 
-  "fieldtype": "Data", 
-  "reqd": 1, 
-  "permlevel": 0
- }, 
- {
-  "colour": "White:FFF", 
-  "doctype": "DocField", 
-  "label": "Content", 
-  "width": "400", 
-  "fieldname": "content", 
-  "fieldtype": "Text Editor", 
-  "reqd": 0, 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "options": "simple", 
-  "fieldname": "section_break1", 
-  "fieldtype": "Section Break", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "label": "Category", 
-  "options": "\nSales\nComplaint\nHelp\nSuggestion\nMiscellaneous\nSent Mail", 
-  "fieldname": "category", 
-  "fieldtype": "Select", 
-  "reqd": 0, 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "column_break2", 
-  "fieldtype": "Column Break", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "label": "Next Communcation On", 
-  "fieldname": "next_communication_date", 
-  "fieldtype": "Date", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "label": "Action", 
-  "options": "\nCreated Opportunity\nSent Quotation\nCreated Support Ticket\nCreated Customer Issue\nNo Action\nSent Mail", 
-  "fieldname": "action", 
-  "fieldtype": "Select", 
-  "reqd": 0, 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "label": "Additional Info", 
-  "fieldname": "additional_info", 
-  "fieldtype": "Section Break", 
-  "permlevel": 0
- }, 
- {
-  "colour": "White:FFF", 
-  "doctype": "DocField", 
-  "fieldname": "column_break3", 
-  "fieldtype": "Column Break", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "label": "Lead", 
-  "options": "Lead", 
-  "fieldname": "lead", 
-  "fieldtype": "Link", 
-  "hidden": 0, 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "label": "Contact", 
-  "options": "Contact", 
-  "fieldname": "contact", 
-  "fieldtype": "Link", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "label": "Customer", 
-  "options": "Customer", 
-  "fieldname": "customer", 
-  "fieldtype": "Link", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "label": "Supplier", 
-  "options": "Supplier", 
-  "fieldname": "supplier", 
-  "fieldtype": "Link", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "label": "Opportunity", 
-  "options": "Opportunity", 
-  "fieldname": "opportunity", 
-  "fieldtype": "Link", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "label": "Quotation", 
-  "options": "Quotation", 
-  "fieldname": "quotation", 
-  "fieldtype": "Link", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "label": "Support Ticket", 
-  "options": "Support Ticket", 
-  "fieldname": "support_ticket", 
-  "fieldtype": "Link", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "column_break1", 
-  "fieldtype": "Column Break", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "label": "Recipients", 
-  "fieldname": "recipients", 
-  "fieldtype": "Data", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "label": "Sender", 
-  "fieldname": "sender", 
-  "fieldtype": "Data", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "label": "Communication Medium", 
-  "options": "\nChat\nPhone\nEmail\nSMS\nVisit\nOther", 
-  "fieldname": "communication_medium", 
-  "fieldtype": "Select", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "label": "Phone No.", 
-  "fieldname": "phone_no", 
-  "fieldtype": "Data", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "options": "simple", 
-  "fieldname": "section_break2", 
-  "fieldtype": "Section Break", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "label": "By", 
-  "fieldname": "column_break4", 
-  "fieldtype": "Column Break", 
-  "permlevel": 0
- }, 
- {
-  "default": "__user", 
-  "colour": "White:FFF", 
-  "doctype": "DocField", 
-  "label": "User", 
-  "options": "Profile", 
-  "fieldname": "user", 
-  "fieldtype": "Link", 
-  "permlevel": 1
- }, 
- {
-  "doctype": "DocField", 
-  "label": "Sales Person", 
-  "options": "Sales Person", 
-  "fieldname": "sales_person", 
-  "fieldtype": "Link", 
-  "permlevel": 1
- }, 
- {
-  "doctype": "DocField", 
-  "label": "On", 
-  "fieldname": "column_break5", 
-  "fieldtype": "Column Break", 
-  "permlevel": 0
- }, 
- {
-  "default": "Today", 
-  "colour": "White:FFF", 
-  "doctype": "DocField", 
-  "label": "Date", 
-  "fieldname": "communication_date", 
-  "fieldtype": "Date", 
-  "permlevel": 0
- }, 
- {
-  "print_hide": 1, 
-  "no_copy": 1, 
-  "doctype": "DocField", 
-  "label": "File List", 
-  "fieldname": "file_list", 
-  "fieldtype": "Text", 
-  "hidden": 1, 
-  "permlevel": 0
- }, 
- {
-  "print_hide": 1, 
-  "no_copy": 1, 
-  "doctype": "DocField", 
-  "label": "User Tags", 
-  "fieldname": "_user_tags", 
-  "fieldtype": "Data", 
-  "hidden": 1, 
-  "permlevel": 0
- }, 
- {
-  "amend": 0, 
-  "create": 1, 
-  "doctype": "DocPerm", 
-  "submit": 0, 
-  "role": "Support Team", 
-  "cancel": 1, 
-  "permlevel": 0
- }, 
- {
-  "amend": 0, 
-  "create": 1, 
-  "doctype": "DocPerm", 
-  "submit": 0, 
-  "role": "Sales Manager", 
-  "cancel": 1, 
-  "permlevel": 0
- }, 
- {
-  "amend": 0, 
-  "create": 1, 
-  "doctype": "DocPerm", 
-  "submit": 0, 
-  "role": "Sales User", 
-  "cancel": 1, 
-  "permlevel": 0
- }, 
- {
-  "amend": 0, 
-  "create": 0, 
-  "doctype": "DocPerm", 
-  "submit": 0, 
-  "role": "Sales Manager", 
-  "cancel": 0, 
-  "permlevel": 1
- }, 
- {
-  "amend": 0, 
-  "create": 0, 
-  "doctype": "DocPerm", 
-  "submit": 0, 
-  "role": "Support Manager", 
-  "cancel": 0, 
-  "permlevel": 1
- }, 
- {
-  "create": 1, 
-  "doctype": "DocPerm", 
-  "role": "Support Manager", 
-  "cancel": 1, 
-  "permlevel": 0
- }, 
- {
-  "create": 1, 
-  "doctype": "DocPerm", 
-  "role": "System Manager", 
-  "cancel": 1, 
-  "permlevel": 0
- }
-]
\ No newline at end of file
diff --git a/support/doctype/communication/communication_list.js b/support/doctype/communication/communication_list.js
deleted file mode 100644
index 8c8d98c..0000000
--- a/support/doctype/communication/communication_list.js
+++ /dev/null
@@ -1,43 +0,0 @@
-wn.doclistviews['Communication'] = wn.views.ListView.extend({
-	init: function(doclistview) {
-		this._super(doclistview);
-		this.fields = this.fields.concat([
-			"`tabCommunication`.creation",
-			"`tabCommunication`.category",
-			"`tabCommunication`.subject",
-			"`tabCommunication`.content"
-		]);
-		this.order_by = "`tabCommunication`.creation desc";
-		this.stats = this.stats.concat(['category']);
-	},
-
-	prepare_data: function(data) {
-		this._super(data);
-		this.prepare_when(data, data.creation);
-
-		// escape double quote
-		data.content = cstr(data.subject)
-			+ " | " + cstr(data.content);
-		data.content = data.content.replace(/"/gi, '\"')
-						.replace(/</gi, '&lt;').replace(/>/gi, '&gt;');
-
-		if(data.content && data.content.length > 50) {
-			data.content = '<span title="'+data.content+'">' +
-				data.content.substr(0,50) + '...</span>';
-		}
-	},
-
-	columns: [
-		{width: '3%', content: 'check'},
-		{width: '5%', content: 'avatar'},
-		{width: '15%', content: 'name'},
-		{width: '15%', content: 'category'},
-		{width: '55%', content: 'content+tags'},
-		{width: '12%', content:'when',
-			css: {'text-align': 'right', 'color':'#777'}}		
-	],
-	
-	make_new_doc: function(new_doctype) {
-		new_doc(new_doctype, 1);
-	}
-});
\ No newline at end of file
diff --git a/support/doctype/customer_issue/customer_issue.py b/support/doctype/customer_issue/customer_issue.py
index bdd7ed6..3d5dba65 100644
--- a/support/doctype/customer_issue/customer_issue.py
+++ b/support/doctype/customer_issue/customer_issue.py
@@ -14,25 +14,16 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.	If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
+from webnotes import session, msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 from utilities.transaction_base import TransactionBase
 
diff --git a/support/doctype/maintenance_schedule/maintenance_schedule.py b/support/doctype/maintenance_schedule/maintenance_schedule.py
index b17fe11..9196162 100644
--- a/support/doctype/maintenance_schedule/maintenance_schedule.py
+++ b/support/doctype/maintenance_schedule/maintenance_schedule.py
@@ -14,24 +14,18 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import add_days, cstr, date_diff, getdate
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
+from webnotes.model.doc import Document, addchild
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 from utilities.transaction_base import TransactionBase
 
diff --git a/support/doctype/maintenance_visit/maintenance_visit.py b/support/doctype/maintenance_visit/maintenance_visit.py
index bcf53f7..bff7f96 100644
--- a/support/doctype/maintenance_visit/maintenance_visit.py
+++ b/support/doctype/maintenance_visit/maintenance_visit.py
@@ -14,24 +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/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
 from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.code import get_obj
+from webnotes import msgprint
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 from utilities.transaction_base import TransactionBase
 
diff --git a/support/doctype/support_ticket/support_ticket.js b/support/doctype/support_ticket/support_ticket.js
index 519d343..fdfbc1a 100644
--- a/support/doctype/support_ticket/support_ticket.js
+++ b/support/doctype/support_ticket/support_ticket.js
@@ -14,8 +14,6 @@
 // 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.require("public/app/js/communication.js");
-
 cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;
 
 $.extend(cur_frm.cscript, {
@@ -62,11 +60,11 @@
 			"modified": doc.creation,
 			"content": doc.description});
 					
-		cur_frm.communication_view = new erpnext.CommunicationView({
+		cur_frm.communication_view = new wn.views.CommunicationList({
 			list: comm_list,
 			parent: wrapper,
 			doc: doc,
-			email: doc.raised_by
+			recipients: doc.raised_by
 		})
 
 	},
diff --git a/support/doctype/support_ticket/support_ticket.py b/support/doctype/support_ticket/support_ticket.py
index e9b13bc..89a58a6 100644
--- a/support/doctype/support_ticket/support_ticket.py
+++ b/support/doctype/support_ticket/support_ticket.py
@@ -16,7 +16,6 @@
 
 from __future__ import unicode_literals
 import webnotes
-from webnotes.model.doc import make_autoname
 
 from utilities.transaction_base import TransactionBase
 from home import update_feed
diff --git a/utilities/doctype/address/address.py b/utilities/doctype/address/address.py
index f9e53e7..08bf5cd 100644
--- a/utilities/doctype/address/address.py
+++ b/utilities/doctype/address/address.py
@@ -14,14 +14,11 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.model.doc import Document
-from webnotes import session, form, msgprint, errprint
+from webnotes import msgprint
 
-# -----------------------------------------------------------------------------------------
 class DocType:
 	def __init__(self, doc, doclist=[]):
 		self.doc = doc
diff --git a/utilities/doctype/contact/contact.js b/utilities/doctype/contact/contact.js
index d51c0f5..3876ca2 100644
--- a/utilities/doctype/contact/contact.js
+++ b/utilities/doctype/contact/contact.js
@@ -14,9 +14,6 @@
 // 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.require("public/app/js/communication.js");
-
-//--------- ONLOAD -------------
 cur_frm.cscript.onload = function(doc, cdt, cdn) {	
 	cur_frm.add_fetch('customer', 'customer_name', 'customer_name');
 	cur_frm.add_fetch('supplier', 'supplier_name', 'supplier_name');
@@ -26,7 +23,7 @@
 }
 
 cur_frm.cscript.refresh = function() {
-	cur_frm.communication_view = new erpnext.CommunicationView({
+	cur_frm.communication_view = new wn.views.CommunicationList({
 		list: wn.model.get("Communication", {"contact": doc.name}),
 		parent: cur_frm.fields_dict.communication_html.wrapper,
 		doc: doc,
diff --git a/utilities/doctype/contact/contact.py b/utilities/doctype/contact/contact.py
index d980733..0db4670 100644
--- a/utilities/doctype/contact/contact.py
+++ b/utilities/doctype/contact/contact.py
@@ -14,12 +14,9 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.model.doc import Document
-from webnotes import session, form, msgprint, errprint
 
 from utilities.transaction_base import TransactionBase
 
diff --git a/utilities/doctype/contact/contact_list.js b/utilities/doctype/contact/contact_list.js
index bbf5bf8..3b1b3c9 100644
--- a/utilities/doctype/contact/contact_list.js
+++ b/utilities/doctype/contact/contact_list.js
@@ -20,7 +20,7 @@
 		data.fullname = (data.first_name || '') + 
 						(data.last_name ? ' ' + data.last_name : '');
 		if(!data.fullname) data.fullname = data.name;
-		data.fullname = repl("<a href='#!Form/Contact/%(name)s'>%(fullname)s\
+		data.fullname = repl("<a href='#!Form/Contact/%(name)s'>%(name)s\
 							</a>", data);
 
 		// prepare description
diff --git a/utilities/doctype/profile_control/profile_control.py b/utilities/doctype/profile_control/profile_control.py
index e906f70..5f6b4d5 100644
--- a/utilities/doctype/profile_control/profile_control.py
+++ b/utilities/doctype/profile_control/profile_control.py
@@ -14,24 +14,16 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import cstr
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.doc import Document
+from webnotes.model.wrapper import copy_doclist
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/utilities/doctype/rename_tool/rename_tool.py b/utilities/doctype/rename_tool/rename_tool.py
index b0d7671..79832fb 100644
--- a/utilities/doctype/rename_tool/rename_tool.py
+++ b/utilities/doctype/rename_tool/rename_tool.py
@@ -24,7 +24,6 @@
 		Generate update quereies for rename
 		"""
 		import webnotes.model
-		from webnotes.model.code import get_obj
 			
 		# rename the document		
 		webnotes.model.rename(self.doc.select_doctype, self.doc.document_to_rename, self.doc.new_name)
diff --git a/utilities/doctype/sms_control/sms_control.py b/utilities/doctype/sms_control/sms_control.py
index 2be7546..9b80d1e 100644
--- a/utilities/doctype/sms_control/sms_control.py
+++ b/utilities/doctype/sms_control/sms_control.py
@@ -14,20 +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/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import cint, flt, load_json, nowdate, cstr
+from webnotes.utils import load_json, nowdate, cstr
 from webnotes.model.code import get_obj
 from webnotes.model.doc import Document
-from webnotes import session, msgprint
+from webnotes import msgprint
 from webnotes.model.wrapper import getlist, copy_doclist
 
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
 	
-# -----------------------------------------------------------------------------------------
 class DocType:
 	def __init__(self, doc, doclist=[]):
 		self.doc = doc
diff --git a/utilities/doctype/trash_control/trash_control.py b/utilities/doctype/trash_control/trash_control.py
index 8d0e02c..50edbf5 100644
--- a/utilities/doctype/trash_control/trash_control.py
+++ b/utilities/doctype/trash_control/trash_control.py
@@ -14,24 +14,16 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Please edit this list and import only required elements
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.utils import now
 from webnotes.model import db_exists
-from webnotes.model.doc import Document, addchild, getchildren, make_autoname
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
-from webnotes import session, form, msgprint, errprint
+from webnotes.model.wrapper import copy_doclist
+from webnotes.model.code import get_obj
 
-set = webnotes.conn.set
 sql = webnotes.conn.sql
-get_value = webnotes.conn.get_value
-in_transaction = webnotes.conn.in_transaction
-convert_to_lists = webnotes.conn.convert_to_lists
 	
-# -----------------------------------------------------------------------------------------
 
 
 class DocType:
diff --git a/utilities/page/questions/questions.py b/utilities/page/questions/questions.py
index 459a32f..b38bc1e 100644
--- a/utilities/page/questions/questions.py
+++ b/utilities/page/questions/questions.py
@@ -17,7 +17,7 @@
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import load_json, cint, cstr
+from webnotes.utils import load_json
 import json
 
 @webnotes.whitelist()
diff --git a/utilities/transaction_base.py b/utilities/transaction_base.py
index 398a831..3f47237 100644
--- a/utilities/transaction_base.py
+++ b/utilities/transaction_base.py
@@ -16,11 +16,9 @@
 
 from __future__ import unicode_literals
 import webnotes
-from webnotes.utils import load_json, cint, cstr, flt, get_defaults
-from webnotes.model.doc import Document, addchild, getchildren
-from webnotes.model.wrapper import getlist, copy_doclist
-from webnotes.model.code import get_obj
-from webnotes import msgprint
+from webnotes.utils import load_json, cstr, flt, get_defaults
+from webnotes.model.doc import addchild
+from webnotes.model.wrapper import copy_doclist
 
 class TransactionBase:
 
@@ -238,10 +236,12 @@
 		return dcc	
 	
 
-	def get_formatted_message(self, args):
-		""" get formatted message for auto notification"""
-		return get_obj('Notification Control').get_formatted_message(args)
-
+	def load_notification_message(self):
+		dt = self.doc.doctype.lower().replace(" ", "_")
+		if int(webnotes.conn.get_value("Notification Control", None, dt) or 0):
+			self.doc.fields["__notification_message"] = \
+				webnotes.conn.get_value("Notification Control", None, dt + "_message")
+				
 	def add_communication_list(self):
 		# remove communications if present
 		self.doclist = webnotes.doclist(self.doclist).get({
diff --git a/website/product.py b/website/product.py
index 1c0d6d9..fd471cb 100644
--- a/website/product.py
+++ b/website/product.py
@@ -12,7 +12,7 @@
 		}
 	"""
 	import webnotes
-	from webnotes.utils import cstr, cint
+	from webnotes.utils import cstr
 	
 	if not args: args = webnotes.form_dict
 	
diff --git a/website/utils.py b/website/utils.py
index 5393a3d..dae998d 100644
--- a/website/utils.py
+++ b/website/utils.py
@@ -16,7 +16,6 @@
 
 from __future__ import unicode_literals
 import webnotes
-from webnotes.model.doc import Document
 
 def scrub_page_name(page_name):
 	if page_name.endswith('.html'):