[Enhance] Companywise perpetual inventory setting
diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py
index d770af3..553c7b3 100644
--- a/erpnext/controllers/buying_controller.py
+++ b/erpnext/controllers/buying_controller.py
@@ -227,7 +227,7 @@
 				})
 				if not rm.rate:
 					rm.rate = get_valuation_rate(bom_item.item_code, self.supplier_warehouse,
-						self.doctype, self.name, currency=self.company_currency)
+						self.doctype, self.name, currency=self.company_currency, company = self.company)
 			else:
 				rm.rate = bom_item.rate
 
diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py
index 822712f..f8df04d 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -21,7 +21,7 @@
 		if self.docstatus == 2:
 			delete_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
 
-		if cint(frappe.defaults.get_global_default("auto_accounting_for_stock")):
+		if cint(self.get_company_default("enable_perpetual_inventory")):
 			warehouse_account = get_warehouse_account_map()
 
 			if self.docstatus==1:
@@ -95,7 +95,7 @@
 
 	def update_stock_ledger_entries(self, sle):
 		sle.valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse,
-			self.doctype, self.name, currency=self.company_currency)
+			self.doctype, self.name, currency=self.company_currency, company=self.company)
 
 		sle.stock_value = flt(sle.qty_after_transaction) * flt(sle.valuation_rate)
 		sle.stock_value_difference = flt(sle.actual_qty) * flt(sle.valuation_rate)