frappe/frappe#478, more changes, removed bean
diff --git a/erpnext/accounts/Print Format/SalesInvoice/SalesInvoice.html b/erpnext/accounts/Print Format/SalesInvoice/SalesInvoice.html
index d4a49ef..8dc39f9 100644
--- a/erpnext/accounts/Print Format/SalesInvoice/SalesInvoice.html
+++ b/erpnext/accounts/Print Format/SalesInvoice/SalesInvoice.html
@@ -65,7 +65,7 @@
 				<th>Basic Rate</th>
 				<th>Amount</th>
 			</tr>
-			{%- for row in doclist.get({"doctype":"Sales Invoice Item"}) %}
+			{%- for row in doc.get({"doctype":"Sales Invoice Item"}) %}
 			<tr>
 				<td style="width: 3%;">{{ row.idx }}</td>
 				<td style="width: 20%;">{{ row.item_name }}</td>
@@ -106,7 +106,7 @@
 								utils.fmt_money(doc.net_total_export, currency=doc.currency)
 							}}</td>
 						</tr>
-						{%- for charge in doclist.get({"doctype":"Sales Taxes and Charges"}) -%}
+						{%- for charge in doc.get({"doctype":"Sales Taxes and Charges"}) -%}
 						{%- if not charge.included_in_print_rate -%}
 						<tr>
 							<td>{{ charge.description }}</td>
diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py
index 094edd0..59637a5 100644
--- a/erpnext/accounts/doctype/account/account.py
+++ b/erpnext/accounts/doctype/account/account.py
@@ -40,13 +40,13 @@
 				["name", "group_or_ledger", "report_type"], as_dict=1)
 			if not par:
 				throw(_("Parent account does not exists"))
-			elif par[0]["name"] == self.name:
+			elif par["name"] == self.name:
 				throw(_("You can not assign itself as parent account"))
-			elif par[0]["group_or_ledger"] != 'Group':
+			elif par["group_or_ledger"] != 'Group':
 				throw(_("Parent account can not be a ledger"))
 				
-			if par[0]["report_type"]:
-				self.report_type = par[0]["report_type"]
+			if par["report_type"]:
+				self.report_type = par["report_type"]
 	
 	def validate_duplicate_account(self):
 		if self.get('__islocal') or not self.name:
diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.py b/erpnext/accounts/doctype/accounts_settings/accounts_settings.py
index bc950d5..b7288e0 100644
--- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.py
+++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.py
@@ -25,5 +25,5 @@
 				frappe.throw(_("Company is missing in following warehouses") + ": \n" + 
 					"\n".join(warehouse_with_no_company))
 			for wh in warehouse_list:
-				wh_bean = frappe.get_doc("Warehouse", wh.name)
-				wh_bean.save()
\ No newline at end of file
+				wh_doc = frappe.get_doc("Warehouse", wh.name)
+				wh_doc.save()
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/budget_distribution/test_records.json b/erpnext/accounts/doctype/budget_distribution/test_records.json
index 0637a08..7e8c640 100644
--- a/erpnext/accounts/doctype/budget_distribution/test_records.json
+++ b/erpnext/accounts/doctype/budget_distribution/test_records.json
@@ -1 +1,44 @@
-[]
\ No newline at end of file
+[{
+	"doctype": "Budget Distribution",
+	"distribution_id": "_Test Distribution",
+	"fiscal_year": "_Test Fiscal Year 2013",
+	"budget_distribution_details": [
+		{
+			"month": "January",
+			"percentage_allocation": "8"
+		}, {
+			"month": "February",
+			"percentage_allocation": "8"
+		}, {
+			"month": "March",
+			"percentage_allocation": "8"
+		}, {
+			"month": "April",
+			"percentage_allocation": "8"
+		}, {
+			"month": "May",
+			"percentage_allocation": "8"
+		}, {
+			"month": "June",
+			"percentage_allocation": "8"
+		}, {
+			"month": "July",
+			"percentage_allocation": "8"
+		}, {
+			"month": "August",
+			"percentage_allocation": "8"
+		}, {
+			"month": "September",
+			"percentage_allocation": "8"
+		}, {
+			"month": "October",
+			"percentage_allocation": "8"
+		}, {
+			"month": "November",
+			"percentage_allocation": "10"
+		}, {
+			"month": "December",
+			"percentage_allocation": "10"
+		}		
+	]
+}]
diff --git a/erpnext/accounts/doctype/chart_of_accounts/import_charts.py b/erpnext/accounts/doctype/chart_of_accounts/import_charts.py
index fd36bf8..9e60551 100644
--- a/erpnext/accounts/doctype/chart_of_accounts/import_charts.py
+++ b/erpnext/accounts/doctype/chart_of_accounts/import_charts.py
@@ -13,13 +13,13 @@
 				chart = json.loads(f.read())
 				country = frappe.db.get_value("Country", {"code": fname.split("_", 1)[0]})
 				if country:
-					bean = frappe.get_doc({
+					doc = frappe.get_doc({
 						"doctype":"Chart of Accounts",
 						"chart_name": chart.get("name"),
 						"source_file": fname,
 						"country": country
 					}).insert()
-					print bean.name.encode("utf-8")
+					print doc.name.encode("utf-8")
 				else:
 					print "No chart for: " + chart.get("name").encode("utf-8")
 				
diff --git a/erpnext/accounts/doctype/cost_center/cost_center.py b/erpnext/accounts/doctype/cost_center/cost_center.py
index ac69e75..7013ffb 100644
--- a/erpnext/accounts/doctype/cost_center/cost_center.py
+++ b/erpnext/accounts/doctype/cost_center/cost_center.py
@@ -13,7 +13,7 @@
 	
 	def autoname(self):
 		self.name = self.cost_center_name.strip() + ' - ' + \
-			frappe.get_value("Company", self.company, "abbr")
+			frappe.db.get_value("Company", self.company, "abbr")
 		
 	def validate_mandatory(self):
 		if not self.group_or_ledger:
diff --git a/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py b/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py
index d0e6c6c..edceddb 100644
--- a/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py
+++ b/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py
@@ -3,4 +3,6 @@
 
 from __future__ import unicode_literals
 
+import frappe
+
 test_records = frappe.get_test_records('Fiscal Year')
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/journal_voucher/journal_voucher.py b/erpnext/accounts/doctype/journal_voucher/journal_voucher.py
index 3af9a03..9829a17 100644
--- a/erpnext/accounts/doctype/journal_voucher/journal_voucher.py
+++ b/erpnext/accounts/doctype/journal_voucher/journal_voucher.py
@@ -349,8 +349,8 @@
 def get_payment_entry_from_sales_invoice(sales_invoice):
 	from erpnext.accounts.utils import get_balance_on
 	si = frappe.get_doc("Sales Invoice", sales_invoice)
-	jv = get_payment_entry(si.doc)
-	jv.remark = 'Payment received against Sales Invoice %(name)s. %(remarks)s' % si.fields
+	jv = get_payment_entry(si)
+	jv.remark = 'Payment received against Sales Invoice {0}. {1}'.format(si.name, si.remarks)
 
 	# credit customer
 	jv.doclist[1].account = si.debit_to
@@ -367,8 +367,8 @@
 def get_payment_entry_from_purchase_invoice(purchase_invoice):
 	from erpnext.accounts.utils import get_balance_on
 	pi = frappe.get_doc("Purchase Invoice", purchase_invoice)
-	jv = get_payment_entry(pi.doc)
-	jv.remark = 'Payment against Purchase Invoice %(name)s. %(remarks)s' % pi.fields
+	jv = get_payment_entry(pi)
+	jv.remark = 'Payment against Purchase Invoice {0}. {1}'.format(pi.name, pi.remarks)
 	
 	# credit supplier
 	jv.doclist[1].account = pi.credit_to
@@ -384,7 +384,7 @@
 def get_payment_entry(doc):
 	bank_account = get_default_bank_cash_account(doc.company, "Bank Voucher")
 	
-	jv = frappe.new_bean('Journal Voucher')
+	jv = frappe.new_doc('Journal Voucher')
 	jv.voucher_type = 'Bank Voucher'
 
 	jv.company = doc.company
diff --git a/erpnext/accounts/doctype/purchase_taxes_and_charges/purchase_taxes_and_charges.py b/erpnext/accounts/doctype/purchase_taxes_and_charges/purchase_taxes_and_charges.py
index 910e380..25dbf95 100644
--- a/erpnext/accounts/doctype/purchase_taxes_and_charges/purchase_taxes_and_charges.py
+++ b/erpnext/accounts/doctype/purchase_taxes_and_charges/purchase_taxes_and_charges.py
@@ -6,5 +6,5 @@
 
 from frappe.model.document import Document
 
-class PurchaseTaxesAndCharges(Document):
+class PurchaseTaxesandCharges(Document):
 	pass
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.py b/erpnext/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.py
index fb9a0ab..e93c572 100644
--- a/erpnext/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.py
+++ b/erpnext/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.py
@@ -5,5 +5,5 @@
 import frappe
 from frappe.model.document import Document
 
-class PurchaseTaxesAndChargesMaster(Document):
+class PurchaseTaxesandChargesMaster(Document):
 	pass
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index e9e9869..ba34b49 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -192,7 +192,7 @@
 			for item in self.get("entries"):
 				if item.get('item_code'):
 					for fname, val in get_pos_settings_item_details(pos, 
-						frappe._dict(item.fields), pos).items():
+						frappe._dict(item.as_dict()), pos).items():
 						
 						if (not for_validate) or (for_validate and not item.get(fname)):
 							item.set(fname, val)
@@ -696,7 +696,7 @@
 		raise Exception, exception_message
 
 def make_new_invoice(ref_wrapper, posting_date):
-	from frappe.model.bean import clone
+	from frappe.model.doc import clone
 	from erpnext.accounts.utils import get_fiscal_year
 	new_invoice = clone(ref_wrapper)
 	
@@ -736,7 +736,7 @@
 	from frappe.core.doctype.print_format.print_format import get_html
 	frappe.sendmail(new_rv.notification_email_address, 
 		subject="New Invoice : " + new_rv.name, 
-		message = get_html(new_rv.doc, new_rv, "SalesInvoice"))
+		message = get_html(new_rv, new_rv, "SalesInvoice"))
 		
 def notify_errors(inv, customer, owner):
 	from frappe.utils.user import get_system_managers
@@ -797,8 +797,8 @@
 	from frappe.model.mapper import get_mapped_doc
 	
 	def set_missing_values(source, target):
-		bean = frappe.get_doc(target)
-		bean.run_method("onload_post_render")
+		doc = frappe.get_doc(target)
+		doc.run_method("onload_post_render")
 		
 	def update_item(source_doc, target_doc, source_parent):
 		target_doc.base_amount = (flt(source_doc.qty) - flt(source_doc.delivered_qty)) * \
diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
index 7879dcb..109d0e5 100644
--- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
@@ -4,7 +4,7 @@
 import frappe
 import unittest, json
 from frappe.utils import flt
-from frappe.model.bean import DocstatusTransitionError, TimestampMismatchError
+from frappe.model.doc import DocstatusTransitionError, TimestampMismatchError
 from erpnext.accounts.utils import get_stock_and_account_difference
 from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory
 
diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.py b/erpnext/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.py
index 8f621de..f4a9448 100644
--- a/erpnext/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.py
+++ b/erpnext/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.py
@@ -6,5 +6,5 @@
 
 from frappe.model.document import Document
 
-class SalesTaxesAndCharges(Document):
+class SalesTaxesandCharges(Document):
 	pass
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.py b/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.py
index 76417e3..f63a767 100644
--- a/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.py
+++ b/erpnext/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.py
@@ -6,7 +6,7 @@
 from frappe.utils import cint
 from frappe.model.controller import DocListController
 
-class SalesTaxesAndChargesMaster(DocListController):		
+class SalesTaxesandChargesMaster(DocListController):		
 	def validate(self):
 		if self.is_default == 1:
 			frappe.db.sql("""update `tabSales Taxes and Charges Master` set is_default = 0 
diff --git a/erpnext/accounts/doctype/shipping_rule/shipping_rule.py b/erpnext/accounts/doctype/shipping_rule/shipping_rule.py
index d27565e..9e88f22 100644
--- a/erpnext/accounts/doctype/shipping_rule/shipping_rule.py
+++ b/erpnext/accounts/doctype/shipping_rule/shipping_rule.py
@@ -66,7 +66,7 @@
 		for i in xrange(0, len(self.shipping_rule_conditions)):
 			for j in xrange(i+1, len(self.shipping_rule_conditions)):
 				d1, d2 = self.shipping_rule_conditions[i], self.shipping_rule_conditions[j]
-				if d1.fields != d2.fields:
+				if d1.as_dict() != d2.as_dict():
 					# in our case, to_value can be zero, hence pass the from_value if so
 					range_a = (d1.from_value, d1.to_value or d1.from_value)
 					range_b = (d2.from_value, d2.to_value or d2.from_value)
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index e86d6a9..a159a73 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -25,8 +25,8 @@
 	if not ignore_permissions and not frappe.has_permission(party_type, "read", party):
 		frappe.throw("Not Permitted", frappe.PermissionError)
 
-	party_bean = frappe.get_doc(party_type, party)
-	party = party_bean.doc
+	party_doc = frappe.get_doc(party_type, party)
+	party = party_doc
 
 	set_address_details(out, party, party_type)
 	set_contact_details(out, party, party_type)
@@ -41,7 +41,7 @@
 		out["sales_team"] = [{
 			"sales_person": d.sales_person, 
 			"sales_designation": d.sales_designation
-		} for d in party_bean.get("sales_team")]
+		} for d in party_doc.get("sales_team")]
 	
 	return out
 
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py
index 9458ecc..afa9748 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.py
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.py
@@ -184,8 +184,8 @@
 	from frappe.model.mapper import get_mapped_doc
 	
 	def set_missing_values(source, target):
-		bean = frappe.get_doc(target)
-		bean.run_method("set_missing_values")
+		doc = frappe.get_doc(target)
+		doc.run_method("set_missing_values")
 
 	def update_item(obj, target, source_parent):
 		target.qty = flt(obj.qty) - flt(obj.received_qty)
@@ -223,8 +223,8 @@
 	from frappe.model.mapper import get_mapped_doc
 	
 	def set_missing_values(source, target):
-		bean = frappe.get_doc(target)
-		bean.run_method("set_missing_values")
+		doc = frappe.get_doc(target)
+		doc.run_method("set_missing_values")
 
 	def update_item(obj, target, source_parent):
 		target.amount = flt(obj.amount) - flt(obj.billed_amt)
diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py
index 0acb836..3580233 100644
--- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py
+++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py
@@ -26,8 +26,8 @@
 		self.assertEquals(len(pr), len(test_records[0]))
 		
 		pr[0]["naming_series"] = "_T-Purchase Receipt-"
-		pr_bean = frappe.get_doc(pr)
-		pr_bean.insert()
+		pr_doc = frappe.get_doc(pr)
+		pr_doc.insert()
 			
 	def test_ordered_qty(self):
 		frappe.db.sql("delete from tabBin")
@@ -54,9 +54,9 @@
 		pr[0]["posting_date"] = "2013-05-12"
 		pr[0]["naming_series"] = "_T-Purchase Receipt-"
 		pr[1]["qty"] = 4.0
-		pr_bean = frappe.get_doc(pr)
-		pr_bean.insert()
-		pr_bean.submit()
+		pr_doc = frappe.get_doc(pr)
+		pr_doc.insert()
+		pr_doc.submit()
 		
 		self.assertEquals(flt(frappe.db.get_value("Bin", {"item_code": "_Test Item", 
 			"warehouse": "_Test Warehouse - _TC"}, "ordered_qty")), 6.0)
@@ -67,9 +67,9 @@
 		pr1[0]["naming_series"] = "_T-Purchase Receipt-"
 		pr1[0]["posting_date"] = "2013-05-12"
 		pr1[1]["qty"] = 8
-		pr1_bean = frappe.get_doc(pr1)
-		pr1_bean.insert()
-		pr1_bean.submit()
+		pr1_doc = frappe.get_doc(pr1)
+		pr1_doc.insert()
+		pr1_doc.submit()
 		
 		self.assertEquals(flt(frappe.db.get_value("Bin", {"item_code": "_Test Item", 
 			"warehouse": "_Test Warehouse - _TC"}, "ordered_qty")), 0.0)
diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py
index ff7e6df..e937735 100644
--- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py
+++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py
@@ -55,9 +55,9 @@
 	from frappe.model.mapper import get_mapped_doc
 	
 	def set_missing_values(source, target):
-		bean = frappe.get_doc(target)
-		bean.run_method("set_missing_values")
-		bean.run_method("get_schedule_dates")
+		doc = frappe.get_doc(target)
+		doc.run_method("set_missing_values")
+		doc.run_method("get_schedule_dates")
 
 	def update_item(obj, target, source_parent):
 		target.conversion_factor = 1
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 083f0a6..1b050d7 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -86,15 +86,16 @@
 	def set_missing_item_details(self):
 		"""set missing item values"""
 		from erpnext.stock.get_item_details import get_item_details
-		for item in self.get(self.fname):
-			if item.get("item_code"):
-				args = item.fields.copy()
-				args.update(self.fields)
-				ret = get_item_details(args)
-				for fieldname, value in ret.items():
-					if self.meta.get_field(fieldname, parentfield=self.fname) and \
-						item.get(fieldname) is None and value is not None:
-							item.set(fieldname, value)
+		if hasattr(self, "fname"):
+			for item in self.get(self.fname):
+				if item.get("item_code"):
+					args = item.as_dict()
+					args.update(self.as_dict())
+					ret = get_item_details(args)
+					for fieldname, value in ret.items():
+						if self.meta.get_field(fieldname, parentfield=self.fname) and \
+							item.get(fieldname) is None and value is not None:
+								item.set(fieldname, value)
 							
 	def set_taxes(self, tax_parentfield, tax_master_field):
 		if not self.meta.get_field(tax_parentfield):
diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py
index 77b62ca..bcc46bb 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -32,12 +32,12 @@
 			self.set_taxes("other_charges", "taxes_and_charges")
 					
 	def set_missing_lead_customer_details(self):
-		if self.customer:
+		if getattr(self, "customer", None):
 			from erpnext.accounts.party import _get_party_details
 			self.update_if_missing(_get_party_details(self.customer,
 				ignore_permissions=self.ignore_permissions))
 		
-		elif self.lead:
+		elif getattr(self, "lead", None):
 			from erpnext.selling.doctype.lead.lead import get_lead_details
 			self.update_if_missing(get_lead_details(self.lead))
 	
diff --git a/erpnext/home/__init__.py b/erpnext/home/__init__.py
index 25e92aa..ea8997a 100644
--- a/erpnext/home/__init__.py
+++ b/erpnext/home/__init__.py
@@ -86,7 +86,7 @@
 	if method in ['on_update', 'on_submit']:
 		subject, color = feed_dict.get(doc.doctype, [None, None])
 		if subject:
-			make_feed('', doc.doctype, doc.name, doc.owner, subject % doc.fields, color)
+			make_feed('', doc.doctype, doc.name, doc.owner, subject % doc.as_dict(), color)
 
 def make_comment_feed(doc, method):
 	"""add comment to feed"""
diff --git a/erpnext/hr/doctype/department/test_records.json b/erpnext/hr/doctype/department/test_records.json
index 0637a08..5bb5871 100644
--- a/erpnext/hr/doctype/department/test_records.json
+++ b/erpnext/hr/doctype/department/test_records.json
@@ -1 +1,4 @@
-[]
\ No newline at end of file
+[
+	{"doctype":"Department", "department_name":"_Test Department"},
+	{"doctype":"Department", "department_name":"_Test Department 1"}
+]
\ No newline at end of file
diff --git a/erpnext/hr/doctype/hr_settings/hr_settings.json b/erpnext/hr/doctype/hr_settings/hr_settings.json
index 15443db..227a3b3 100644
--- a/erpnext/hr/doctype/hr_settings/hr_settings.json
+++ b/erpnext/hr/doctype/hr_settings/hr_settings.json
@@ -43,7 +43,7 @@
  "icon": "icon-cog", 
  "idx": 1, 
  "issingle": 1, 
- "modified": "2014-02-19 17:40:18.000000", 
+ "modified": "2014-02-19 17:40:18.000001", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "HR Settings", 
diff --git a/erpnext/hr/doctype/job_applicant/get_job_applications.py b/erpnext/hr/doctype/job_applicant/get_job_applications.py
index a94325d..e4a8d70 100644
--- a/erpnext/hr/doctype/job_applicant/get_job_applications.py
+++ b/erpnext/hr/doctype/job_applicant/get_job_applications.py
@@ -37,7 +37,7 @@
 			applicant.ignore_mandatory = True
 			applicant.insert()
 		
-		mail.save_attachments_in_doc(applicant.doc)
+		mail.save_attachments_in_doc(applicant)
 				
 		_make(content=mail.content, sender=mail.from_email, subject=mail.subject or "No Subject",
 			doctype="Job Applicant", name=applicant.name, sent_or_received="Received")
diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py
index f2f95bf..e1bc1f9 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.py
+++ b/erpnext/hr/doctype/leave_application/leave_application.py
@@ -136,7 +136,7 @@
 			and (from_date between %(from_date)s and %(to_date)s 
 				or to_date between %(from_date)s and %(to_date)s
 				or %(from_date)s between from_date and to_date)
-			and name != %(name)s""", self.fields, as_dict = 1):
+			and name != %(name)s""", self.as_dict(), as_dict = 1):
  
 			msgprint("Employee : %s has already applied for %s between %s and %s on %s. Please refer Leave Application : <a href=\"#Form/Leave Application/%s\">%s</a>" % (self.employee, cstr(d['leave_type']), formatdate(d['from_date']), formatdate(d['to_date']), formatdate(d['posting_date']), d['name'], d['name']), raise_exception = OverlapError)
 
diff --git a/erpnext/hr/doctype/salary_manager/salary_manager.py b/erpnext/hr/doctype/salary_manager/salary_manager.py
index 5bb0be5..05d73c7 100644
--- a/erpnext/hr/doctype/salary_manager/salary_manager.py
+++ b/erpnext/hr/doctype/salary_manager/salary_manager.py
@@ -129,11 +129,11 @@
 		for ss in ss_list:
 			ss_obj = frappe.get_doc("Salary Slip",ss[0])
 			try:
-				frappe.db.set(ss_obj.doc, 'email_check', cint(self.send_mail))
+				frappe.db.set(ss_obj, 'email_check', cint(self.send_mail))
 				if cint(self.send_email) == 1:
 					ss_obj.send_mail_funct()
 					
-				frappe.db.set(ss_obj.doc, 'docstatus', 1)
+				frappe.db.set(ss_obj, 'docstatus', 1)
 			except Exception,e:
 				not_submitted_ss.append(ss[0])
 				msgprint(e)
diff --git a/erpnext/manufacturing/doctype/production_order/production_order.py b/erpnext/manufacturing/doctype/production_order/production_order.py
index 75f40fa..af92413 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order.py
+++ b/erpnext/manufacturing/doctype/production_order/production_order.py
@@ -153,7 +153,7 @@
 def make_stock_entry(production_order_id, purpose):
 	production_order = frappe.get_doc("Production Order", production_order_id)
 		
-	stock_entry = frappe.new_bean("Stock Entry")
+	stock_entry = frappe.new_doc("Stock Entry")
 	stock_entry.purpose = purpose
 	stock_entry.production_order = production_order_id
 	stock_entry.company = production_order.company
diff --git a/erpnext/manufacturing/doctype/production_order/test_production_order.py b/erpnext/manufacturing/doctype/production_order/test_production_order.py
index 1af4815..d7d4198 100644
--- a/erpnext/manufacturing/doctype/production_order/test_production_order.py
+++ b/erpnext/manufacturing/doctype/production_order/test_production_order.py
@@ -17,9 +17,9 @@
 		frappe.db.sql("""delete from `tabBin`""")
 		frappe.db.sql("""delete from `tabGL Entry`""")
 		
-		pro_bean = frappe.copy_doc(test_records[0])
-		pro_bean.insert()
-		pro_bean.submit()
+		pro_doc = frappe.copy_doc(test_records[0])
+		pro_doc.insert()
+		pro_doc.submit()
 		
 		from erpnext.stock.doctype.stock_entry.test_stock_entry import test_records as se_test_records
 		mr1 = frappe.copy_doc(se_test_records[0])
@@ -31,7 +31,7 @@
 		mr2.insert()
 		mr2.submit()
 		
-		stock_entry = make_stock_entry(pro_bean.name, "Manufacture/Repack")
+		stock_entry = make_stock_entry(pro_doc.name, "Manufacture/Repack")
 		stock_entry = frappe.get_doc(stock_entry)
 		stock_entry.fiscal_year = "_Test Fiscal Year 2013"
 		stock_entry.fg_completed_qty = 4
@@ -40,12 +40,12 @@
 		stock_entry.run_method("get_items")
 		stock_entry.submit()
 		
-		self.assertEqual(frappe.db.get_value("Production Order", pro_bean.name, 
+		self.assertEqual(frappe.db.get_value("Production Order", pro_doc.name, 
 			"produced_qty"), 4)
 		self.assertEqual(frappe.db.get_value("Bin", {"item_code": "_Test FG Item", 
 			"warehouse": "_Test Warehouse 1 - _TC"}, "planned_qty"), 6)
 			
-		return pro_bean.name
+		return pro_doc.name
 			
 	def test_over_production(self):
 		from erpnext.stock.doctype.stock_entry.stock_entry import StockOverProductionError
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 c94a72c..e3fe7c3 100644
--- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
+++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
@@ -214,7 +214,7 @@
 
 		pro_list = []
 		for key in items:
-			pro = frappe.new_bean("Production Order")
+			pro = frappe.new_doc("Production Order")
 			pro.update(items[key])
 			
 			frappe.flags.mute_messages = True
diff --git a/erpnext/selling/doctype/lead/get_leads.py b/erpnext/selling/doctype/lead/get_leads.py
index 661021e..b765db6 100644
--- a/erpnext/selling/doctype/lead/get_leads.py
+++ b/erpnext/selling/doctype/lead/get_leads.py
@@ -34,8 +34,8 @@
 	
 	if mail:
 		# save attachments to parent if from mail
-		bean = frappe.get_doc(parent_doctype, parent_name)
-		mail.save_attachments_in_doc(bean.doc)
+		doc = frappe.get_doc(parent_doctype, parent_name)
+		mail.save_attachments_in_doc(doc)
 
 class SalesMailbox(POP3Mailbox):	
 	def setup(self, args=None):
diff --git a/erpnext/selling/doctype/lead/lead.py b/erpnext/selling/doctype/lead/lead.py
index df57cf5..2c16a1d 100644
--- a/erpnext/selling/doctype/lead/lead.py
+++ b/erpnext/selling/doctype/lead/lead.py
@@ -42,8 +42,7 @@
 			"owner": self.lead_owner,
 			"subject": ('Contact ' + cstr(self.lead_name)),
 			"description": ('Contact ' + cstr(self.lead_name)) + \
-				(self.contact_by and ('. By : ' + cstr(self.contact_by)) or '') + \
-				(self.remark and ('.To Discuss : ' + cstr(self.remark)) or '')
+				(self.contact_by and ('. By : ' + cstr(self.contact_by)) or '')
 		}, force)
 
 	def check_email_id_is_unique(self):
@@ -117,7 +116,7 @@
 			}
 		}}, target_doc)
 		
-	return [d if isinstance(d, dict) else d.fields for d in doclist]
+	return doclist
 	
 @frappe.whitelist()
 def get_lead_details(lead):
@@ -126,8 +125,8 @@
 	from erpnext.accounts.party import set_address_details
 	out = frappe._dict()
 	
-	lead_bean = frappe.get_doc("Lead", lead)
-	lead = lead_bean.doc
+	lead_doc = frappe.get_doc("Lead", lead)
+	lead = lead_doc
 		
 	out.update({
 		"territory": lead.territory,
diff --git a/erpnext/selling/doctype/lead/test_lead.py b/erpnext/selling/doctype/lead/test_lead.py
index 697f2e1..b2533e0 100644
--- a/erpnext/selling/doctype/lead/test_lead.py
+++ b/erpnext/selling/doctype/lead/test_lead.py
@@ -3,11 +3,11 @@
 
 from __future__ import unicode_literals
 
-test_records = frappe.get_test_records('Lead')
-
 import frappe
 import unittest
 
+test_records = frappe.get_test_records('Lead')
+
 class TestLead(unittest.TestCase):
 	def test_make_customer(self):
 		print "test_make_customer"
diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py
index 42b3596..d420e96 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.py
+++ b/erpnext/selling/doctype/sales_order/sales_order.py
@@ -253,8 +253,8 @@
 		return "order" if self.docstatus==1 else None
 		
 def set_missing_values(source, target):
-	bean = frappe.get_doc(target)
-	bean.run_method("onload_post_render")
+	doc = frappe.get_doc(target)
+	doc.run_method("onload_post_render")
 	
 @frappe.whitelist()
 def make_material_request(source_name, target_doc=None):	
@@ -277,7 +277,7 @@
 		}
 	}, target_doc, postprocess)
 	
-	return [(d if isinstance(d, dict) else d.fields) for d in doclist]
+	return doclist
 
 @frappe.whitelist()
 def make_delivery_note(source_name, target_doc=None):	
@@ -322,9 +322,9 @@
 @frappe.whitelist()
 def make_sales_invoice(source_name, target_doc=None):
 	def set_missing_values(source, target):
-		bean = frappe.get_doc(target)
-		bean.is_pos = 0
-		bean.run_method("onload_post_render")
+		doc = frappe.get_doc(target)
+		doc.is_pos = 0
+		doc.run_method("onload_post_render")
 		
 	def update_item(obj, target, source_parent):
 		target.amount = flt(obj.amount) - flt(obj.billed_amt)
diff --git a/erpnext/selling/doctype/sales_order/test_sales_order.py b/erpnext/selling/doctype/sales_order/test_sales_order.py
index e56de33..435ad65 100644
--- a/erpnext/selling/doctype/sales_order/test_sales_order.py
+++ b/erpnext/selling/doctype/sales_order/test_sales_order.py
@@ -281,21 +281,20 @@
 
 	def test_warehouse_user(self):
 		frappe.defaults.add_default("Warehouse", "_Test Warehouse 1 - _TC1", "test@example.com", "Restriction")
-		frappe.get_doc("User", "test@example.com").get_controller()\
+		frappe.get_doc("User", "test@example.com")\
 			.add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
 			
-		frappe.get_doc("User", "test2@example.com").get_controller()\
+		frappe.get_doc("User", "test2@example.com")\
 			.add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
 		
 		frappe.set_user("test@example.com")
 
-		from frappe.model.bean import BeanPermissionError
 		so = frappe.copy_doc(test_records[0])
 		so.company = "_Test Company 1"
 		so.conversion_rate = 0.02
 		so.plc_conversion_rate = 0.02
 		so.doclist[1].warehouse = "_Test Warehouse 2 - _TC1"
-		self.assertRaises(BeanPermissionError, so.insert)
+		self.assertRaises(frappe.PermissionError, so.insert)
 
 		frappe.set_user("test2@example.com")
 		so.insert()
diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py
index 1880ffd..111a180 100644
--- a/erpnext/setup/doctype/company/company.py
+++ b/erpnext/setup/doctype/company/company.py
@@ -78,7 +78,7 @@
 					"title": self.name + " Home",
 					"published": 1,
 					"description": "Standard Home Page for " + self.name,
-					"main_section": webfile.read() % self.fields
+					"main_section": webfile.read() % self.as_dict()
 				}).insert()
 			
 				# update in home page in settings
@@ -163,12 +163,12 @@
 		]
 		for cc in cc_list:
 			cc.update({"doctype": "Cost Center"})
-			cc_bean = frappe.get_doc(cc)
-			cc_bean.ignore_permissions = True
+			cc_doc = frappe.get_doc(cc)
+			cc_doc.ignore_permissions = True
 		
 			if cc.get("cost_center_name") == self.name:
-				cc_bean.ignore_mandatory = True
-			cc_bean.insert()
+				cc_doc.ignore_mandatory = True
+			cc_doc.insert()
 			
 		frappe.db.set(self, "cost_center", "Main - " + self.abbr)
 
diff --git a/erpnext/setup/doctype/company/test_company.py b/erpnext/setup/doctype/company/test_company.py
index 570cd23..06db121 100644
--- a/erpnext/setup/doctype/company/test_company.py
+++ b/erpnext/setup/doctype/company/test_company.py
@@ -13,7 +13,7 @@
 				print "Country: ", country
 				print "Chart Name: ", chart_name
 				
-				company_bean = frappe.get_doc({
+				company_doc = frappe.get_doc({
 					"doctype": "Company",
 					"company_name": "_Test Company 2",
 					"abbr": "_TC2",
@@ -22,7 +22,7 @@
 					"chart_of_accounts": chart_name
 				})
 
-				company_bean.insert()
+				company_doc.insert()
 				self.assertTrue(frappe.db.sql("""select count(*) from tabAccount 
 					where company='_Test Company 2'""")[0][0] > 10)
 				
diff --git a/erpnext/setup/doctype/global_defaults/global_defaults.py b/erpnext/setup/doctype/global_defaults/global_defaults.py
index a9896dc..dce4f60 100644
--- a/erpnext/setup/doctype/global_defaults/global_defaults.py
+++ b/erpnext/setup/doctype/global_defaults/global_defaults.py
@@ -60,13 +60,13 @@
 					raise_exception=1)
 
 	def update_control_panel(self):
-		cp_bean = frappe.get_doc("Control Panel")
+		cp_doc = frappe.get_doc("Control Panel")
 		if self.country:
-			cp_bean.country = self.country
+			cp_doc.country = self.country
 		if self.time_zone:
-			cp_bean.time_zone = self.time_zone
-		cp_bean.ignore_permissions = True
-		cp_bean.save()
+			cp_doc.time_zone = self.time_zone
+		cp_doc.ignore_permissions = True
+		cp_doc.save()
 
 	def get_defaults(self):
 		return frappe.defaults.get_defaults()
diff --git a/erpnext/setup/doctype/item_group/test_item_group.py b/erpnext/setup/doctype/item_group/test_item_group.py
index ae23499..6f1d4db 100644
--- a/erpnext/setup/doctype/item_group/test_item_group.py
+++ b/erpnext/setup/doctype/item_group/test_item_group.py
@@ -183,9 +183,9 @@
 		for name in frappe.db.sql_list("""select name from `tabItem Group`
 			where parent_item_group='_Test Item Group C'"""):
 			
-			bean = frappe.get_doc("Item Group", name)
-			bean.parent_item_group = "_Test Item Group B"
-			bean.save()
+			doc = frappe.get_doc("Item Group", name)
+			doc.parent_item_group = "_Test Item Group B"
+			doc.save()
 
 		self.test_basic_tree()
 		
diff --git a/erpnext/setup/doctype/naming_series/naming_series.py b/erpnext/setup/doctype/naming_series/naming_series.py
index cf2c29f..e93af3c 100644
--- a/erpnext/setup/doctype/naming_series/naming_series.py
+++ b/erpnext/setup/doctype/naming_series/naming_series.py
@@ -169,6 +169,6 @@
 				ifnull({fieldname}, '')=''""".format(doctype=doctype, fieldname=fieldname))
 
 def get_default_naming_series(doctype):
-	naming_series = frappe.model.get_meta(doctype).get_field("naming_series").options or ""
+	naming_series = frappe.get_meta(doctype).get_field("naming_series").options or ""
 	naming_series = naming_series.split("\n")
 	return naming_series[0] or naming_series[1]
\ No newline at end of file
diff --git a/erpnext/setup/install.py b/erpnext/setup/install.py
index a7e91d1..6f4669e 100644
--- a/erpnext/setup/install.py
+++ b/erpnext/setup/install.py
@@ -139,7 +139,7 @@
 def set_single_defaults():
 	for dt in frappe.db.sql_list("""select name from `tabDocType` where issingle=1"""):
 		default_values = frappe.db.sql("""select fieldname, `default` from `tabDocField`
-			where parent=%s""", dt, as_dict=True)
+			where parent=%s""", dt)
 		if default_values:
 			try:
 				b = frappe.get_doc(dt, dt)
diff --git a/erpnext/setup/page/setup_wizard/setup_wizard.py b/erpnext/setup/page/setup_wizard/setup_wizard.py
index d635e08..61a3c71 100644
--- a/erpnext/setup/page/setup_wizard/setup_wizard.py
+++ b/erpnext/setup/page/setup_wizard/setup_wizard.py
@@ -202,7 +202,7 @@
 	
 	# scheduler errors digest
 	if companies:
-		edigest = frappe.new_bean("Email Digest")
+		edigest = frappe.new_doc("Email Digest")
 		edigest.update({
 			"name": "Scheduler Errors",
 			"company": companies[0],
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py
index 9b3095d..8dcdde1 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.py
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.py
@@ -222,9 +222,8 @@
 			AND docstatus = 1""", self.name)
 
 		if res:
-			from frappe.model.bean import Bean
 			for r in res:
-				ps = Bean(dt='Packing Slip', dn=r[0])
+				ps = frappe.get_doc('Packing Slip', r[0])
 				ps.cancel()
 			frappe.msgprint(_("Packing Slip(s) Cancelled"))
 
diff --git a/erpnext/stock/doctype/item_price/test_item_price.py b/erpnext/stock/doctype/item_price/test_item_price.py
index a1a10ba..1a430bf 100644
--- a/erpnext/stock/doctype/item_price/test_item_price.py
+++ b/erpnext/stock/doctype/item_price/test_item_price.py
@@ -8,7 +8,7 @@
 class TestItem(unittest.TestCase):
 	def test_duplicate_item(self):
 		from erpnext.stock.doctype.item_price.item_price import ItemPriceDuplicateItem
-		bean = frappe.copy_doc(test_records[0])
-		self.assertRaises(ItemPriceDuplicateItem, bean.insert)
+		doc = frappe.copy_doc(test_records[0])
+		self.assertRaises(ItemPriceDuplicateItem, doc.insert)
 
 test_records = frappe.get_test_records('Item Price')
\ No newline at end of file
diff --git a/erpnext/stock/doctype/landed_cost_wizard/landed_cost_wizard.py b/erpnext/stock/doctype/landed_cost_wizard/landed_cost_wizard.py
index 968969d..e7cb410 100644
--- a/erpnext/stock/doctype/landed_cost_wizard/landed_cost_wizard.py
+++ b/erpnext/stock/doctype/landed_cost_wizard/landed_cost_wizard.py
@@ -34,13 +34,13 @@
 		total_amt = self.get_total_pr_amt(purchase_receipts)
 		
 		for pr in purchase_receipts:
-			pr_bean = frappe.get_doc('Purchase Receipt', pr)
-			pr_items = pr_bean.get("purchase_tax_details")
+			pr_doc = frappe.get_doc('Purchase Receipt', pr)
+			pr_items = pr_doc.get("purchase_tax_details")
 			
 			for lc in self.get("landed_cost_details"):
-				amt = flt(lc.amount) * flt(pr_bean.net_total)/ flt(total_amt)
+				amt = flt(lc.amount) * flt(pr_doc.net_total)/ flt(total_amt)
 				
-				matched_row = pr_bean.get("other_charges", {
+				matched_row = pr_doc.get("other_charges", {
 					"category": "Valuation",
 					"add_deduct_tax": "Add",
 					"charge_type": "Actual",
@@ -48,7 +48,7 @@
 				})
 				
 				if not matched_row:	# add if not exists
-					ch = pr_bean.append("other_charges")
+					ch = pr_doc.append("other_charges")
 					ch.category = 'Valuation'
 					ch.add_deduct_tax = 'Add'
 					ch.charge_type = 'Actual'
@@ -64,8 +64,8 @@
 					matched_row[0].tax_amount = amt
 					matched_row[0].cost_center = lc.cost_center
 					
-			pr_bean.run_method("validate")
-			for d in pr_bean.get_all_children():
+			pr_doc.run_method("validate")
+			for d in pr_doc.get_all_children():
 				d.db_update()
 	
 	def get_total_pr_amt(self, purchase_receipts):
@@ -75,9 +75,9 @@
 			
 	def cancel_pr(self, purchase_receipts):
 		for pr in purchase_receipts:
-			pr_bean = frappe.get_doc("Purchase Receipt", pr)
+			pr_doc = frappe.get_doc("Purchase Receipt", pr)
 			
-			pr_bean.run_method("update_ordered_qty")
+			pr_doc.run_method("update_ordered_qty")
 			
 			frappe.db.sql("""delete from `tabStock Ledger Entry` 
 				where voucher_type='Purchase Receipt' and voucher_no=%s""", pr)
@@ -86,7 +86,7 @@
 			
 	def submit_pr(self, purchase_receipts):
 		for pr in purchase_receipts:
-			pr_bean = frappe.get_doc("Purchase Receipt", pr)
-			pr_bean.run_method("update_ordered_qty")
-			pr_bean.run_method("update_stock")
-			pr_bean.run_method("make_gl_entries")
\ No newline at end of file
+			pr_doc = frappe.get_doc("Purchase Receipt", pr)
+			pr_doc.run_method("update_ordered_qty")
+			pr_doc.run_method("update_stock")
+			pr_doc.run_method("make_gl_entries")
\ No newline at end of file
diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py
index 296dda9..1cabce7 100644
--- a/erpnext/stock/doctype/material_request/material_request.py
+++ b/erpnext/stock/doctype/material_request/material_request.py
@@ -165,11 +165,11 @@
 		self.per_ordered = flt((per_ordered / flt(len(item_doclist))) * 100.0, 2)
 		frappe.db.set_value(self.doctype, self.name, "per_ordered", self.per_ordered)
 		
-def update_completed_qty(bean, method):
-	if bean.doctype == "Stock Entry":
+def update_completed_qty(doc, method):
+	if doc.doctype == "Stock Entry":
 		material_request_map = {}
 		
-		for d in bean.get("mtn_details"):
+		for d in doc.get("mtn_details"):
 			if d.material_request:
 				material_request_map.setdefault(d.material_request, []).append(d.material_request_item)
 			
@@ -182,17 +182,17 @@
 					+ _(mr_doctype.get_label("status")) + " = %s. " % _(mr_obj.status)
 					+ _("Cannot continue."), exc=frappe.InvalidStatusError)
 				
-			_update_requested_qty(bean, mr_obj, mr_items)
+			_update_requested_qty(doc, mr_obj, mr_items)
 			
 			# update ordered percentage and qty
 			mr_obj.update_completed_qty(mr_items)
 			
-def _update_requested_qty(bean, mr_obj, mr_items):
+def _update_requested_qty(doc, mr_obj, mr_items):
 	"""update requested qty (before ordered_qty is updated)"""
 	from erpnext.stock.utils import update_bin
 	for mr_item_name in mr_items:
 		mr_item = mr_obj.get("indent_details", {"name": mr_item_name})
-		se_detail = bean.get("mtn_details", {"material_request": mr_obj.name, 
+		se_detail = doc.get("mtn_details", {"material_request": mr_obj.name, 
 			"material_request_item": mr_item_name})
 	
 		if mr_item and se_detail:
@@ -215,7 +215,7 @@
 				"item_code": se_detail.item_code,
 				"warehouse": se_detail.t_warehouse,
 				"indented_qty": (se_detail.docstatus==2 and 1 or -1) * add_indented_qty,
-				"posting_date": bean.posting_date,
+				"posting_date": doc.posting_date,
 			})
 
 def set_missing_values(source, target_doc):
diff --git a/erpnext/stock/doctype/packing_slip/packing_slip.py b/erpnext/stock/doctype/packing_slip/packing_slip.py
index 1860983..b4b64cd 100644
--- a/erpnext/stock/doctype/packing_slip/packing_slip.py
+++ b/erpnext/stock/doctype/packing_slip/packing_slip.py
@@ -57,7 +57,7 @@
 			(from_case_no BETWEEN %(from_case_no)s AND %(to_case_no)s
 			OR to_case_no BETWEEN %(from_case_no)s AND %(to_case_no)s
 			OR %(from_case_no)s BETWEEN from_case_no AND to_case_no)
-			""", self.fields)
+			""", self.as_dict())
 
 		if res:
 			frappe.msgprint(_("""Case No(s) already in use. Please rectify and try again.
@@ -145,7 +145,7 @@
 			note
 		"""
 		recommended_case_no = frappe.db.sql("""SELECT MAX(to_case_no) FROM `tabPacking Slip`
-			WHERE delivery_note = %(delivery_note)s AND docstatus=1""", self.fields)
+			WHERE delivery_note = %(delivery_note)s AND docstatus=1""", self.as_dict())
 		
 		return cint(recommended_case_no[0][0]) + 1
 		
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
index 8dde16b..59b9c98 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -298,8 +298,8 @@
 	from frappe.model.mapper import get_mapped_doc
 	
 	def set_missing_values(source, target):
-		bean = frappe.get_doc(target)
-		bean.run_method("set_missing_values")
+		doc = frappe.get_doc(target)
+		doc.run_method("set_missing_values")
 
 	doclist = get_mapped_doc("Purchase Receipt", source_name,	{
 		"Purchase Receipt": {
diff --git a/erpnext/stock/doctype/serial_no/serial_no.py b/erpnext/stock/doctype/serial_no/serial_no.py
index cab1424..d6b1ef2 100644
--- a/erpnext/stock/doctype/serial_no/serial_no.py
+++ b/erpnext/stock/doctype/serial_no/serial_no.py
@@ -280,7 +280,7 @@
 		if s.strip()]
 
 def make_serial_no(serial_no, sle):
-	sr = frappe.new_bean("Serial No")
+	sr = frappe.new_doc("Serial No")
 	sr.serial_no = serial_no
 	sr.item_code = sle.item_code
 	sr.warehouse = None
diff --git a/erpnext/stock/doctype/serial_no/test_serial_no.py b/erpnext/stock/doctype/serial_no/test_serial_no.py
index 30368b6..9518e78 100644
--- a/erpnext/stock/doctype/serial_no/test_serial_no.py
+++ b/erpnext/stock/doctype/serial_no/test_serial_no.py
@@ -14,7 +14,7 @@
 
 class TestSerialNo(unittest.TestCase):
 	def test_cannot_create_direct(self):
-		sr = frappe.new_bean("Serial No")
+		sr = frappe.new_doc("Serial No")
 		sr.item_code = "_Test Serialized Item"
 		sr.warehouse = "_Test Warehouse - _TC"
 		sr.serial_no = "_TCSER0001"
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 8841b96..56ba780 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -325,41 +325,41 @@
 		self.make_sl_entries(sl_entries, self.amended_from and 'Yes' or 'No')
 
 	def update_production_order(self):
-		def _validate_production_order(pro_bean):
-			if flt(pro_bean.docstatus) != 1:
+		def _validate_production_order(pro_doc):
+			if flt(pro_doc.docstatus) != 1:
 				frappe.throw(_("Production Order must be submitted") + ": " + 
 					self.production_order)
 					
-			if pro_bean.status == 'Stopped':
+			if pro_doc.status == 'Stopped':
 				msgprint(_("Transaction not allowed against stopped Production Order") + ": " + 
 					self.production_order)
 		
 		if self.production_order:
-			pro_bean = frappe.get_doc("Production Order", self.production_order)
-			_validate_production_order(pro_bean)
-			self.update_produced_qty(pro_bean)
+			pro_doc = frappe.get_doc("Production Order", self.production_order)
+			_validate_production_order(pro_doc)
+			self.update_produced_qty(pro_doc)
 			if self.purpose == "Manufacture/Repack":
-				self.update_planned_qty(pro_bean)
+				self.update_planned_qty(pro_doc)
 			
-	def update_produced_qty(self, pro_bean):
+	def update_produced_qty(self, pro_doc):
 		if self.purpose == "Manufacture/Repack":
-			produced_qty = flt(pro_bean.produced_qty) + \
+			produced_qty = flt(pro_doc.produced_qty) + \
 				(self.docstatus==1 and 1 or -1 ) * flt(self.fg_completed_qty)
 				
-			if produced_qty > flt(pro_bean.qty):
+			if produced_qty > flt(pro_doc.qty):
 				frappe.throw(_("Production Order") + ": " + self.production_order + "\n" +
 					_("Total Manufactured Qty can not be greater than Planned qty to manufacture") 
-					+ "(%s/%s)" % (produced_qty, flt(pro_bean.qty)), StockOverProductionError)
+					+ "(%s/%s)" % (produced_qty, flt(pro_doc.qty)), StockOverProductionError)
 					
-			status = 'Completed' if flt(produced_qty) >= flt(pro_bean.qty) else 'In Process'
+			status = 'Completed' if flt(produced_qty) >= flt(pro_doc.qty) else 'In Process'
 			frappe.db.sql("""update `tabProduction Order` set status=%s, produced_qty=%s 
 				where name=%s""", (status, produced_qty, self.production_order))
 			
-	def update_planned_qty(self, pro_bean):
+	def update_planned_qty(self, pro_doc):
 		from erpnext.stock.utils import update_bin
 		update_bin({
-			"item_code": pro_bean.production_item,
-			"warehouse": pro_bean.fg_warehouse,
+			"item_code": pro_doc.production_item,
+			"warehouse": pro_doc.fg_warehouse,
 			"posting_date": self.posting_date,
 			"planned_qty": (self.docstatus==1 and -1 or 1 ) * flt(self.fg_completed_qty)
 		})
@@ -725,7 +725,7 @@
 		for fieldname, val in return_map[args["purpose"]].items():
 			if args.get(fieldname):
 				ref.fieldname = fieldname
-				ref.doc = frappe.get_doc(val[0], args[fieldname])
+				ref.doc = frappe.get_doc(val[0], args.get(fieldname))
 				ref.parentfields = val[1]
 				break
 				
@@ -748,7 +748,7 @@
 	if not se.purpose in ["Sales Return", "Purchase Return"]:
 		return
 	
-	ref = get_return_doc_and_details(se.fields)
+	ref = get_return_doc_and_details(se)
 	
 	if ref.doc.doctype == "Delivery Note":
 		result = make_return_jv_from_delivery_note(se, ref)
diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py
index 98e1b00..38e99c1 100644
--- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py
@@ -765,7 +765,7 @@
 	def test_warehouse_company_validation(self):
 		set_perpetual_inventory(0)
 		self._clear_stock_account_balance()
-		frappe.get_doc("User", "test2@example.com").get_controller()\
+		frappe.get_doc("User", "test2@example.com")\
 			.add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
 		frappe.set_user("test2@example.com")
 
@@ -778,21 +778,20 @@
 	# permission tests
 	def test_warehouse_user(self):
 		import frappe.defaults
-		from frappe.model.bean import BeanPermissionError
 		set_perpetual_inventory(0)
 		
 		frappe.defaults.add_default("Warehouse", "_Test Warehouse 1 - _TC1", "test@example.com", "Restriction")
 		frappe.defaults.add_default("Warehouse", "_Test Warehouse 2 - _TC1", "test2@example.com", "Restriction")
-		frappe.get_doc("User", "test@example.com").get_controller()\
+		frappe.get_doc("User", "test@example.com")\
 			.add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
-		frappe.get_doc("User", "test2@example.com").get_controller()\
+		frappe.get_doc("User", "test2@example.com")\
 			.add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
 
 		frappe.set_user("test@example.com")
 		st1 = frappe.copy_doc(test_records[0])
 		st1.company = "_Test Company 1"
 		st1.doclist[1].t_warehouse="_Test Warehouse 2 - _TC1"
-		self.assertRaises(BeanPermissionError, st1.insert)
+		self.assertRaises(frappe.PermissionError, st1.insert)
 
 		frappe.set_user("test2@example.com")
 		st1 = frappe.copy_doc(test_records[0])
diff --git a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
index 0482dd3..17d4282 100644
--- a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
+++ b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
@@ -47,7 +47,7 @@
 				frappe.throw("""Not enough quantity (requested: %(actual_qty)s, \
 					current: %(batch_bal)s in Batch <b>%(batch_no)s</b> for Item \
 					<b>%(item_code)s</b> at Warehouse <b>%(warehouse)s</b> \
-					as on %(posting_date)s %(posting_time)s""" % self.fields)
+					as on %(posting_date)s %(posting_time)s""" % self.as_dict())
 
 				self.pop('batch_bal')
 
diff --git a/erpnext/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py b/erpnext/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py
index 770c6df..80354ec 100644
--- a/erpnext/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py
+++ b/erpnext/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py
@@ -34,9 +34,9 @@
 			raise Exception
 			
 	def update_item_master(self):
-		item_bean = frappe.get_doc("Item", self.item_code)
-		item_bean.stock_uom = self.new_stock_uom
-		item_bean.save()
+		item_doc = frappe.get_doc("Item", self.item_code)
+		item_doc.stock_uom = self.new_stock_uom
+		item_doc.save()
 		
 		msgprint(_("Default UOM updated in item ") + self.item_code)
 		
diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py
index 0bb70a5..3b159fc 100644
--- a/erpnext/stock/doctype/warehouse/warehouse.py
+++ b/erpnext/stock/doctype/warehouse/warehouse.py
@@ -22,15 +22,15 @@
 		self.update_parent_account()
 				
 	def update_parent_account(self):
-		if not self.__islocal and (self.create_account_under != 
+		if not getattr(self, "__islocal", None) and (self.create_account_under != 
 			frappe.db.get_value("Warehouse", self.name, "create_account_under")):
 				warehouse_account = frappe.db.get_value("Account", 
 					{"account_type": "Warehouse", "company": self.company, 
 					"master_name": self.name}, ["name", "parent_account"])
 				if warehouse_account and warehouse_account[1] != self.create_account_under:
-					acc_bean = frappe.get_doc("Account", warehouse_account[0])
-					acc_bean.parent_account = self.create_account_under
-					acc_bean.save()
+					acc_doc = frappe.get_doc("Account", warehouse_account[0])
+					acc_doc.parent_account = self.create_account_under
+					acc_doc.save()
 				
 	def on_update(self):
 		self.create_account_head()
@@ -43,7 +43,7 @@
 				if self.get("__islocal") or not frappe.db.get_value(
 						"Stock Ledger Entry", {"warehouse": self.name}):
 					self.validate_parent_account()
-					ac_bean = frappe.get_doc({
+					ac_doc = frappe.get_doc({
 						"doctype": "Account",
 						'account_name': self.warehouse_name, 
 						'parent_account': self.create_account_under, 
@@ -53,10 +53,10 @@
 						"master_name": self.name,
 						"freeze_account": "No"
 					})
-					ac_bean.ignore_permissions = True
-					ac_bean.insert()
+					ac_doc.ignore_permissions = True
+					ac_doc.insert()
 					
-					msgprint(_("Account Head") + ": " + ac_bean.name + _(" created"))
+					msgprint(_("Account Head") + ": " + ac_doc.name + _(" created"))
 	
 	def validate_parent_account(self):
 		if not self.create_account_under:
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index ed23cf7..eeff275 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -46,20 +46,20 @@
 	elif not args.item_code and args.serial_no:
 		args.item_code = get_item_code(serial_no=args.serial_no)
 	
-	item_bean = frappe.get_doc("Item", args.item_code)
-	item = item_bean.doc
+	item_doc = frappe.get_doc("Item", args.item_code)
+	item = item_doc
 
 	validate_item_details(args, item)
 		
-	out = get_basic_details(args, item_bean)
+	out = get_basic_details(args, item_doc)
 	
-	get_party_item_code(args, item_bean, out)
+	get_party_item_code(args, item_doc, out)
 
 	if out.get("warehouse"):
 		out.update(get_available_qty(args.item_code, out.warehouse))
 		out.update(get_projected_qty(item.name, out.warehouse))
 	
-	get_price_list_rate(args, item_bean, out)
+	get_price_list_rate(args, item_doc, out)
 
 	if args.transaction_type == "selling" and cint(args.is_pos):
 		out.update(get_pos_settings_item_details(args.company, args))
@@ -67,8 +67,8 @@
 	apply_pricing_rule(out, args)
 		
 	if args.get("doctype") in ("Sales Invoice", "Delivery Note"):
-		if item_bean.has_serial_no == "Yes" and not args.serial_no:
-			out.serial_no = get_serial_nos_by_fifo(args, item_bean)
+		if item_doc.has_serial_no == "Yes" and not args.serial_no:
+			out.serial_no = get_serial_nos_by_fifo(args, item_doc)
 			
 	if args.transaction_date and item.lead_time_days:
 		out.schedule_date = out.lead_time_date = add_days(args.transaction_date,
@@ -116,8 +116,8 @@
 				_("not a sub-contracted item.") +
 				_("Please select a sub-contracted item or do not sub-contract the transaction."))
 			
-def get_basic_details(args, item_bean):
-	item = item_bean.doc
+def get_basic_details(args, item_doc):
+	item = item_doc
 	
 	from frappe.defaults import get_user_default_as_list
 	user_default_warehouse_list = get_user_default_as_list('warehouse')
@@ -137,7 +137,7 @@
 			if args.transaction_type == "selling" else item.buying_cost_center,
 		"batch_no": None,
 		"item_tax_rate": json.dumps(dict(([d.tax_type, d.tax_rate] for d in 
-			item_bean.get("item_tax")))),
+			item_doc.get("item_tax")))),
 		"uom": item.stock_uom,
 		"min_order_qty": flt(item.min_order_qty) if args.doctype == "Material Request" else "",
 		"conversion_factor": 1.0,
@@ -156,7 +156,7 @@
 			
 	return out
 	
-def get_price_list_rate(args, item_bean, out):
+def get_price_list_rate(args, item_doc, out):
 	meta = frappe.get_meta(args.doctype)
 
 	if meta.get_field("currency"):
@@ -173,7 +173,7 @@
 		
 		if not out.price_list_rate and args.transaction_type == "buying":
 			from erpnext.stock.doctype.item.item import get_last_purchase_details
-			out.update(get_last_purchase_details(item_bean.name, 
+			out.update(get_last_purchase_details(item_doc.name, 
 				args.docname, args.conversion_rate))
 			
 def validate_price_list(args):
@@ -207,12 +207,12 @@
 			get_field_precision(meta.get_field("plc_conversion_rate"), 
 			frappe._dict({"fields": args})))
 	
-def get_party_item_code(args, item_bean, out):
+def get_party_item_code(args, item_doc, out):
 	if args.transaction_type == "selling":
-		customer_item_code = item_bean.get("item_customer_details", {"customer_name": args.customer})
+		customer_item_code = item_doc.get("item_customer_details", {"customer_name": args.customer})
 		out.customer_item_code = customer_item_code[0].ref_code if customer_item_code else None
 	else:
-		item_supplier = item_bean.get({"item_supplier_details", {"supplier": args.supplier})
+		item_supplier = item_doc.get("item_supplier_details", {"supplier": args.supplier})
 		out.supplier_part_no = item_supplier[0].supplier_part_no if item_supplier else None
 		
 
@@ -351,7 +351,7 @@
 
 	return filtered_rules or pricing_rules
 
-def get_serial_nos_by_fifo(args, item_bean):
+def get_serial_nos_by_fifo(args, item_doc):
 	return "\n".join(frappe.db.sql_list("""select name from `tabSerial No` 
 		where item_code=%(item_code)s and warehouse=%(warehouse)s and status='Available' 
 		order by timestamp(purchase_date, purchase_time) asc limit %(qty)s""", {
diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py
index 69d27ba..343f6c9 100644
--- a/erpnext/stock/utils.py
+++ b/erpnext/stock/utils.py
@@ -261,10 +261,10 @@
 						"brand": item.brand,
 					})
 			
-				mr_bean = frappe.get_doc(mr)
-				mr_bean.insert()
-				mr_bean.submit()
-				mr_list.append(mr_bean)
+				mr_doc = frappe.get_doc(mr)
+				mr_doc.insert()
+				mr_doc.submit()
+				mr_list.append(mr_doc)
 
 			except:
 				if frappe.local.message_log:
diff --git a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py
index 1002aba..b9cc0bc 100644
--- a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py
+++ b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py
@@ -203,9 +203,9 @@
 
 	def update_amc_date(self, serial_nos, amc_expiry_date=None):
 		for serial_no in serial_nos:
-			serial_no_bean = frappe.get_doc("Serial No", serial_no)
-			serial_no_bean.amc_expiry_date = amc_expiry_date
-			serial_no_bean.save()
+			serial_no_doc = frappe.get_doc("Serial No", serial_no)
+			serial_no_doc.amc_expiry_date = amc_expiry_date
+			serial_no_doc.save()
 
 	def validate_serial_no(self, serial_nos, amc_start_date):
 		for serial_no in serial_nos:
diff --git a/erpnext/support/doctype/support_ticket/get_support_mails.py b/erpnext/support/doctype/support_ticket/get_support_mails.py
index fa3b283..b36437e 100644
--- a/erpnext/support/doctype/support_ticket/get_support_mails.py
+++ b/erpnext/support/doctype/support_ticket/get_support_mails.py
@@ -32,7 +32,7 @@
 			
 		if new_ticket and cint(self.email_settings.send_autoreply) and \
 			"mailer-daemon" not in mail.from_email.lower():
-				self.send_auto_reply(ticket.doc)
+				self.send_auto_reply(ticket)
 
 	def send_auto_reply(self, d):
 		signature = self.email_settings.get('support_signature') or ''
@@ -80,6 +80,6 @@
 		date=mail.date if mail else today(), sent_or_received="Received")
 
 	if mail:
-		mail.save_attachments_in_doc(ticket.doc)
+		mail.save_attachments_in_doc(ticket)
 		
 	return ticket
\ No newline at end of file