Merge branch 'model-cleanup' of github.com:frappe/erpnext into model-cleanup
diff --git a/erpnext/accounts/doctype/journal_voucher/journal_voucher.py b/erpnext/accounts/doctype/journal_voucher/journal_voucher.py
index a2fbec1..02bca17 100644
--- a/erpnext/accounts/doctype/journal_voucher/journal_voucher.py
+++ b/erpnext/accounts/doctype/journal_voucher/journal_voucher.py
@@ -11,7 +11,8 @@
 from erpnext.controllers.accounts_controller import AccountsController
 
 class JournalVoucher(AccountsController):
-
+	def __init__(self, arg1, arg2=None):
+		super(JournalVoucher, self).__init__(arg1, arg2)
 		self.master_type = {}
 		self.credit_days_for = {}
 		self.credit_days_global = -1
diff --git a/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py b/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py
index a07ed2f..d8661e1 100644
--- a/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py
+++ b/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py
@@ -8,8 +8,6 @@
 from erpnext.controllers.accounts_controller import AccountsController
 
 class PeriodClosingVoucher(AccountsController):
-		self.year_start_date = ''
-
 	def validate(self):
 		self.validate_account_head()
 		self.validate_posting_date()
@@ -47,7 +45,7 @@
 			and t2.docstatus < 2 and t2.company = %s 
 			and t1.posting_date between %s and %s 
 			group by t1.account
-		""", (self.company, self.year_start_date, self.posting_date), as_dict=1)
+		""", (self.company, self.get("year_start_date"), self.posting_date), as_dict=1)
 	 
 	def make_gl_entries(self):
 		gl_entries = []
diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.py b/erpnext/buying/doctype/purchase_common/purchase_common.py
index a571144..80af450 100644
--- a/erpnext/buying/doctype/purchase_common/purchase_common.py
+++ b/erpnext/buying/doctype/purchase_common/purchase_common.py
@@ -5,7 +5,6 @@
 import frappe
 
 from frappe.utils import cstr, flt
-from frappe.model.utils import getlist
 from frappe import msgprint, _
 
 from erpnext.stock.doctype.item.item import get_last_purchase_details
@@ -19,7 +18,7 @@
 		import frappe.utils
 		this_purchase_date = frappe.utils.getdate(obj.get('posting_date') or obj.get('transaction_date'))
 		
-		for d in getlist(obj.doclist,obj.fname):
+		for d in obj.get(obj.fname):
 			# get last purchase details
 			last_purchase_details = get_last_purchase_details(d.item_code, obj.name)
 
@@ -47,7 +46,7 @@
 		doc_name = obj.name
 		conversion_rate = flt(obj.get('conversion_rate')) or 1.0
 		
-		for d in getlist(obj.doclist, obj.fname):
+		for d in obj.get(obj.fname):
 			if d.item_code:
 				last_purchase_details = get_last_purchase_details(d.item_code, doc_name)
 
@@ -69,7 +68,7 @@
 			
 	def validate_for_items(self, obj):
 		check_list, chk_dupl_itm=[],[]
-		for d in getlist( obj.doclist, obj.fname):
+		for d in obj.get(obj.fname):
 			# validation for valid qty	
 			if flt(d.qty) < 0 or (d.parenttype != 'Purchase Receipt' and not flt(d.qty)):
 				frappe.throw("Please enter valid qty for item %s" % cstr(d.item_code))
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py
index ca68e2b..81c7dfb 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.py
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.py
@@ -11,19 +11,19 @@
 	
 from erpnext.controllers.buying_controller import BuyingController
 class PurchaseOrder(BuyingController):
-		self.tname = 'Purchase Order Item'
-		self.fname = 'po_details'
-		self.status_updater = [{
-			'source_dt': 'Purchase Order Item',
-			'target_dt': 'Material Request Item',
-			'join_field': 'prevdoc_detail_docname',
-			'target_field': 'ordered_qty',
-			'target_parent_dt': 'Material Request',
-			'target_parent_field': 'per_ordered',
-			'target_ref_field': 'qty',
-			'source_field': 'qty',
-			'percent_join_field': 'prevdoc_docname',
-		}]
+	tname = 'Purchase Order Item'
+	fname = 'po_details'
+	status_updater = [{
+		'source_dt': 'Purchase Order Item',
+		'target_dt': 'Material Request Item',
+		'join_field': 'prevdoc_detail_docname',
+		'target_field': 'ordered_qty',
+		'target_parent_dt': 'Material Request',
+		'target_parent_field': 'per_ordered',
+		'target_ref_field': 'qty',
+		'source_field': 'qty',
+		'percent_join_field': 'prevdoc_docname',
+	}]
 		
 	def validate(self):
 		super(DocType, self).validate()
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 777150e..b3155fd 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -342,20 +342,14 @@
 	
 	def _cleanup(self):
 		for tax in self.tax_doclist:
-			for fieldname in ("grand_total_for_current_item",
-				"tax_amount_for_current_item",
-				"tax_fraction_for_current_item", 
-				"grand_total_fraction_for_current_item"):
-				if fieldname in tax.fields:
-					del tax.get(fieldname)
-			
 			tax.item_wise_tax_detail = json.dumps(tax.item_wise_tax_detail)
 			
 	def _set_in_company_currency(self, item, print_field, base_field):
 		"""set values in base currency"""
-		item.set(base_field, flt((flt(item.get(print_field),)
-			self.precision(print_field, item)) * self.conversion_rate),
+		value_in_company_currency = flt(self.conversion_rate * 
+			flt(item.get(print_field), self.precision(print_field, item)),
 			self.precision(base_field, item))
+		item.set(base_field, value_in_company_currency)
 			
 	def calculate_total_advance(self, parenttype, advance_parentfield):
 		if self.doctype == parenttype and self.docstatus < 2:
diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py
index b186e5c..b37213c 100644
--- a/erpnext/controllers/buying_controller.py
+++ b/erpnext/controllers/buying_controller.py
@@ -147,18 +147,6 @@
 			self.outstanding_amount = flt(self.total_amount_to_pay - self.total_advance,
 				self.precision("outstanding_amount"))
 			
-	def _cleanup(self):
-		super(BuyingController, self)._cleanup()
-		
-		if not self.meta.get_field("item_tax_amount", parentfield=self.fname):
-			for item in self.item_doclist:
-				del item.get("item_tax_amount")
-				
-		if not self.meta.get_field("tax_amount_after_discount_amount", 
-				parentfield=self.other_fname):
-			for tax in self.tax_doclist:
-				del tax.get("tax_amount_after_discount_amount")
-				
 	# update valuation rate
 	def update_valuation_rate(self, parentfield):
 		"""
diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
index 8c9c3cd..cec6471 100644
--- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
+++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
@@ -10,6 +10,8 @@
 from frappe.model.document import Document
 
 class ProductionPlanningTool(Document):
+	def __init__(self, arg1, arg2=None):
+		super(ProductionPlanningTool, self).__init__(arg1, arg2)
 		self.item_dict = {}
 
 	def get_so_details(self, so):
diff --git a/erpnext/selling/doctype/installation_note/installation_note.py b/erpnext/selling/doctype/installation_note/installation_note.py
index 91f1a07..b69e319 100644
--- a/erpnext/selling/doctype/installation_note/installation_note.py
+++ b/erpnext/selling/doctype/installation_note/installation_note.py
@@ -12,21 +12,21 @@
 from erpnext.utilities.transaction_base import TransactionBase
 
 class InstallationNote(TransactionBase):
-		self.tname = 'Installation Note Item'
-		self.fname = 'installed_item_details'
-		self.status_updater = [{
-			'source_dt': 'Installation Note Item',
-			'target_dt': 'Delivery Note Item',
-			'target_field': 'installed_qty',
-			'target_ref_field': 'qty',
-			'join_field': 'prevdoc_detail_docname',
-			'target_parent_dt': 'Delivery Note',
-			'target_parent_field': 'per_installed',
-			'source_field': 'qty',
-			'percent_join_field': 'prevdoc_docname',
-			'status_field': 'installation_status',
-			'keyword': 'Installed'
-		}]
+	tname = 'Installation Note Item'
+	fname = 'installed_item_details'
+	status_updater = [{
+		'source_dt': 'Installation Note Item',
+		'target_dt': 'Delivery Note Item',
+		'target_field': 'installed_qty',
+		'target_ref_field': 'qty',
+		'join_field': 'prevdoc_detail_docname',
+		'target_parent_dt': 'Delivery Note',
+		'target_parent_field': 'per_installed',
+		'source_field': 'qty',
+		'percent_join_field': 'prevdoc_docname',
+		'status_field': 'installation_status',
+		'keyword': 'Installed'
+	}]
 
 	def validate(self):
 		self.validate_fiscal_year()
diff --git a/erpnext/selling/doctype/lead/lead.py b/erpnext/selling/doctype/lead/lead.py
index 4fdb8c0..743dc04 100644
--- a/erpnext/selling/doctype/lead/lead.py
+++ b/erpnext/selling/doctype/lead/lead.py
@@ -11,20 +11,19 @@
 from erpnext.controllers.selling_controller import SellingController
 
 class Lead(SellingController):
-
-		self._prev = frappe._dict({
-			"contact_date": frappe.db.get_value("Lead", self.name, "contact_date") if \
-				(not cint(self.get("__islocal"))) else None,
-			"contact_by": frappe.db.get_value("Lead", self.name, "contact_by") if \
-				(not cint(self.get("__islocal"))) else None,
-		})
-
 	def onload(self):
 		customer = frappe.db.get_value("Customer", {"lead_name": self.name})
 		if customer:
 			self.set("__is_customer", customer)
 	
 	def validate(self):
+		self._prev = frappe._dict({
+			"contact_date": frappe.db.get_value("Lead", self.name, "contact_date") if \
+				(not cint(self.get("__islocal"))) else None,
+			"contact_by": frappe.db.get_value("Lead", self.name, "contact_by") if \
+				(not cint(self.get("__islocal"))) else None,
+		})
+		
 		self.set_status()
 		
 		if self.source == 'Campaign' and not self.campaign_name and session['user'] != 'Guest':
diff --git a/erpnext/setup/doctype/authorization_control/authorization_control.py b/erpnext/setup/doctype/authorization_control/authorization_control.py
index a50eb2f..8a401f0 100644
--- a/erpnext/setup/doctype/authorization_control/authorization_control.py
+++ b/erpnext/setup/doctype/authorization_control/authorization_control.py
@@ -86,7 +86,7 @@
 				add_cond = " and master_name = '"+make_esc("'")(cstr(customer))+"'"
 		if based_on == 'Itemwise Discount':
 			if doc_obj:
-				for t in getlist(doc_obj.doclist, doc_obj.fname):
+				for t in doc_obj.get(doc_obj.fname):
 					self.validate_auth_rule(doctype_name, t.discount_percentage, based_on, add_cond, company,t.item_code )
 		else:
 			self.validate_auth_rule(doctype_name, auth_value, based_on, add_cond, company)
@@ -98,7 +98,7 @@
 		av_dis = 0
 		if doc_obj:
 			price_list_rate, base_rate = 0, 0
-			for d in getlist(doc_obj.doclist, doc_obj.fname):
+			for d in doc_obj.get(doc_obj.fname):
 				if d.base_price_list_rate and d.base_rate:
 					price_list_rate += flt(d.base_price_list_rate)
 					base_rate += flt(d.base_rate)
diff --git a/erpnext/setup/doctype/item_group/item_group.py b/erpnext/setup/doctype/item_group/item_group.py
index 52880fc..e1f79a5 100644
--- a/erpnext/setup/doctype/item_group/item_group.py
+++ b/erpnext/setup/doctype/item_group/item_group.py
@@ -7,7 +7,7 @@
 from frappe.utils.nestedset import DocTypeNestedSet
 
 class ItemGroup(DocTypeNestedSet):
-		self.nsm_parent_field = 'parent_item_group'
+	nsm_parent_field = 'parent_item_group'
 	
 	def validate(self):
 		if not self.parent_website_route:
diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py
index fc7f64e..f9ba9b5 100644
--- a/erpnext/stock/doctype/material_request/material_request.py
+++ b/erpnext/stock/doctype/material_request/material_request.py
@@ -8,7 +8,6 @@
 import frappe
 
 from frappe.utils import cstr, flt
-from frappe.model.utils import getlist
 from frappe import msgprint, _
 
 from erpnext.controllers.buying_controller import BuyingController
diff --git a/erpnext/stock/doctype/packed_item/packed_item.py b/erpnext/stock/doctype/packed_item/packed_item.py
index 232e601..755c110 100644
--- a/erpnext/stock/doctype/packed_item/packed_item.py
+++ b/erpnext/stock/doctype/packed_item/packed_item.py
@@ -32,7 +32,7 @@
 
 	# check if exists
 	exists = 0
-	for d in getlist(obj.doclist, 'packing_details'):
+	for d in obj.get("packing_details"):
 		if d.parent_item == line.item_code and d.item_code == packing_item_code and d.parent_detail_docname == line.name:
 			pi, exists = d, 1
 			break
diff --git a/erpnext/utilities/doctype/sms_control/sms_control.py b/erpnext/utilities/doctype/sms_control/sms_control.py
index c0a4647..6b8c684 100644
--- a/erpnext/utilities/doctype/sms_control/sms_control.py
+++ b/erpnext/utilities/doctype/sms_control/sms_control.py
@@ -70,7 +70,7 @@
 	def send_via_gateway(self, arg):
 		ss = frappe.get_doc('SMS Settings', 'SMS Settings')
 		args = {ss.message_parameter : arg.get('message')}
-		for d in getlist(ss.doclist, 'static_parameter_details'):
+		for d in ss.get("static_parameter_details"):
 			args[d.parameter] = d.value
 		
 		resp = []
diff --git a/erpnext/utilities/transaction_base.py b/erpnext/utilities/transaction_base.py
index 66a1a03..4be3d6f 100644
--- a/erpnext/utilities/transaction_base.py
+++ b/erpnext/utilities/transaction_base.py
@@ -13,8 +13,8 @@
 	def load_notification_message(self):
 		dt = self.doctype.lower().replace(" ", "_")
 		if int(frappe.db.get_value("Notification Control", None, dt) or 0):
-			self.set("__notification_message", \)
-				frappe.db.get_value("Notification Control", None, dt + "_message")
+			self.set("__notification_message",
+				frappe.db.get_value("Notification Control", None, dt + "_message"))
 							
 	def validate_posting_time(self):
 		if not self.posting_time: