Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/accounts/doctype/account/account.py b/accounts/doctype/account/account.py
index 763c64b..a717fd3 100644
--- a/accounts/doctype/account/account.py
+++ b/accounts/doctype/account/account.py
@@ -149,7 +149,7 @@
 	# Check user role for approval process
 	def get_authorized_user(self):
 		# Check logged-in user is authorized
-		if get_value('Global Defaults', None, 'credit_controller') in webnotes.user.get_roles():
+		if webnotes.conn.get_value('Global Defaults', None, 'credit_controller') in webnotes.user.get_roles():
 			return 1
 			
 	# Check Credit limit for customer
@@ -160,7 +160,7 @@
 		cr_limit = sql("select t1.credit_limit from tabCustomer t1, `tabAccount` t2 where t2.name='%s' and t1.name = t2.master_name" % account)
 		credit_limit = cr_limit and flt(cr_limit[0][0]) or 0
 		if not credit_limit:
-			credit_limit = get_value('Company', company, 'credit_limit')
+			credit_limit = webnotes.conn.get_value('Company', company, 'credit_limit')
 			credit_limit_from = 'global settings in the Company'
 		
 		# If outstanding greater than credit limit and not authorized person raise exception
diff --git a/accounts/doctype/budget_control/budget_control.py b/accounts/doctype/budget_control/budget_control.py
index 75c938c..2fd321d 100644
--- a/accounts/doctype/budget_control/budget_control.py
+++ b/accounts/doctype/budget_control/budget_control.py
@@ -24,7 +24,6 @@
 from webnotes import msgprint
 
 sql = webnotes.conn.sql
-	
 
 
 class DocType:
@@ -72,7 +71,7 @@
       
       if bgt_flag and bgt_flag[0]['monthly_bgt_flag'] in ['Stop', 'Warn']:
         # get start date and last date
-        st_date = get_value('Fiscal Year', cfy, 'year_start_date').strftime('%Y-%m-%d')
+        st_date = webnotes.conn.get_value('Fiscal Year', cfy, 'year_start_date').strftime('%Y-%m-%d')
         lt_date = sql("select LAST_DAY('%s')" % post_dt)
         
         # get Actual
diff --git a/accounts/doctype/gl_entry/gl_entry.py b/accounts/doctype/gl_entry/gl_entry.py
index 4e20f1b..293a2ee 100644
--- a/accounts/doctype/gl_entry/gl_entry.py
+++ b/accounts/doctype/gl_entry/gl_entry.py
@@ -108,9 +108,9 @@
 	#----------------------------------------------------------------------------------------------
 	def check_freezing_date(self, adv_adj):
 		if not adv_adj:
-			acc_frozen_upto = get_value('Global Defaults', None, 'acc_frozen_upto')
+			acc_frozen_upto = webnotes.conn.get_value('Global Defaults', None, 'acc_frozen_upto')
 			if acc_frozen_upto:
-				bde_auth_role = get_value( 'Global Defaults', None,'bde_auth_role')
+				bde_auth_role = webnotes.conn.get_value( 'Global Defaults', None,'bde_auth_role')
 				if getdate(self.doc.posting_date) <= getdate(acc_frozen_upto) and not bde_auth_role in webnotes.user.get_roles():
 					msgprint("You are not authorized to do/modify back dated accounting entries before %s." % getdate(acc_frozen_upto).strftime('%d-%m-%Y'), raise_exception=1)
 
diff --git a/accounts/doctype/journal_voucher/journal_voucher.py b/accounts/doctype/journal_voucher/journal_voucher.py
index 450b8b8..01b6880 100644
--- a/accounts/doctype/journal_voucher/journal_voucher.py
+++ b/accounts/doctype/journal_voucher/journal_voucher.py
@@ -294,7 +294,7 @@
 			master_type, acc_type = chk_type and cstr(chk_type[0][0]) or '', chk_type and cstr(chk_type[0][1]) or ''
 			if master_type in ['Supplier', 'Customer']:
 				if not self.doc.pay_to_recd_from:
-					self.doc.pay_to_recd_from = get_value(master_type, ' - '.join(d.account.split(' - ')[:-1]), master_type == 'Customer' and 'customer_name' or 'supplier_name')
+					self.doc.pay_to_recd_from = webnotes.conn.get_value(master_type, ' - '.join(d.account.split(' - ')[:-1]), master_type == 'Customer' and 'customer_name' or 'supplier_name')
 			
 			if acc_type == 'Bank or Cash':
 				dcc = TransactionBase().get_company_currency(self.doc.company)
diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py
index cf34cf6..28cf516 100644
--- a/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -60,7 +60,7 @@
 	def get_cust(self):
 		ret = {}
 		if self.doc.credit_to:
-			acc = get_value('Account',self.doc.credit_to,['master_name', 'credit_days'])
+			acc = webnotes.conn.get_value('Account',self.doc.credit_to,['master_name', 'credit_days'])
 			ret['supplier'] = acc[0]
 			ret['due_date'] = add_days(cstr(self.doc.posting_date), acc and cint(acc[1]) or 0)
 			
@@ -384,7 +384,7 @@
 	# get tds rate
 	# -------------
 	def get_tds_rate(self):
-		return {'rate' : flt(get_value('Account', self.doc.tax_code, 'tax_rate'))}
+		return {'rate' : flt(webnotes.conn.get_value('Account', self.doc.tax_code, 'tax_rate'))}
 
 	# set aging date
 	#-------------------
diff --git a/accounts/search_criteria/budget_variance_report/budget_variance_report.py b/accounts/search_criteria/budget_variance_report/budget_variance_report.py
index dbb6b2d..301c19a 100644
--- a/accounts/search_criteria/budget_variance_report/budget_variance_report.py
+++ b/accounts/search_criteria/budget_variance_report/budget_variance_report.py
@@ -149,7 +149,7 @@
 
 
 # get start date
-start_date = get_value('Fiscal Year', fiscal_year, 'year_start_date')
+start_date = webnotes.conn.get_value('Fiscal Year', fiscal_year, 'year_start_date')
 if not start_date:
   msgprint("Please Define Year Start Date for Fiscal Year " + str(fiscal_year))
   raise Exception
diff --git a/buying/doctype/purchase_common/purchase_common.py b/buying/doctype/purchase_common/purchase_common.py
index b2634b0..566c01c 100644
--- a/buying/doctype/purchase_common/purchase_common.py
+++ b/buying/doctype/purchase_common/purchase_common.py
@@ -544,10 +544,10 @@
 			raise Exception
 		
 		#check if tolerance added in item master
-		tolerance = flt(get_value('Item',item_code,'tolerance') or 0)
+		tolerance = flt(webnotes.conn.get_value('Item',item_code,'tolerance') or 0)
 		
 		if not(tolerance):
-			tolerance = flt(get_value('Global Defaults',None,'tolerance') or 0)
+			tolerance = flt(webnotes.conn.get_value('Global Defaults',None,'tolerance') or 0)
 
 		if is_submit:
 			qty = qty + flt(curr_qty)
diff --git a/buying/doctype/purchase_order/purchase_order.py b/buying/doctype/purchase_order/purchase_order.py
index c49c054..4497bcd 100644
--- a/buying/doctype/purchase_order/purchase_order.py
+++ b/buying/doctype/purchase_order/purchase_order.py
@@ -133,7 +133,7 @@
 	def validate(self):
 		self.validate_fiscal_year()
 		# Step 1:=> set status as "Draft"
-		set(self.doc, 'status', 'Draft')
+		webnotes.conn.set(self.doc, 'status', 'Draft')
 		
 		# Step 2:=> get Purchase Common Obj
 		pc_obj = get_obj(dt='Purchase Common')
@@ -213,7 +213,7 @@
 	def update_status(self, status):
 		self.check_modified_date()
 		# step 1:=> Set Status
-		set(self.doc,'status',cstr(status))
+		webnotes.conn.set(self.doc,'status',cstr(status))
 
 		# step 2:=> Update Bin
 		self.update_bin(is_submit = (status == 'Submitted') and 1 or 0, is_stopped = 1)
@@ -243,7 +243,7 @@
 		pc_obj.update_last_purchase_rate(self, is_submit = 1)
 
 		# Step 6 :=> Set Status
-		set(self.doc,'status','Submitted')
+		webnotes.conn.set(self.doc,'status','Submitted')
 	 
 	# On Cancel
 	# -------------------------------------------------------------------------------------------------------
@@ -267,7 +267,7 @@
 			raise Exception
 
 		# 4.Set Status as Cancelled
-		set(self.doc,'status','Cancelled')
+		webnotes.conn.set(self.doc,'status','Cancelled')
 
 		# 5.Update Purchase Requests Pending Qty and accordingly it's Status 
 		pc_obj.update_prevdoc_detail(self,is_submit = 0)
diff --git a/buying/doctype/purchase_request/purchase_request.py b/buying/doctype/purchase_request/purchase_request.py
index f30b722..79c7400 100644
--- a/buying/doctype/purchase_request/purchase_request.py
+++ b/buying/doctype/purchase_request/purchase_request.py
@@ -147,7 +147,7 @@
 		self.validate_fiscal_year()
 		
 		# set status as "Draft"
-		set(self.doc, 'status', 'Draft')
+		webnotes.conn.set(self.doc, 'status', 'Draft')
 
 		# Get Purchase Common Obj
 		pc_obj = get_obj(dt='Purchase Common')
@@ -183,7 +183,7 @@
 				get_obj('Warehouse', d.warehouse).update_bin(args)		
 		
 	def on_submit(self):
-		set(self.doc,'status','Submitted')
+		webnotes.conn.set(self.doc,'status','Submitted')
 		self.update_bin(is_submit = 1, is_stopped = 0)
 	
 	def check_modified_date(self):
@@ -200,7 +200,7 @@
 		self.update_bin(is_submit = (status == 'Submitted') and 1 or 0, is_stopped = 1)
 
 		# Step 2:=> Set status 
-		set(self.doc,'status',cstr(status))
+		webnotes.conn.set(self.doc,'status',cstr(status))
 		
 		# Step 3:=> Acknowledge User
 		msgprint(self.doc.doctype + ": " + self.doc.name + " has been %s." % ((status == 'Submitted') and 'Unstopped' or cstr(status)) )
@@ -219,4 +219,4 @@
 		self.update_bin(is_submit = 0, is_stopped = (cstr(self.doc.status) == 'Stopped') and 1 or 0)
 		
 		# Step 5:=> Set Status
-		set(self.doc,'status','Cancelled')
+		webnotes.conn.set(self.doc,'status','Cancelled')
diff --git a/hr/doctype/attendance/attendance.py b/hr/doctype/attendance/attendance.py
index 3f45825..d3daeb1 100644
--- a/hr/doctype/attendance/attendance.py
+++ b/hr/doctype/attendance/attendance.py
@@ -41,7 +41,7 @@
     emp_nm = sql("select employee_name from `tabEmployee` where name=%s", self.doc.employee)
 
     #this is done because sometimes user entered wrong employee name while uploading employee attendance
-    set(self.doc, 'employee_name', emp_nm and emp_nm[0][0] or '')
+    webnotes.conn.set(self.doc, 'employee_name', emp_nm and emp_nm[0][0] or '')
 
     ret = { 'employee_name' : emp_nm and emp_nm[0][0] or ''}
     return ret
@@ -102,5 +102,5 @@
 
   def on_submit(self):
     #this is done because while uploading attendance chnage docstatus to 1 i.e. submit
-    set(self.doc,'docstatus',1)
+    webnotes.conn.set(self.doc,'docstatus',1)
     pass
diff --git a/hr/doctype/expense_claim/expense_claim.py b/hr/doctype/expense_claim/expense_claim.py
index 66434bb..0bfc318 100644
--- a/hr/doctype/expense_claim/expense_claim.py
+++ b/hr/doctype/expense_claim/expense_claim.py
@@ -65,9 +65,9 @@
 				raise Exception
 			d.save(1)
 		if self.doc.total_sanctioned_amount:
-			set(self.doc,'total_sanctioned_amount',self.doc.total_sanctioned_amount)
+			webnotes.conn.set(self.doc,'total_sanctioned_amount',self.doc.total_sanctioned_amount)
 		if self.doc.remark:
-			set(self.doc, 'remark', self.doc.remark)
+			webnotes.conn.set(self.doc, 'remark', self.doc.remark)
 	
 	def approve_voucher(self):
 		missing_count = 0
@@ -83,7 +83,7 @@
 			return cstr('No Amount')
 		self.update_voucher()
 		
-		set(self.doc, 'approval_status', 'Approved')		
+		webnotes.conn.set(self.doc, 'approval_status', 'Approved')		
 		# on approval notification
 		#get_obj('Notification Control').notify_contact('Expense Claim Approved', self.doc.doctype, self.doc.name, self.doc.email_id, self.doc.employee_name)
 
@@ -92,8 +92,8 @@
 	def reject_voucher(self):
 		
 		if self.doc.remark:
-			set(self.doc, 'remark', self.doc.remark)	 
-		set(self.doc, 'approval_status', 'Rejected')		
+			webnotes.conn.set(self.doc, 'remark', self.doc.remark)	 
+		webnotes.conn.set(self.doc, 'approval_status', 'Rejected')		
 
 		return cstr('Rejected')
 	
@@ -110,7 +110,7 @@
 		self.validate_fiscal_year()
 		
 	def on_update(self):
-		set(self.doc, 'approval_status', 'Draft')
+		webnotes.conn.set(self.doc, 'approval_status', 'Draft')
 	
 	def validate_exp_details(self):
 		if not getlist(self.doclist, 'expense_voucher_details'):
@@ -127,10 +127,10 @@
 		
 	def on_submit(self):
 		self.validate_exp_details()
-		set(self.doc, 'approval_status', 'Submitted')
+		webnotes.conn.set(self.doc, 'approval_status', 'Submitted')
 	
 	def on_cancel(self):
-		set(self.doc, 'approval_status', 'Cancelled')
+		webnotes.conn.set(self.doc, 'approval_status', 'Cancelled')
 
 	def get_formatted_message(self, args):
 		""" get formatted message for auto notification"""
diff --git a/hr/doctype/leave_allocation/leave_allocation.py b/hr/doctype/leave_allocation/leave_allocation.py
index 9e830b9..870a040 100755
--- a/hr/doctype/leave_allocation/leave_allocation.py
+++ b/hr/doctype/leave_allocation/leave_allocation.py
@@ -96,7 +96,7 @@
 			self.doc.leave_type)
 		cf = cf and cint(cf[0][0]) or 0
 		if not cf:
-			set(self.doc,'carry_forward',0)
+			webnotes.conn.set(self.doc,'carry_forward',0)
 			msgprint("Sorry! You cannot carry forward %s" % (self.doc.leave_type),
 				raise_exception=1)
 
@@ -117,8 +117,8 @@
 
 	def get_total_allocated_leaves(self):
 		leave_det = self.get_carry_forwarded_leaves()
-		set(self.doc,'carry_forwarded_leaves',flt(leave_det['carry_forwarded_leaves']))
-		set(self.doc,'total_leaves_allocated',flt(leave_det['total_leaves_allocated']))
+		webnotes.conn.set(self.doc,'carry_forwarded_leaves',flt(leave_det['carry_forwarded_leaves']))
+		webnotes.conn.set(self.doc,'total_leaves_allocated',flt(leave_det['total_leaves_allocated']))
 
 	def check_for_leave_application(self):
 		exists = sql("""select name from `tabLeave Application`
diff --git a/hr/doctype/leave_application/leave_application.py b/hr/doctype/leave_application/leave_application.py
index dcc5b50..91c9d8c 100755
--- a/hr/doctype/leave_application/leave_application.py
+++ b/hr/doctype/leave_application/leave_application.py
@@ -74,8 +74,8 @@
 			bal = self.get_leave_balance()
 			tot_leaves = self.get_total_leave_days()
 			bal, tot_leaves = bal, tot_leaves
-			set(self.doc,'leave_balance',flt(bal['leave_balance']))
-			set(self.doc,'total_leave_days',flt(tot_leaves['total_leave_days']))
+			webnotes.conn.set(self.doc,'leave_balance',flt(bal['leave_balance']))
+			webnotes.conn.set(self.doc,'total_leave_days',flt(tot_leaves['total_leave_days']))
 			if flt(bal['leave_balance']) < flt(tot_leaves['total_leave_days']):
 				msgprint("Warning : There is not enough leave balance")
 
diff --git a/hr/doctype/leave_control_panel/leave_control_panel.py b/hr/doctype/leave_control_panel/leave_control_panel.py
index cb10e71..a2d4fee 100644
--- a/hr/doctype/leave_control_panel/leave_control_panel.py
+++ b/hr/doctype/leave_control_panel/leave_control_panel.py
@@ -70,7 +70,7 @@
     for d in self.get_employees():
       la = Document('Leave Allocation')
       la.employee = cstr(d[0])
-      la.employee_name = get_value('Employee',cstr(d[0]),'employee_name')
+      la.employee_name = webnotes.conn.get_value('Employee',cstr(d[0]),'employee_name')
       la.leave_type = self.doc.leave_type
       la.fiscal_year = self.doc.fiscal_year
       la.posting_date = nowdate()
diff --git a/production/doctype/workstation/workstation.py b/production/doctype/workstation/workstation.py
index fdd4022..1609f6d 100644
--- a/production/doctype/workstation/workstation.py
+++ b/production/doctype/workstation/workstation.py
@@ -36,6 +36,6 @@
         sql("update `tabBOM Operation` set hour_rate = '%s' where parent = '%s' and workstation = '%s'"%( self.doc.hour_rate, bom_no[0], self.doc.name))
   
   def on_update(self):
-    set(self.doc, 'overhead', flt(self.doc.hour_rate_electricity) + flt(self.doc.hour_rate_consumable) + flt(self.doc.hour_rate_rent))
-    set(self.doc, 'hour_rate', flt(self.doc.hour_rate_labour) + flt(self.doc.overhead))
+    webnotes.conn.set(self.doc, 'overhead', flt(self.doc.hour_rate_electricity) + flt(self.doc.hour_rate_consumable) + flt(self.doc.hour_rate_rent))
+    webnotes.conn.set(self.doc, 'hour_rate', flt(self.doc.hour_rate_labour) + flt(self.doc.overhead))
     self.update_bom_operation()
\ No newline at end of file
diff --git a/projects/doctype/timesheet/timesheet.py b/projects/doctype/timesheet/timesheet.py
index 775937e..c2b296f 100644
--- a/projects/doctype/timesheet/timesheet.py
+++ b/projects/doctype/timesheet/timesheet.py
@@ -81,10 +81,10 @@
   
   def on_update(self):
     self.calculate_total_hr()
-    set(self.doc, 'status', 'Draft')
+    webnotes.conn.set(self.doc, 'status', 'Draft')
   
   def on_submit(self):
-    set(self.doc, 'status', 'Submitted')
+    webnotes.conn.set(self.doc, 'status', 'Submitted')
   
   def on_cancel(self):
-    set(self.doc, 'status', 'Cancelled')
\ No newline at end of file
+    webnotes.conn.set(self.doc, 'status', 'Cancelled')
\ No newline at end of file
diff --git a/selling/doctype/customer/customer.py b/selling/doctype/customer/customer.py
index ee5ef54..fa16f45 100644
--- a/selling/doctype/customer/customer.py
+++ b/selling/doctype/customer/customer.py
@@ -52,7 +52,7 @@
 			self.doc.name = make_autoname(self.doc.naming_series+'.#####')
 
 	def get_company_abbr(self):
-		return get_value('Company', self.doc.company, 'abbr')
+		return webnotes.conn.get_value('Company', self.doc.company, 'abbr')
 
 	def get_receivables_group(self):
 		g = sql("select receivables_group from tabCompany where name=%s", self.doc.company)
diff --git a/selling/doctype/installation_note/installation_note.py b/selling/doctype/installation_note/installation_note.py
index 43f5286..1b8590b 100644
--- a/selling/doctype/installation_note/installation_note.py
+++ b/selling/doctype/installation_note/installation_note.py
@@ -171,7 +171,7 @@
       raise Exception
   
   def on_update(self):
-    set(self.doc, 'status', 'Draft')
+    webnotes.conn.set(self.doc, 'status', 'Draft')
   
   def on_submit(self):
     valid_lst = []
@@ -187,7 +187,7 @@
       
       sql("update `tabSerial No` set status = 'Installed' where name = '%s'" % x)
     
-    set(self.doc, 'status', 'Submitted')
+    webnotes.conn.set(self.doc, 'status', 'Submitted')
 
   
   def on_cancel(self):
@@ -204,4 +204,4 @@
     for x in cur_s_no:
       sql("update `tabSerial No` set status = 'Delivered' where name = '%s'" % x)
       
-    set(self.doc, 'status', 'Cancelled')
+    webnotes.conn.set(self.doc, 'status', 'Cancelled')
diff --git a/selling/doctype/quotation/quotation.py b/selling/doctype/quotation/quotation.py
index 3a547a0..37a750f 100644
--- a/selling/doctype/quotation/quotation.py
+++ b/selling/doctype/quotation/quotation.py
@@ -173,7 +173,7 @@
 			else:
 				msgprint("Contact Date Cannot be before Last Contact Date")
 				raise Exception
-			#set(self.doc, 'contact_date_ref',self.doc.contact_date)
+			#webnotes.conn.set(self.doc, 'contact_date_ref',self.doc.contact_date)
 	
 
 	# Validate
@@ -199,10 +199,10 @@
 		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)
+			webnotes.conn.set(self.doc, 'contact_date_ref',self.doc.contact_date)
 		
 		# Set Quotation Status
-		set(self.doc, 'status', 'Draft')
+		webnotes.conn.set(self.doc, 'status', 'Draft')
 
 		# subject for follow
 		self.doc.subject = '[%(status)s] To %(customer)s worth %(currency)s %(grand_total)s' % self.doc.fields
@@ -274,8 +274,8 @@
 			msgprint("Sales Order No. "+cstr(chk[0][0])+" is submitted against this Quotation. Thus 'Order Lost' can not be declared against it.")
 			raise Exception
 		else:
-			set(self.doc, 'status', 'Order Lost')
-			set(self.doc, 'order_lost_reason', arg)
+			webnotes.conn.set(self.doc, 'status', 'Order Lost')
+			webnotes.conn.set(self.doc, 'order_lost_reason', arg)
 			self.update_enquiry('order lost')
 			return 'true'
 	
@@ -291,15 +291,15 @@
 	def on_submit(self):
 		self.check_item_table()
 		if not self.doc.amended_from:
-			set(self.doc, 'message', 'Quotation: '+self.doc.name+' has been sent')
+			webnotes.conn.set(self.doc, 'message', 'Quotation: '+self.doc.name+' has been sent')
 		else:
-			set(self.doc, 'message', 'Quotation has been amended. New Quotation no:'+self.doc.name)
+			webnotes.conn.set(self.doc, 'message', 'Quotation has been amended. New Quotation no:'+self.doc.name)
 		
 		# Check for Approving Authority
 		get_obj('Authorization Control').validate_approving_authority(self.doc.doctype, self.doc.company, self.doc.grand_total, self)
 
 		# Set Quotation Status
-		set(self.doc, 'status', 'Submitted')
+		webnotes.conn.set(self.doc, 'status', 'Submitted')
 		
 		#update enquiry status
 		self.update_enquiry('submit')
@@ -308,12 +308,12 @@
 # ON CANCEL
 # ==========================================================================
 	def on_cancel(self):
-		set(self.doc, 'message', 'Quotation: '+self.doc.name+' has been cancelled')
+		webnotes.conn.set(self.doc, 'message', 'Quotation: '+self.doc.name+' has been cancelled')
 		
 		#update enquiry status
 		self.update_enquiry('cancel')
 		
-		set(self.doc,'status','Cancelled')
+		webnotes.conn.set(self.doc,'status','Cancelled')
 		
 	
 # SEND SMS
diff --git a/selling/doctype/sales_common/sales_common.py b/selling/doctype/sales_common/sales_common.py
index 96314c6..8a1bce8 100644
--- a/selling/doctype/sales_common/sales_common.py
+++ b/selling/doctype/sales_common/sales_common.py
@@ -115,7 +115,7 @@
 	# ====================
 	def get_invoice_details(self, obj = ''):
 		if obj.doc.company:
-			acc_head = webnotes.conn.sql("select name from `tabAccount` where name = '%s' and docstatus != 2" % (cstr(obj.doc.customer) + " - " + get_value('Company', obj.doc.company, 'abbr')))
+			acc_head = webnotes.conn.sql("select name from `tabAccount` where name = '%s' and docstatus != 2" % (cstr(obj.doc.customer) + " - " + webnotes.conn.get_value('Company', obj.doc.company, 'abbr')))
 			obj.doc.debit_to = acc_head and acc_head[0][0] or ''
 
 	
@@ -710,11 +710,11 @@
 		if self.tolerance.get(item_code):
 			return self.tolerance[item_code]
 		
-		tolerance = flt(get_value('Item',item_code,'tolerance') or 0)
+		tolerance = flt(webnotes.conn.get_value('Item',item_code,'tolerance') or 0)
 
 		if not tolerance:
 			if self.global_tolerance == None:
-				self.global_tolerance = flt(get_value('Global Defaults',None,'tolerance') or 0)
+				self.global_tolerance = flt(webnotes.conn.get_value('Global Defaults',None,'tolerance') or 0)
 			tolerance = self.global_tolerance
 		
 		self.tolerance[item_code] = tolerance
diff --git a/selling/doctype/sales_order/sales_order.py b/selling/doctype/sales_order/sales_order.py
index 410a6e1..0a73cac 100644
--- a/selling/doctype/sales_order/sales_order.py
+++ b/selling/doctype/sales_order/sales_order.py
@@ -341,7 +341,7 @@
 		get_obj('Authorization Control').validate_approving_authority(self.doc.doctype, self.doc.grand_total, self)
 		
 		self.update_prevdoc_status('submit')
-		set(self.doc, 'status', 'Submitted')
+		webnotes.conn.set(self.doc, 'status', 'Submitted')
 	
 	def on_cancel(self):
 		# Cannot cancel stopped SO
@@ -353,7 +353,7 @@
 		
 		self.update_prevdoc_status('cancel')
 		
-		set(self.doc, 'status', 'Cancelled')
+		webnotes.conn.set(self.doc, 'status', 'Cancelled')
 		
 	# does not allow to cancel document if DN or RV made against it is SUBMITTED 
 	# ----------------------------------------------------------------------------
@@ -395,14 +395,14 @@
 	def stop_sales_order(self):
 		self.check_modified_date()
 		self.update_stock_ledger(update_stock = -1,clear = 1)
-		set(self.doc, 'status', 'Stopped')
+		webnotes.conn.set(self.doc, 'status', 'Stopped')
 		msgprint("""%s: %s has been Stopped. To make transactions against this Sales Order 
 			you need to Unstop it.""" % (self.doc.doctype, self.doc.name))
 
 	def unstop_sales_order(self):
 		self.check_modified_date()
 		self.update_stock_ledger(update_stock = 1,clear = 1)
-		set(self.doc, 'status', 'Submitted')
+		webnotes.conn.set(self.doc, 'status', 'Submitted')
 		msgprint("%s: %s has been Unstopped" % (self.doc.doctype, self.doc.name))
 
 
diff --git a/selling/search_criteria/sales_persons_target_variance_item_group_wise/sales_persons_target_variance_item_group_wise.py b/selling/search_criteria/sales_persons_target_variance_item_group_wise/sales_persons_target_variance_item_group_wise.py
index 9656a75..3c822a6 100644
--- a/selling/search_criteria/sales_persons_target_variance_item_group_wise/sales_persons_target_variance_item_group_wise.py
+++ b/selling/search_criteria/sales_persons_target_variance_item_group_wise/sales_persons_target_variance_item_group_wise.py
@@ -100,7 +100,7 @@
 
 
 # get start date
-start_date = get_value('Fiscal Year', fiscal_year, 'year_start_date')
+start_date = webnotes.conn.get_value('Fiscal Year', fiscal_year, 'year_start_date')
 if not start_date:
   msgprint("Please Define Year Start Date for Fiscal Year " + str(fiscal_year))
   raise Exception
diff --git a/selling/search_criteria/target_variance_report/target_variance_report.py b/selling/search_criteria/target_variance_report/target_variance_report.py
index ea11f1b..0c14112 100644
--- a/selling/search_criteria/target_variance_report/target_variance_report.py
+++ b/selling/search_criteria/target_variance_report/target_variance_report.py
@@ -88,7 +88,7 @@
 coloptions[col_idx[based_on]]= based_on 
 
 # get start date
-start_date = get_value('Fiscal Year', fiscal_year, 'year_start_date')
+start_date = webnotes.conn.get_value('Fiscal Year', fiscal_year, 'year_start_date')
 if not start_date:
   msgprint("Please Define Year Start Date for Fiscal Year " + str(fiscal_year))
   raise Exception
diff --git a/selling/search_criteria/territories_target_variance_item_group_wise/territories_target_variance_item_group_wise.py b/selling/search_criteria/territories_target_variance_item_group_wise/territories_target_variance_item_group_wise.py
index 0ba3fc3..17acb47 100644
--- a/selling/search_criteria/territories_target_variance_item_group_wise/territories_target_variance_item_group_wise.py
+++ b/selling/search_criteria/territories_target_variance_item_group_wise/territories_target_variance_item_group_wise.py
@@ -95,7 +95,7 @@
 #coloptions[col_idx['Item Group']]= 'Sales '
 
 # get start date
-start_date = get_value('Fiscal Year', fiscal_year, 'year_start_date')
+start_date = webnotes.conn.get_value('Fiscal Year', fiscal_year, 'year_start_date')
 if not start_date:
   msgprint("Please Define Year Start Date for Fiscal Year " + str(fiscal_year))
   raise Exception
diff --git a/selling/search_criteria/total_target_variance_report/total_target_variance_report.py b/selling/search_criteria/total_target_variance_report/total_target_variance_report.py
index a0663fd..954f9f2 100644
--- a/selling/search_criteria/total_target_variance_report/total_target_variance_report.py
+++ b/selling/search_criteria/total_target_variance_report/total_target_variance_report.py
@@ -174,7 +174,7 @@
 #coloptions[col_idx[based_on]]= based_on
 
 # get start date
-start_date = get_value('Fiscal Year', fiscal_year, 'year_start_date')
+start_date = webnotes.conn.get_value('Fiscal Year', fiscal_year, 'year_start_date')
 if not start_date:
   msgprint("Please Define Year Start Date for Fiscal Year " + str(fiscal_year))
   raise Exception
diff --git a/setup/doctype/company/company.py b/setup/doctype/company/company.py
index 83c9f83..8bed425 100644
--- a/setup/doctype/company/company.py
+++ b/setup/doctype/company/company.py
@@ -190,9 +190,9 @@
 	# ---------------------------------------------------
 	def set_default_groups(self):
 		if not self.doc.receivables_group:
-			set(self.doc, 'receivables_group', 'Accounts Receivable - '+self.doc.abbr)
+			webnotes.conn.set(self.doc, 'receivables_group', 'Accounts Receivable - '+self.doc.abbr)
 		if not self.doc.payables_group:
-			set(self.doc, 'payables_group', 'Accounts Payable - '+self.doc.abbr)
+			webnotes.conn.set(self.doc, 'payables_group', 'Accounts Payable - '+self.doc.abbr)
 			
 			
 	# Create default cost center
diff --git a/stock/doctype/delivery_note/delivery_note.py b/stock/doctype/delivery_note/delivery_note.py
index 5b756cf..ece9936 100644
--- a/stock/doctype/delivery_note/delivery_note.py
+++ b/stock/doctype/delivery_note/delivery_note.py
@@ -256,7 +256,7 @@
 		self.credit_limit()
 
 		# set DN status
-		set(self.doc, 'status', 'Submitted')
+		webnotes.conn.set(self.doc, 'status', 'Submitted')
 
 
 	def validate_packed_qty(self):
@@ -294,7 +294,7 @@
 		
 		sales_com_obj.update_prevdoc_detail(0,self)
 		self.update_stock_ledger(update_stock = -1)
-		set(self.doc, 'status', 'Cancelled')
+		webnotes.conn.set(self.doc, 'status', 'Cancelled')
 		self.cancel_packing_slips()
 
 
diff --git a/stock/doctype/purchase_receipt/purchase_receipt.py b/stock/doctype/purchase_receipt/purchase_receipt.py
index 84cf47b..6b7720b 100644
--- a/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -162,7 +162,7 @@
 	def validate(self):
 		self.po_required()
 		self.validate_fiscal_year()
-		set(self.doc, 'status', 'Draft')			 # set status as "Draft"
+		webnotes.conn.set(self.doc, 'status', 'Draft')			 # set status as "Draft"
 		self.validate_accepted_rejected_qty()
 		self.validate_inspection()						 # Validate Inspection
 		get_obj('Stock Ledger').validate_serial_no(self, 'purchase_receipt_details')
@@ -301,7 +301,7 @@
 		get_obj('Authorization Control').validate_approving_authority(self.doc.doctype, self.doc.company, self.doc.grand_total)
 
 		# Set status as Submitted
-		set(self.doc,'status', 'Submitted')
+		webnotes.conn.set(self.doc,'status', 'Submitted')
 		pc_obj = get_obj('Purchase Common')
 
 		# Update Previous Doc i.e. update pending_qty and Status accordingly
@@ -340,7 +340,7 @@
 			raise Exception
 
 		# 2.Set Status as Cancelled
-		set(self.doc,'status','Cancelled')
+		webnotes.conn.set(self.doc,'status','Cancelled')
 
 		# 3. Cancel Serial No
 		get_obj('Stock Ledger').update_serial_record(self, 'purchase_receipt_details', is_submit = 0, is_incoming = 1)
diff --git a/stock/doctype/stock_ledger/stock_ledger.py b/stock/doctype/stock_ledger/stock_ledger.py
index 3235c32..b64abaf 100644
--- a/stock/doctype/stock_ledger/stock_ledger.py
+++ b/stock/doctype/stock_ledger/stock_ledger.py
@@ -75,8 +75,8 @@
 	def validate_serial_no(self, obj, fname):
 		"""check whether serial no is required"""
 		for d in getlist(obj.doclist, fname):
-			is_stock_item = get_value('Item', d.item_code, 'is_stock_item')
-			ar_required = get_value('Item', d.item_code, 'has_serial_no')
+			is_stock_item = webnotes.conn.get_value('Item', d.item_code, 'is_stock_item')
+			ar_required = webnotes.conn.get_value('Item', d.item_code, 'has_serial_no')
 			
 			# [bug fix] need to strip serial nos of all spaces and new lines for validation
 			serial_no = cstr(d.serial_no).strip()
@@ -237,7 +237,7 @@
 		for k in args.keys():
 			# adds warehouse_type
 			if k == 'warehouse':
-				sle.fields['warehouse_type'] = get_value('Warehouse' , args[k], 'warehouse_type')
+				sle.fields['warehouse_type'] = webnotes.conn.get_value('Warehouse' , args[k], 'warehouse_type')
 			sle.fields[k] = args[k]
 		sle_obj = get_obj(doc=sle)
 		
diff --git a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
index 3214435..facd052 100644
--- a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
+++ b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
@@ -84,9 +84,9 @@
 	# Nobody can do SL Entries where posting date is before freezing date except authorized person
 	#----------------------------------------------------------------------------------------------
 	def check_stock_frozen_date(self):
-		stock_frozen_upto = get_value('Global Defaults', None, 'stock_frozen_upto') or ''
+		stock_frozen_upto = webnotes.conn.get_value('Global Defaults', None, 'stock_frozen_upto') or ''
 		if stock_frozen_upto:
-			stock_auth_role = get_value('Global Defaults', None,'stock_auth_role')
+			stock_auth_role = webnotes.conn.get_value('Global Defaults', None,'stock_auth_role')
 			if getdate(self.doc.posting_date) <= getdate(stock_frozen_upto) and not stock_auth_role in webnotes.user.get_roles():
 				msgprint("You are not authorized to do / modify back dated stock entries before %s" % getdate(stock_frozen_upto).strftime('%d-%m-%Y'), raise_exception=1)
 
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 a02afe9..0af37d6 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
@@ -32,7 +32,7 @@
 		self.doc, self.doclist = d,dl
 
 	def get_stock_uom(self, item_code):
-		return {'current_stock_uom': cstr(get_value('Item', item_code, 'stock_uom'))}
+		return {'current_stock_uom': cstr(webnotes.conn.get_value('Item', item_code, 'stock_uom'))}
 	
 	def validate_mandatory(self):
 		if not cstr(self.doc.item_code):
diff --git a/stock/doctype/valuation_control/valuation_control.py~ b/stock/doctype/valuation_control/valuation_control.py~
index 82e7fb9..88ce63e 100644
--- a/stock/doctype/valuation_control/valuation_control.py~
+++ b/stock/doctype/valuation_control/valuation_control.py~
@@ -49,7 +49,7 @@
 		tot = 0
 		for s in sr_nos:
 			serial_no = s.strip()
-			tot += flt(get_value('Serial No', serial_no, 'purchase_rate'))
+			tot += flt(webnotes.conn.get_value('Serial No', serial_no, 'purchase_rate'))
 		return tot / len(sr_nos)
 
 
diff --git a/support/doctype/customer_issue/customer_issue.py b/support/doctype/customer_issue/customer_issue.py
index 3d5dba65..44ae891 100644
--- a/support/doctype/customer_issue/customer_issue.py
+++ b/support/doctype/customer_issue/customer_issue.py
@@ -52,7 +52,7 @@
 			msgprint("Maintenance Visit No. "+lst1+" already created against this customer issue. So can not be Cancelled")
 			raise Exception
 		else:
-			set(self.doc, 'status', 'Cancelled')
+			webnotes.conn.set(self.doc, 'status', 'Cancelled')
 
 	def on_update(self):
 		pass
diff --git a/support/doctype/maintenance_schedule/maintenance_schedule.py b/support/doctype/maintenance_schedule/maintenance_schedule.py
index 9196162..b703e56 100644
--- a/support/doctype/maintenance_schedule/maintenance_schedule.py
+++ b/support/doctype/maintenance_schedule/maintenance_schedule.py
@@ -102,7 +102,7 @@
       for key in scheduled_date:
         if email_map[d.incharge_name]:
           self.add_calender_event(key["scheduled_date"],email_map[d.incharge_name],d.item_code)     
-    set(self.doc, 'status', 'Submitted')    
+    webnotes.conn.set(self.doc, 'status', 'Submitted')    
     
 
   def add_calender_event(self,scheduled_date,incharge_email,item_code):
@@ -274,7 +274,7 @@
       sql("update `tabSerial No` set amc_expiry_date = '%s', maintenance_status = 'Under AMC' where name = '%s'"% (amc_end_date,x))
   
   def on_update(self):
-    set(self.doc, 'status', 'Draft')
+    webnotes.conn.set(self.doc, 'status', 'Draft')
   
   #validate that new maintenance start date does not clash with existing mntc end date
   #-------------------------------------------------------------------------------------------------
@@ -334,7 +334,7 @@
     for d in getlist(self.doclist, 'item_maintenance_detail'):
       if d.serial_no:
         self.update_amc_date(d.serial_no, '')
-    set(self.doc, 'status', 'Cancelled')
+    webnotes.conn.set(self.doc, 'status', 'Cancelled')
     sql("delete from `tabEvent` where ref_type='Maintenance Schedule' and ref_name='%s' " %(self.doc.name))
   def on_trash(self):
     sql("delete from `tabEvent` where ref_type='Maintenance Schedule' and ref_name='%s' " %(self.doc.name))
diff --git a/support/doctype/maintenance_visit/maintenance_visit.py b/support/doctype/maintenance_visit/maintenance_visit.py
index bff7f96..98a3f52 100644
--- a/support/doctype/maintenance_visit/maintenance_visit.py
+++ b/support/doctype/maintenance_visit/maintenance_visit.py
@@ -148,11 +148,11 @@
 	
 	def on_submit(self):
 		self.update_customer_issue(1)		
-		set(self.doc, 'status', 'Submitted')
+		webnotes.conn.set(self.doc, 'status', 'Submitted')
 	
 	def on_cancel(self):
 		self.check_if_last_visit()		
-		set(self.doc, 'status', 'Cancelled')
+		webnotes.conn.set(self.doc, 'status', 'Cancelled')
 
 	def on_update(self):
 		pass
diff --git a/utilities/doctype/sms_control/sms_control.py b/utilities/doctype/sms_control/sms_control.py
index 9b80d1e..a1a886e 100644
--- a/utilities/doctype/sms_control/sms_control.py
+++ b/utilities/doctype/sms_control/sms_control.py
@@ -41,7 +41,7 @@
 				d = d.replace(x, '')
 
 			# mobile no validation for erpnext gateway
-			if get_value('SMS Settings', None, 'sms_gateway_url'):
+			if webnotes.conn.webnotes.conn.get_value('SMS Settings', None, 'sms_gateway_url'):
 				mob_no = d
 			else:
 				if not d.startswith("0") and len(d) == 10:
@@ -104,7 +104,7 @@
 			}
 
 		# personalized or erpnext gateway
-		if get_value('SMS Settings', None, 'sms_gateway_url'):
+		if webnotes.conn.get_value('SMS Settings', None, 'sms_gateway_url'):
 			ret = self.send_via_personalized_gateway(arg)
 			msgprint(ret)