Merge branch 'develop' of https://github.com/frappe/erpnext into project-link-for-all-accounts
diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json
index 353ff77..0e238a6 100644
--- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json
+++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json
@@ -19,7 +19,6 @@
   "unlink_payment_on_cancellation_of_invoice",
   "unlink_advance_payment_on_cancelation_of_order",
   "book_asset_depreciation_entry_automatically",
-  "allow_cost_center_in_entry_of_bs_account",
   "add_taxes_from_item_tax_template",
   "automatically_fetch_payment_terms",
   "automatically_process_deferred_accounting_entry",
@@ -109,12 +108,6 @@
    "label": "Book Asset Depreciation Entry Automatically"
   },
   {
-   "default": "0",
-   "fieldname": "allow_cost_center_in_entry_of_bs_account",
-   "fieldtype": "Check",
-   "label": "Allow Cost Center In Entry of Balance Sheet Account"
-  },
-  {
    "default": "1",
    "fieldname": "add_taxes_from_item_tax_template",
    "fieldtype": "Check",
diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.py b/erpnext/accounts/doctype/accounts_settings/accounts_settings.py
index 2473d71..5593466 100644
--- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.py
+++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.py
@@ -20,7 +20,6 @@
 
 		self.validate_stale_days()
 		self.enable_payment_schedule_in_print()
-		self.enable_fields_for_cost_center_settings()
 
 	def validate_stale_days(self):
 		if not self.allow_stale and cint(self.stale_days) <= 0:
@@ -33,8 +32,3 @@
 		for doctype in ("Sales Order", "Sales Invoice", "Purchase Order", "Purchase Invoice"):
 			make_property_setter(doctype, "due_date", "print_hide", show_in_print, "Check")
 			make_property_setter(doctype, "payment_schedule", "print_hide",  0 if show_in_print else 1, "Check")
-
-	def enable_fields_for_cost_center_settings(self):
-		show_field = 0 if cint(self.allow_cost_center_in_entry_of_bs_account) else 1
-		for doctype in ("Sales Invoice", "Purchase Invoice", "Payment Entry"):
-			make_property_setter(doctype, "cost_center", "hidden", show_field, "Check")
diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py
index 291aff3..b03eb16 100644
--- a/erpnext/accounts/doctype/gl_entry/gl_entry.py
+++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py
@@ -72,12 +72,6 @@
 			if not self.cost_center and self.voucher_type != 'Period Closing Voucher':
 				frappe.throw(_("{0} {1}: Cost Center is required for 'Profit and Loss' account {2}. Please set up a default Cost Center for the Company.")
 					.format(self.voucher_type, self.voucher_no, self.account))
-		else:
-			from erpnext.accounts.utils import get_allow_cost_center_in_entry_of_bs_account
-			if not get_allow_cost_center_in_entry_of_bs_account() and self.cost_center:
-				self.cost_center = None
-			if self.project:
-				self.project = None
 
 	def validate_dimensions_for_pl_and_bs(self):
 
diff --git a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py
index 6996c77..23ad1ee 100644
--- a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py
@@ -204,11 +204,8 @@
 		self.assertEqual(jv.inter_company_journal_entry_reference, "")
 		self.assertEqual(jv1.inter_company_journal_entry_reference, "")
 
-	def test_jv_for_enable_allow_cost_center_in_entry_of_bs_account(self):
+	def test_jv_with_cost_centre(self):
 		from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
-		accounts_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 1
-		accounts_settings.save()
 		cost_center = "_Test Cost Center for BS Account - _TC"
 		create_cost_center(cost_center_name="_Test Cost Center for BS Account", company="_Test Company")
 		jv = make_journal_entry("_Test Cash - _TC", "_Test Bank - _TC", 100, cost_center = cost_center, save=False)
@@ -237,15 +234,45 @@
 		for gle in gl_entries:
 			self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center)
 
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 0
-		accounts_settings.save()
+	def test_jv_with_project(self):
+		from erpnext.projects.doctype.project.test_project import make_project
+		project = make_project({
+			'project_name': 'Journal Entry Project',
+			'project_template_name': 'Test Project Template',
+			'start_date': '2020-01-01'
+		})
 
-	def test_jv_account_and_party_balance_for_enable_allow_cost_center_in_entry_of_bs_account(self):
+		jv = make_journal_entry("_Test Cash - _TC", "_Test Bank - _TC", 100, save=False)
+		for d in jv.accounts:
+			d.project = project.project_name
+		jv.voucher_type = "Bank Entry"
+		jv.multi_currency = 0
+		jv.cheque_no = "112233"
+		jv.cheque_date = nowdate()
+		jv.insert()
+		jv.submit()
+
+		expected_values = {
+			"_Test Cash - _TC": {
+				"project": project.project_name
+			},
+			"_Test Bank - _TC": {
+				"project": project.project_name
+			}
+		}
+
+		gl_entries = frappe.db.sql("""select account, project, debit, credit
+			from `tabGL Entry` where voucher_type='Journal Entry' and voucher_no=%s
+			order by account asc""", jv.name, as_dict=1)
+
+		self.assertTrue(gl_entries)
+
+		for gle in gl_entries:
+			self.assertEqual(expected_values[gle.account]["project"], gle.project)
+
+	def test_jv_account_and_party_balance_with_cost_centre(self):
 		from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
 		from erpnext.accounts.utils import get_balance_on
-		accounts_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 1
-		accounts_settings.save()
 		cost_center = "_Test Cost Center for BS Account - _TC"
 		create_cost_center(cost_center_name="_Test Cost Center for BS Account", company="_Test Company")
 		jv = make_journal_entry("_Test Cash - _TC", "_Test Bank - _TC", 100, cost_center = cost_center, save=False)
@@ -261,9 +288,6 @@
 		account_balance = get_balance_on(account="_Test Bank - _TC", cost_center=cost_center)
 		self.assertEqual(expected_account_balance, account_balance)
 
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 0
-		accounts_settings.save()
-
 def make_journal_entry(account1, account2, amount, cost_center=None, posting_date=None, exchange_rate=1, save=True, submit=False, project=None):
 	if not cost_center:
 		cost_center = "_Test Cost Center - _TC"
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index d2245d6..cfcefff 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -6,7 +6,7 @@
 import frappe, erpnext, json
 from frappe import _, scrub, ValidationError
 from frappe.utils import flt, comma_or, nowdate, getdate
-from erpnext.accounts.utils import get_outstanding_invoices, get_account_currency, get_balance_on, get_allow_cost_center_in_entry_of_bs_account
+from erpnext.accounts.utils import get_outstanding_invoices, get_account_currency, get_balance_on
 from erpnext.accounts.party import get_party_account
 from erpnext.accounts.doctype.journal_entry.journal_entry import get_default_bank_cash_account
 from erpnext.setup.utils import get_exchange_rate
@@ -654,7 +654,7 @@
 			.format(frappe.db.escape(args["voucher_type"]), frappe.db.escape(args["voucher_no"]))
 
 	# Add cost center condition
-	if args.get("cost_center") and get_allow_cost_center_in_entry_of_bs_account():
+	if args.get("cost_center"):
 		condition += " and cost_center='%s'" % args.get("cost_center")
 
 	date_fields_dict = {
diff --git a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py
index 8bb741f..772fc1a 100644
--- a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py
@@ -460,11 +460,8 @@
 		outstanding_amount = flt(frappe.db.get_value("Sales Invoice", si.name, "outstanding_amount"))
 		self.assertEqual(outstanding_amount, 0)
 
-	def test_payment_entry_against_sales_invoice_for_enable_allow_cost_center_in_entry_of_bs_account(self):
+	def test_payment_entry_against_sales_invoice_with_cost_centre(self):
 		from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
-		accounts_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 1
-		accounts_settings.save()
 		cost_center = "_Test Cost Center for BS Account - _TC"
 		create_cost_center(cost_center_name="_Test Cost Center for BS Account", company="_Test Company")
 
@@ -499,39 +496,8 @@
 		for gle in gl_entries:
 			self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center)
 
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 0
-		accounts_settings.save()
-
-	def test_payment_entry_against_sales_invoice_for_disable_allow_cost_center_in_entry_of_bs_account(self):
-		accounts_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 0
-		accounts_settings.save()
-		si =  create_sales_invoice(debit_to="Debtors - _TC")
-
-		pe = get_payment_entry("Sales Invoice", si.name, bank_account="_Test Bank - _TC")
-
-		pe.reference_no = "112211-2"
-		pe.reference_date = nowdate()
-		pe.paid_to = "_Test Bank - _TC"
-		pe.paid_amount = si.grand_total
-		pe.insert()
-		pe.submit()
-
-		gl_entries = frappe.db.sql("""select account, cost_center, account_currency, debit, credit,
-			debit_in_account_currency, credit_in_account_currency
-			from `tabGL Entry` where voucher_type='Payment Entry' and voucher_no=%s
-			order by account asc""", pe.name, as_dict=1)
-
-		self.assertTrue(gl_entries)
-
-		for gle in gl_entries:
-			self.assertEqual(gle.cost_center, None)
-
-	def test_payment_entry_against_purchase_invoice_for_enable_allow_cost_center_in_entry_of_bs_account(self):
+	def test_payment_entry_against_purchase_invoice_with_cost_center(self):
 		from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
-		accounts_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 1
-		accounts_settings.save()
 		cost_center = "_Test Cost Center for BS Account - _TC"
 		create_cost_center(cost_center_name="_Test Cost Center for BS Account", company="_Test Company")
 
@@ -566,40 +532,9 @@
 		for gle in gl_entries:
 			self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center)
 
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 0
-		accounts_settings.save()
-
-	def test_payment_entry_against_purchase_invoice_for_disable_allow_cost_center_in_entry_of_bs_account(self):
-		accounts_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 0
-		accounts_settings.save()
-		pi =  make_purchase_invoice(credit_to="Creditors - _TC")
-
-		pe = get_payment_entry("Purchase Invoice", pi.name, bank_account="_Test Bank - _TC")
-
-		pe.reference_no = "112222-2"
-		pe.reference_date = nowdate()
-		pe.paid_from = "_Test Bank - _TC"
-		pe.paid_amount = pi.grand_total
-		pe.insert()
-		pe.submit()
-
-		gl_entries = frappe.db.sql("""select account, cost_center, account_currency, debit, credit,
-			debit_in_account_currency, credit_in_account_currency
-			from `tabGL Entry` where voucher_type='Payment Entry' and voucher_no=%s
-			order by account asc""", pe.name, as_dict=1)
-
-		self.assertTrue(gl_entries)
-
-		for gle in gl_entries:
-			self.assertEqual(gle.cost_center, None)
-
-	def test_payment_entry_account_and_party_balance_for_enable_allow_cost_center_in_entry_of_bs_account(self):
+	def test_payment_entry_account_and_party_balance_with_cost_center(self):
 		from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
 		from erpnext.accounts.utils import get_balance_on
-		accounts_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 1
-		accounts_settings.save()
 		cost_center = "_Test Cost Center for BS Account - _TC"
 		create_cost_center(cost_center_name="_Test Cost Center for BS Account", company="_Test Company")
 
@@ -630,9 +565,6 @@
 		self.assertEqual(expected_party_balance, party_balance)
 		self.assertEqual(expected_party_account_balance, party_account_balance)
 
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 0
-		accounts_settings.save()
-
 def create_payment_terms_template():
 
 	create_payment_term('Basic Amount Receivable')
@@ -665,4 +597,4 @@
 		frappe.get_doc({
 			'doctype': 'Payment Term',
 			'payment_term_name': name
-		}).insert()
\ No newline at end of file
+		}).insert()
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
index 98ba5c7..b8d173b 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
@@ -26,6 +26,7 @@
   "accounting_dimensions_section",
   "cost_center",
   "dimension_col_break",
+  "project",
   "supplier_invoice_details",
   "bill_no",
   "column_break_15",
@@ -1297,6 +1298,12 @@
    "read_only": 1
   },
   {
+   "fieldname": "project",
+   "fieldtype": "Link",
+   "label": "Project",
+   "options": "Project"
+  },
+  {
    "fieldname": "tax_withholding_category",
    "fieldtype": "Link",
    "hidden": 1,
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index aa1d5b5..c77e500 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -459,6 +459,7 @@
 						if self.party_account_currency==self.company_currency else grand_total,
 					"against_voucher": self.return_against if cint(self.is_return) and self.return_against else self.name,
 					"against_voucher_type": self.doctype,
+					"project": self.project,
 					"cost_center": self.cost_center
 				}, self.party_account_currency, item=self)
 			)
@@ -499,6 +500,7 @@
 							"account":  warehouse_account[item.warehouse]['account'],
 							"against": warehouse_account[item.from_warehouse]["account"],
 							"cost_center": item.cost_center,
+							"project": item_row.project or self.project,
 							"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
 							"debit": warehouse_debit_amount,
 						}, warehouse_account[item.warehouse]["account_currency"], item=item))
@@ -508,6 +510,7 @@
 							"account":  warehouse_account[item.from_warehouse]['account'],
 							"against": warehouse_account[item.warehouse]["account"],
 							"cost_center": item.cost_center,
+							"project": item_row.project or self.project,
 							"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
 							"debit": -1 * flt(item.base_net_amount, item.precision("base_net_amount")),
 						}, warehouse_account[item.from_warehouse]["account_currency"], item=item))
@@ -531,7 +534,7 @@
 								"debit": warehouse_debit_amount,
 								"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
 								"cost_center": item.cost_center,
-								"project": item.project
+								"project": item.project or self.project
 							}, account_currency, item=item)
 						)
 
@@ -544,7 +547,7 @@
 								"cost_center": item.cost_center,
 								"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
 								"credit": flt(amount),
-								"project": item.project
+								"project": item.project or self.project
 							}, item=item))
 
 					# sub-contracting warehouse
@@ -557,6 +560,7 @@
 							"account": supplier_warehouse_account,
 							"against": item.expense_account,
 							"cost_center": item.cost_center,
+							"project": item.project or self.project,
 							"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
 							"credit": flt(item.rm_supp_cost)
 						}, warehouse_account[self.supplier_warehouse]["account_currency"], item=item))
@@ -575,7 +579,7 @@
 							"against": self.supplier,
 							"debit": amount,
 							"cost_center": item.cost_center,
-							"project": item.project
+							"project": item.project or self.project
 						}, account_currency, item=item))
 
 					# If asset is bought through this document and not linked to PR
@@ -588,7 +592,7 @@
 							"cost_center": item.cost_center,
 							"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
 							"credit": flt(item.landed_cost_voucher_amount),
-							"project": item.project
+							"project": item.project or self.project
 						}, item=item))
 
 						gl_entries.append(self.get_gl_dict({
@@ -597,7 +601,7 @@
 							"cost_center": item.cost_center,
 							"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
 							"debit": flt(item.landed_cost_voucher_amount),
-							"project": item.project
+							"project": item.project or self.project
 						}, item=item))
 
 						# update gross amount of asset bought through this document
@@ -623,7 +627,8 @@
 									"against": self.supplier,
 									"debit": flt(item.item_tax_amount, item.precision("item_tax_amount")),
 									"remarks": self.remarks or "Accounting Entry for Stock",
-									"cost_center": self.cost_center
+									"cost_center": self.cost_center,
+									"project": item.project or self.project
 								}, item=item)
 							)
 
@@ -652,7 +657,8 @@
 						"debit": base_asset_amount,
 						"debit_in_account_currency": (base_asset_amount
 							if arbnb_currency == self.company_currency else asset_amount),
-						"cost_center": item.cost_center
+						"cost_center": item.cost_center,
+						"project": item.project or self.project
 					}, item=item))
 
 					if item.item_tax_amount:
@@ -662,6 +668,7 @@
 							"against": self.supplier,
 							"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
 							"cost_center": item.cost_center,
+							"project": item.project or self.project,
 							"credit": item.item_tax_amount,
 							"credit_in_account_currency": (item.item_tax_amount
 								if asset_eiiav_currency == self.company_currency else
@@ -678,7 +685,8 @@
 						"debit": base_asset_amount,
 						"debit_in_account_currency": (base_asset_amount
 							if cwip_account_currency == self.company_currency else asset_amount),
-						"cost_center": self.cost_center
+						"cost_center": self.cost_center,
+						"project": item.project or self.project
 					}, item=item))
 
 					if item.item_tax_amount and not cint(erpnext.is_perpetual_inventory_enabled(self.company)):
@@ -689,6 +697,7 @@
 							"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
 							"cost_center": item.cost_center,
 							"credit": item.item_tax_amount,
+							"project": item.project or self.project,
 							"credit_in_account_currency": (item.item_tax_amount
 								if asset_eiiav_currency == self.company_currency else
 									item.item_tax_amount / self.conversion_rate)
@@ -704,7 +713,7 @@
 								"cost_center": item.cost_center,
 								"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
 								"credit": flt(item.landed_cost_voucher_amount),
-								"project": item.project
+								"project": item.project or self.project
 							}, item=item))
 
 							gl_entries.append(self.get_gl_dict({
@@ -713,7 +722,7 @@
 								"cost_center": item.cost_center,
 								"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
 								"debit": flt(item.landed_cost_voucher_amount),
-								"project": item.project
+								"project": item.project or self.project
 							}, item=item))
 
 						# update gross amount of assets bought through this document
@@ -748,7 +757,7 @@
 					"debit": stock_adjustment_amt,
 					"remarks": self.get("remarks") or _("Stock Adjustment"),
 					"cost_center": item.cost_center,
-					"project": item.project
+					"project": item.project or self.project
 				}, account_currency, item=item)
 			)
 
@@ -840,7 +849,8 @@
 						if self.party_account_currency==self.company_currency else self.paid_amount,
 					"against_voucher": self.return_against if cint(self.is_return) and self.return_against else self.name,
 					"against_voucher_type": self.doctype,
-					"cost_center": self.cost_center
+					"cost_center": self.cost_center,
+					"project": self.project
 				}, self.party_account_currency, item=self)
 			)
 
@@ -872,7 +882,8 @@
 						if self.party_account_currency==self.company_currency else self.write_off_amount,
 					"against_voucher": self.return_against if cint(self.is_return) and self.return_against else self.name,
 					"against_voucher_type": self.doctype,
-					"cost_center": self.cost_center
+					"cost_center": self.cost_center,
+					"project": self.project
 				}, self.party_account_currency, item=self)
 			)
 			gl_entries.append(
@@ -1020,7 +1031,7 @@
 
 		# calculate totals again after applying TDS
 		self.calculate_taxes_and_totals()
-	
+
 	def set_status(self, update=False, status=None, update_modified=True):
 		if self.is_new():
 			if self.get('amended_from'):
diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
index 6170005..5cbfad2 100644
--- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
@@ -807,11 +807,8 @@
 		pi_doc = frappe.get_doc('Purchase Invoice', pi.name)
 		self.assertEqual(pi_doc.outstanding_amount, 0)
 
-	def test_purchase_invoice_for_enable_allow_cost_center_in_entry_of_bs_account(self):
+	def test_purchase_invoice_with_cost_center(self):
 		from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
-		accounts_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 1
-		accounts_settings.save()
 		cost_center = "_Test Cost Center for BS Account - _TC"
 		create_cost_center(cost_center_name="_Test Cost Center for BS Account", company="_Test Company")
 
@@ -837,13 +834,7 @@
 		for gle in gl_entries:
 			self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center)
 
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 0
-		accounts_settings.save()
-
-	def test_purchase_invoice_for_disable_allow_cost_center_in_entry_of_bs_account(self):
-		accounts_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 0
-		accounts_settings.save()
+	def test_purchase_invoice_without_cost_center(self):
 		cost_center = "_Test Cost Center - _TC"
 		pi =  make_purchase_invoice(credit_to="Creditors - _TC")
 
@@ -865,7 +856,45 @@
 
 		for gle in gl_entries:
 			self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center)
+	
+	def test_purchase_invoice_with_project_link(self):
+		from erpnext.projects.doctype.project.test_project import make_project
 
+		project = make_project({
+			'project_name': 'Purchase Invoice Project',
+			'project_template_name': 'Test Project Template',
+			'start_date': '2020-01-01'
+		})
+		item_project = make_project({
+			'project_name': 'Purchase Invoice Item Project',
+			'project_template_name': 'Test Project Template',
+			'start_date': '2019-06-01'
+		})
+
+		pi = make_purchase_invoice(credit_to="Creditors - _TC" ,do_not_save=1)
+		pi.items[0].project = item_project.project_name
+		pi.project = project.project_name
+
+		pi.submit()
+
+		expected_values = {
+			"Creditors - _TC": {
+				"project": project.project_name
+			},
+			"_Test Account Cost for Goods Sold - _TC": {
+				"project": item_project.project_name
+			}
+		}
+
+		gl_entries = frappe.db.sql("""select account, cost_center, project, account_currency, debit, credit,
+			debit_in_account_currency, credit_in_account_currency
+			from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no=%s
+			order by account asc""", pi.name, as_dict=1)
+		
+		self.assertTrue(gl_entries)
+		
+		for gle in gl_entries:
+			self.assertEqual(expected_values[gle.account]["project"], gle.project)
 
 def unlink_payment_on_cancel_of_invoice(enable=1):
 	accounts_settings = frappe.get_doc("Accounts Settings")
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index 57dc179..f60f87f 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -790,7 +790,8 @@
 						if self.party_account_currency==self.company_currency else grand_total,
 					"against_voucher": self.return_against if cint(self.is_return) and self.return_against else self.name,
 					"against_voucher_type": self.doctype,
-					"cost_center": self.cost_center
+					"cost_center": self.cost_center,
+					"project": self.project
 				}, self.party_account_currency, item=self)
 			)
 
@@ -845,7 +846,8 @@
 							"credit_in_account_currency": (flt(item.base_net_amount, item.precision("base_net_amount"))
 								if account_currency==self.company_currency
 								else flt(item.net_amount, item.precision("net_amount"))),
-							"cost_center": item.cost_center
+							"cost_center": item.cost_center,
+							"project": item.project or self.project
 						}, account_currency, item=item)
 					)
 
@@ -926,7 +928,8 @@
 							if self.party_account_currency==self.company_currency else flt(self.change_amount),
 						"against_voucher": self.return_against if cint(self.is_return) and self.return_against else self.name,
 						"against_voucher_type": self.doctype,
-						"cost_center": self.cost_center
+						"cost_center": self.cost_center,
+						"project": self.project
 					}, self.party_account_currency, item=self)
 				)
 
@@ -959,7 +962,8 @@
 						else flt(self.write_off_amount, self.precision("write_off_amount"))),
 					"against_voucher": self.return_against if cint(self.is_return) else self.name,
 					"against_voucher_type": self.doctype,
-					"cost_center": self.cost_center
+					"cost_center": self.cost_center,
+					"project": self.project
 				}, self.party_account_currency, item=self)
 			)
 			gl_entries.append(
diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
index c82a249..fc53f88 100644
--- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
@@ -1065,6 +1065,7 @@
 		serial_no = frappe.get_doc({
 			"doctype": "Serial No",
 			"item_code": "_Test Serialized Item With Series",
+			"company": "Wind Power LLC",
 			"serial_no": make_autoname("SR", "Serial No")
 		})
 		serial_no.save()
@@ -1640,11 +1641,8 @@
 		si_doc = frappe.get_doc('Sales Invoice', si.name)
 		self.assertEqual(si_doc.outstanding_amount, 0)
 
-	def test_sales_invoice_for_enable_allow_cost_center_in_entry_of_bs_account(self):
+	def test_sales_invoice_with_cost_center(self):
 		from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
-		accounts_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 1
-		accounts_settings.save()
 		cost_center = "_Test Cost Center for BS Account - _TC"
 		create_cost_center(cost_center_name="_Test Cost Center for BS Account", company="_Test Company")
 
@@ -1669,14 +1667,47 @@
 
 		for gle in gl_entries:
 			self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center)
+	
+	def test_sales_invoice_with_project_link(self):
+		from erpnext.projects.doctype.project.test_project import make_project
 
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 0
-		accounts_settings.save()
+		project = make_project({
+			'project_name': 'Sales Invoice Project',
+			'project_template_name': 'Test Project Template',
+			'start_date': '2020-01-01'
+		})
+		item_project = make_project({
+			'project_name': 'Sales Invoice Item Project',
+			'project_template_name': 'Test Project Template',
+			'start_date': '2019-06-01'
+		})
 
-	def test_sales_invoice_for_disable_allow_cost_center_in_entry_of_bs_account(self):
-		accounts_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 1
-		accounts_settings.save()
+		sales_invoice = create_sales_invoice(do_not_save=1)
+		sales_invoice.items[0].project = item_project.project_name
+		sales_invoice.project = project.project_name
+
+		sales_invoice.submit()
+
+		expected_values = {
+			"Debtors - _TC": {
+				"project": project.project_name
+			},
+			"Sales - _TC": {
+				"project": item_project.project_name
+			}
+		}
+
+		gl_entries = frappe.db.sql("""select account, cost_center, project, account_currency, debit, credit,
+			debit_in_account_currency, credit_in_account_currency
+			from `tabGL Entry` where voucher_type='Sales Invoice' and voucher_no=%s
+			order by account asc""", sales_invoice.name, as_dict=1)
+		
+		self.assertTrue(gl_entries)
+		
+		for gle in gl_entries:
+			self.assertEqual(expected_values[gle.account]["project"], gle.project)
+
+	def test_sales_invoice_without_cost_center(self):
 		cost_center = "_Test Cost Center - _TC"
 		si =  create_sales_invoice(debit_to="Debtors - _TC")
 
@@ -1699,9 +1730,6 @@
 		for gle in gl_entries:
 			self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center)
 
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 0
-		accounts_settings.save()
-
 	def test_deferred_revenue(self):
 		deferred_account = create_account(account_name="Deferred Revenue",
 			parent_account="Current Liabilities - _TC", company="_Test Company")
diff --git a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
index b2294e4..9bc2466 100644
--- a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
+++ b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
@@ -94,6 +94,7 @@
   "accounting_dimensions_section",
   "cost_center",
   "dimension_col_break",
+  "project",
   "section_break_54",
   "page_break"
  ],
@@ -783,12 +784,18 @@
    "fieldtype": "Link",
    "label": "Finance Book",
    "options": "Finance Book"
+  },
+  {
+   "fieldname": "project",
+   "fieldtype": "Link",
+   "label": "Project",
+   "options": "Project"
   }
  ],
  "idx": 1,
  "istable": 1,
  "links": [],
- "modified": "2019-12-04 12:22:38.517710",
+ "modified": "2020-03-11 12:24:41.749986",
  "modified_by": "Administrator",
  "module": "Accounts",
  "name": "Sales Invoice Item",
diff --git a/erpnext/accounts/doctype/subscription/subscription.py b/erpnext/accounts/doctype/subscription/subscription.py
index 0933c7e..fbdaf1b 100644
--- a/erpnext/accounts/doctype/subscription/subscription.py
+++ b/erpnext/accounts/doctype/subscription/subscription.py
@@ -238,6 +238,10 @@
 		Creates a `Sales Invoice`, submits it and returns it
 		"""
 		invoice = frappe.new_doc('Sales Invoice')
+		
+		if not invoice.company:
+			invoice.company = frappe.db.get_value('Global Defaults', None, 'default_company')
+
 		invoice.set_posting_time = 1
 		invoice.posting_date = self.current_invoice_start
 		invoice.customer = self.customer
diff --git a/erpnext/accounts/doctype/subscription/test_subscription.py b/erpnext/accounts/doctype/subscription/test_subscription.py
index 3d96f23..a0784e6 100644
--- a/erpnext/accounts/doctype/subscription/test_subscription.py
+++ b/erpnext/accounts/doctype/subscription/test_subscription.py
@@ -101,6 +101,7 @@
 		subscription.delete()
 
 	def test_invoice_is_generated_at_end_of_billing_period(self):
+		frappe.db.set_value("Global Defaults", None, "default_company", "_Test Company")
 		subscription = frappe.new_doc('Subscription')
 		subscription.customer = '_Test Customer'
 		subscription.start = '2018-01-01'
@@ -116,8 +117,10 @@
 		self.assertEqual(subscription.current_invoice_start, '2018-01-01')
 		self.assertEqual(subscription.status, 'Past Due Date')
 		subscription.delete()
+		frappe.db.set_value("Global Defaults", None, "default_company", None)
 
 	def test_status_goes_back_to_active_after_invoice_is_paid(self):
+		frappe.db.set_value("Global Defaults", None, "default_company", "_Test Company")
 		subscription = frappe.new_doc('Subscription')
 		subscription.customer = '_Test Customer'
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
@@ -141,8 +144,10 @@
 		self.assertEqual(len(subscription.invoices), 1)
 
 		subscription.delete()
+		frappe.db.set_value("Global Defaults", None, "default_company", None)
 
 	def test_subscription_cancel_after_grace_period(self):
+		frappe.db.set_value("Global Defaults", None, "default_company", "_Test Company")
 		settings = frappe.get_single('Subscription Settings')
 		default_grace_period_action = settings.cancel_after_grace
 		settings.cancel_after_grace = 1
@@ -164,8 +169,11 @@
 		settings.cancel_after_grace = default_grace_period_action
 		settings.save()
 		subscription.delete()
+		frappe.db.set_value("Global Defaults", None, "default_company", None)
 
 	def test_subscription_unpaid_after_grace_period(self):
+		frappe.db.set_value("Global Defaults", None, "default_company", "_Test Company")
+
 		settings = frappe.get_single('Subscription Settings')
 		default_grace_period_action = settings.cancel_after_grace
 		settings.cancel_after_grace = 0
@@ -187,8 +195,11 @@
 		settings.cancel_after_grace = default_grace_period_action
 		settings.save()
 		subscription.delete()
+		frappe.db.set_value("Global Defaults", None, "default_company", None)
 
 	def test_subscription_invoice_days_until_due(self):
+		frappe.db.set_value("Global Defaults", None, "default_company", "_Test Company")
+
 		subscription = frappe.new_doc('Subscription')
 		subscription.customer = '_Test Customer'
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
@@ -200,8 +211,11 @@
 		self.assertEqual(subscription.status, 'Active')
 
 		subscription.delete()
+		frappe.db.set_value("Global Defaults", None, "default_company", None)
 
 	def test_subscription_is_past_due_doesnt_change_within_grace_period(self):
+		frappe.db.set_value("Global Defaults", None, "default_company", "_Test Company")
+
 		settings = frappe.get_single('Subscription Settings')
 		grace_period = settings.grace_period
 		settings.grace_period = 1000
@@ -229,6 +243,7 @@
 		settings.grace_period = grace_period
 		settings.save()
 		subscription.delete()
+		frappe.db.set_value("Global Defaults", None, "default_company", None)
 
 	def test_subscription_remains_active_during_invoice_period(self):
 		subscription = frappe.new_doc('Subscription')
@@ -257,6 +272,7 @@
 		subscription.delete()
 
 	def test_subscription_cancelation(self):
+		frappe.db.set_value("Global Defaults", None, "default_company", "_Test Company")
 		subscription = frappe.new_doc('Subscription')
 		subscription.customer = '_Test Customer'
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
@@ -266,8 +282,10 @@
 		self.assertEqual(subscription.status, 'Cancelled')
 
 		subscription.delete()
+		frappe.db.set_value("Global Defaults", None, "default_company", None)
 
 	def test_subscription_cancellation_invoices(self):
+		frappe.db.set_value("Global Defaults", None, "default_company", "_Test Company")
 		settings = frappe.get_single('Subscription Settings')
 		to_prorate = settings.prorate
 		settings.prorate = 1
@@ -301,8 +319,11 @@
 		subscription.delete()
 		settings.prorate = to_prorate
 		settings.save()
+		frappe.db.set_value("Global Defaults", None, "default_company", None)
 
 	def test_subscription_cancellation_invoices_with_prorata_false(self):
+		frappe.db.set_value("Global Defaults", None, "default_company", "_Test Company")
+
 		settings = frappe.get_single('Subscription Settings')
 		to_prorate = settings.prorate
 		settings.prorate = 0
@@ -321,8 +342,11 @@
 		settings.save()
 
 		subscription.delete()
+		frappe.db.set_value("Global Defaults", None, "default_company", None)
 
 	def test_subscription_cancellation_invoices_with_prorata_true(self):
+		frappe.db.set_value("Global Defaults", None, "default_company", "_Test Company")
+
 		settings = frappe.get_single('Subscription Settings')
 		to_prorate = settings.prorate
 		settings.prorate = 1
@@ -345,8 +369,10 @@
 		settings.save()
 
 		subscription.delete()
+		frappe.db.set_value("Global Defaults", None, "default_company", None)
 
 	def test_subcription_cancellation_and_process(self):
+		frappe.db.set_value("Global Defaults", None, "default_company", "_Test Company")
 		settings = frappe.get_single('Subscription Settings')
 		default_grace_period_action = settings.cancel_after_grace
 		settings.cancel_after_grace = 1
@@ -378,8 +404,11 @@
 		settings.cancel_after_grace = default_grace_period_action
 		settings.save()
 		subscription.delete()
+		frappe.db.set_value("Global Defaults", None, "default_company", None)
 
 	def test_subscription_restart_and_process(self):
+		frappe.db.set_value("Global Defaults", None, "default_company", "_Test Company")
+
 		settings = frappe.get_single('Subscription Settings')
 		default_grace_period_action = settings.cancel_after_grace
 		settings.grace_period = 0
@@ -416,8 +445,11 @@
 		settings.cancel_after_grace = default_grace_period_action
 		settings.save()
 		subscription.delete()
+		frappe.db.set_value("Global Defaults", None, "default_company", None)
 
 	def test_subscription_unpaid_back_to_active(self):
+		frappe.db.set_value("Global Defaults", None, "default_company", "_Test Company")
+
 		settings = frappe.get_single('Subscription Settings')
 		default_grace_period_action = settings.cancel_after_grace
 		settings.cancel_after_grace = 0
@@ -450,6 +482,7 @@
 		settings.cancel_after_grace = default_grace_period_action
 		settings.save()
 		subscription.delete()
+		frappe.db.set_value("Global Defaults", None, "default_company", None)
 
 	def test_restart_active_subscription(self):
 		subscription = frappe.new_doc('Subscription')
@@ -462,6 +495,8 @@
 		subscription.delete()
 
 	def test_subscription_invoice_discount_percentage(self):
+		frappe.db.set_value("Global Defaults", None, "default_company", "_Test Company")
+
 		subscription = frappe.new_doc('Subscription')
 		subscription.customer = '_Test Customer'
 		subscription.additional_discount_percentage = 10
@@ -475,8 +510,11 @@
 		self.assertEqual(invoice.apply_discount_on, 'Grand Total')
 
 		subscription.delete()
+		frappe.db.set_value("Global Defaults", None, "default_company", None)
 
 	def test_subscription_invoice_discount_amount(self):
+		frappe.db.set_value("Global Defaults", None, "default_company", "_Test Company")
+
 		subscription = frappe.new_doc('Subscription')
 		subscription.customer = '_Test Customer'
 		subscription.additional_discount_amount = 11
@@ -490,10 +528,12 @@
 		self.assertEqual(invoice.apply_discount_on, 'Grand Total')
 
 		subscription.delete()
+		frappe.db.set_value("Global Defaults", None, "default_company", None)
 
 	def test_prepaid_subscriptions(self):
 		# Create a non pre-billed subscription, processing should not create
 		# invoices.
+		frappe.db.set_value("Global Defaults", None, "default_company", "_Test Company")
 		subscription = frappe.new_doc('Subscription')
 		subscription.customer = '_Test Customer'
 		subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1})
@@ -509,8 +549,10 @@
 		subscription.process()
 
 		self.assertEqual(len(subscription.invoices), 1)
+		frappe.db.set_value("Global Defaults", None, "default_company", None)
 
 	def test_prepaid_subscriptions_with_prorate_true(self):
+		frappe.db.set_value("Global Defaults", None, "default_company", "_Test Company")
 		settings = frappe.get_single('Subscription Settings')
 		to_prorate = settings.prorate
 		settings.prorate = 1
@@ -538,3 +580,4 @@
 		settings.save()
 
 		subscription.delete()
+		frappe.db.set_value("Global Defaults", None, "default_company", None)
\ No newline at end of file
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 5165495..58cd570 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -124,14 +124,12 @@
 			# hence, assuming balance as 0.0
 			return 0.0
 
-	allow_cost_center_in_entry_of_bs_account = get_allow_cost_center_in_entry_of_bs_account()
-
 	if account:
 		report_type = acc.report_type
 	else:
 		report_type = ""
 
-	if cost_center and (allow_cost_center_in_entry_of_bs_account or report_type =='Profit and Loss'):
+	if cost_center and report_type == 'Profit and Loss':
 		cc = frappe.get_doc("Cost Center", cost_center)
 		if cc.is_group:
 			cond.append(""" exists (
@@ -877,11 +875,6 @@
 
 	return accounts
 
-def get_allow_cost_center_in_entry_of_bs_account():
-	def generator():
-		return cint(frappe.db.get_value('Accounts Settings', None, 'allow_cost_center_in_entry_of_bs_account'))
-	return frappe.local_cache("get_allow_cost_center_in_entry_of_bs_account", (), generator, regenerate_if_none=True)
-
 def get_stock_accounts(company):
 	return frappe.get_all("Account", filters = {
 		"account_type": "Stock",
diff --git a/erpnext/assets/doctype/asset/depreciation.py b/erpnext/assets/doctype/asset/depreciation.py
index 522c1fe..ad671ba 100644
--- a/erpnext/assets/doctype/asset/depreciation.py
+++ b/erpnext/assets/doctype/asset/depreciation.py
@@ -10,7 +10,7 @@
 
 def post_depreciation_entries(date=None):
 	# Return if automatic booking of asset depreciation is disabled
-	if not cint(frappe.db.get_single_value("Accounts Settings", "book_asset_depreciation_entry_automatically")):
+	if not cint(frappe.db.get_value("Accounts Settings", None, "book_asset_depreciation_entry_automatically")):
 		return
 
 	if not date:
diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py
index aed78e7..9490c8c 100644
--- a/erpnext/assets/doctype/asset/test_asset.py
+++ b/erpnext/assets/doctype/asset/test_asset.py
@@ -75,6 +75,7 @@
 			'qty': 1,
 			'asset': asset.name
 		})
+		doc.company = 'Wind Power LLC'
 
 		doc.set_missing_values()
 		self.assertEquals(doc.items[0].is_fixed_asset, 1)
@@ -666,7 +667,7 @@
 		"asset_name": args.asset_name or "Macbook Pro 1",
 		"asset_category": "Computers",
 		"item_code": args.item_code or "Macbook Pro",
-		"company": args.company or"_Test Company",
+		"company": args.company or "_Test Company",
 		"purchase_date": "2015-01-01",
 		"calculate_depreciation": 0,
 		"gross_purchase_amount": 100000,
diff --git a/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py b/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py
index bebf0cc..0c840ec 100644
--- a/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py
+++ b/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py
@@ -36,16 +36,18 @@
 		mr = make_material_request(company="_Test Procurement Company", warehouse=warehouse)
 		po = make_purchase_order(mr.name)
 		po.supplier = "_Test Supplier"
-		po.get("items")[0].cost_center = "_Test Cost Center - _TC"
+		po.company = "_Test Procurement Company"
+		po.get("items")[0].cost_center = "_Test Cost Center - _TPC"
 		po.submit()
 		pr = make_purchase_receipt(po.name)
+		pr.company = "_Test Procurement Company"
 		pr.submit()
 		frappe.db.commit()
 		date_obj = datetime.date(datetime.now())
 
 		expected_data = {
 			"material_request_date": date_obj,
-			"cost_center": "_Test Cost Center - _TC",
+			"cost_center": "_Test Cost Center - _TPC",
 			"project": None,
 			"requesting_site": "_Test Procurement Warehouse - _TPC",
 			"requestor": "Administrator",
diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py
index 90d2930..83139b1 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -95,6 +95,7 @@
 							"account": warehouse_account[sle.warehouse]["account"],
 							"against": item_row.expense_account,
 							"cost_center": item_row.cost_center,
+							"project": item_row.project or self.project if hasattr(self, 'project') else None,
 							"remarks": self.get("remarks") or "Accounting Entry for Stock",
 							"debit": flt(sle.stock_value_difference, precision),
 							"is_opening": item_row.get("is_opening") or self.get("is_opening") or "No",
@@ -105,6 +106,7 @@
 							"account": item_row.expense_account,
 							"against": warehouse_account[sle.warehouse]["account"],
 							"cost_center": item_row.cost_center,
+							"project": item_row.project or self.project if hasattr(self, 'project') else None,
 							"remarks": self.get("remarks") or "Accounting Entry for Stock",
 							"credit": flt(sle.stock_value_difference, precision),
 							"project": item_row.get("project") or self.get("project"),
diff --git a/erpnext/controllers/tests/test_mapper.py b/erpnext/controllers/tests/test_mapper.py
index 8839e00..08248be 100644
--- a/erpnext/controllers/tests/test_mapper.py
+++ b/erpnext/controllers/tests/test_mapper.py
@@ -43,6 +43,7 @@
 		qtn = frappe.get_doc({
 			"doctype": "Quotation",
 			"quotation_to": "Customer",
+			"company": "_Test Company",
 			"party_name": customer,
 			"order_type": "Sales",
 			"transaction_date" : nowdate(),
@@ -59,6 +60,7 @@
 			"base_amount": 1000.0,
 			"base_rate": 100.0,
 			"description": "CPU",
+			"company": "_Test Company",
 			"doctype": "Sales Order Item",
 			"item_code": "_Test Item Home Desktop 100",
 			"item_name": "CPU",
diff --git a/erpnext/crm/doctype/opportunity/test_opportunity.py b/erpnext/crm/doctype/opportunity/test_opportunity.py
index 33d9007..fc852b1 100644
--- a/erpnext/crm/doctype/opportunity/test_opportunity.py
+++ b/erpnext/crm/doctype/opportunity/test_opportunity.py
@@ -30,6 +30,7 @@
 		new_lead_email_id = "new{}@example.com".format(random_string(5))
 		args = {
 			"doctype": "Opportunity",
+			"company": "_Test Company",
 			"contact_email": new_lead_email_id,
 			"opportunity_type": "Sales",
 			"with_items": 0,
diff --git a/erpnext/crm/doctype/opportunity/test_records.json b/erpnext/crm/doctype/opportunity/test_records.json
index a1e0ad9..0a6c29b 100644
--- a/erpnext/crm/doctype/opportunity/test_records.json
+++ b/erpnext/crm/doctype/opportunity/test_records.json
@@ -2,6 +2,7 @@
 	{
 		"doctype": "Opportunity",
 		"name": "_Test Opportunity 1",
+		"company": "Wind Power LLC",
 		"opportunity_from": "Lead",
 		"enquiry_type": "Sales",
 		"party_name": "_T-Lead-00001",
diff --git a/erpnext/erpnext_integrations/doctype/plaid_settings/test_plaid_settings.py b/erpnext/erpnext_integrations/doctype/plaid_settings/test_plaid_settings.py
index 1a063d6..8be2510 100644
--- a/erpnext/erpnext_integrations/doctype/plaid_settings/test_plaid_settings.py
+++ b/erpnext/erpnext_integrations/doctype/plaid_settings/test_plaid_settings.py
@@ -108,7 +108,7 @@
 		}
 
 		bank = json.dumps(frappe.get_doc("Bank", "Citi").as_dict(), default=json_handler)
-		company = frappe.db.get_single_value('Global Defaults', 'default_company')
+		company = frappe.db.get_single_value('Global Defaults', 'default_company') or '_Test Company'
 
 		if frappe.db.get_value("Company", company, "default_bank_account") is None:
 			frappe.db.set_value("Company", company, "default_bank_account", get_default_bank_cash_account(company, "Cash").get("account"))
diff --git a/erpnext/healthcare/doctype/clinical_procedure/test_clinical_procedure.py b/erpnext/healthcare/doctype/clinical_procedure/test_clinical_procedure.py
index 207351f..100addc 100644
--- a/erpnext/healthcare/doctype/clinical_procedure/test_clinical_procedure.py
+++ b/erpnext/healthcare/doctype/clinical_procedure/test_clinical_procedure.py
@@ -18,6 +18,7 @@
 		self.assertEquals(frappe.db.get_value('Item', procedure_template.item, 'disabled'), 1)
 
 	def test_consumables(self):
+		frappe.db.set_value('Global Defaults', None, 'default_company', '_Test Company')
 		patient, medical_department, practitioner = create_healthcare_docs()
 		procedure_template = create_clinical_procedure_template()
 		procedure_template.allow_stock_consumption = 1
@@ -38,6 +39,7 @@
 		result = procedure.complete_procedure()
 		# check consumption
 		self.assertTrue(frappe.db.exists('Stock Entry', result))
+		frappe.db.set_value('Global Defaults', None, 'default_company', None)
 
 
 def create_consumable():
diff --git a/erpnext/healthcare/doctype/inpatient_record/test_inpatient_record.py b/erpnext/healthcare/doctype/inpatient_record/test_inpatient_record.py
index 4c2d3f6..c4826c9 100644
--- a/erpnext/healthcare/doctype/inpatient_record/test_inpatient_record.py
+++ b/erpnext/healthcare/doctype/inpatient_record/test_inpatient_record.py
@@ -83,7 +83,8 @@
 		service_unit.service_unit_type = get_service_unit_type()
 		service_unit.inpatient_occupancy = 1
 		service_unit.occupancy_status = "Vacant"
-		service_unit.is_group = 0
+		service_unit.is_group = 0,
+		service_unit.company = "_Test Company"
 		service_unit_parent_name = frappe.db.exists({
 				"doctype": "Healthcare Service Unit",
 				"healthcare_service_unit_name": "All Healthcare Service Units",
diff --git a/erpnext/healthcare/doctype/patient/test_patient.py b/erpnext/healthcare/doctype/patient/test_patient.py
index 9274b6f..dfe61bd 100644
--- a/erpnext/healthcare/doctype/patient/test_patient.py
+++ b/erpnext/healthcare/doctype/patient/test_patient.py
@@ -15,6 +15,7 @@
 		self.assertTrue(frappe.db.get_value('Patient', patient, 'customer'))
 
 	def test_patient_registration(self):
+		frappe.db.set_value('Global Defaults', None, 'default_company', '_Test Company')
 		frappe.db.sql("""delete from `tabPatient`""")
 		settings = frappe.get_single('Healthcare Settings')
 		settings.collect_registration_fee = 1
@@ -32,3 +33,4 @@
 
 		settings.collect_registration_fee = 0
 		settings.save()
+		frappe.db.set_value('Global Defaults', None, 'default_company', None)
diff --git a/erpnext/healthcare/doctype/patient_medical_record/test_patient_medical_record.py b/erpnext/healthcare/doctype/patient_medical_record/test_patient_medical_record.py
index e5a5e4c..4de90bc 100644
--- a/erpnext/healthcare/doctype/patient_medical_record/test_patient_medical_record.py
+++ b/erpnext/healthcare/doctype/patient_medical_record/test_patient_medical_record.py
@@ -13,6 +13,7 @@
 		frappe.db.set_value('Healthcare Settings', None, 'automate_appointment_invoicing', 1)
 
 	def test_medical_record(self):
+		frappe.db.set_value('Global Defaults', None, 'default_company', '_Test Company')
 		patient, medical_department, practitioner = create_healthcare_docs()
 		appointment = create_appointment(patient, practitioner, nowdate(), invoice=1)
 		encounter = create_encounter(appointment)
@@ -38,6 +39,7 @@
 		# check for lab test
 		medical_rec = frappe.db.exists('Patient Medical Record', {'status': 'Open', 'reference_name': lab_test.name})
 		self.assertTrue(medical_rec)
+		frappe.db.set_value('Global Defaults', None, 'default_company', None)
 
 
 def create_procedure(appointment):
diff --git a/erpnext/hr/doctype/compensatory_leave_request/test_compensatory_leave_request.py b/erpnext/hr/doctype/compensatory_leave_request/test_compensatory_leave_request.py
index 1615ab3..1181192 100644
--- a/erpnext/hr/doctype/compensatory_leave_request/test_compensatory_leave_request.py
+++ b/erpnext/hr/doctype/compensatory_leave_request/test_compensatory_leave_request.py
@@ -104,7 +104,8 @@
 				"doctype": "Attendance",
 				"employee": employee.name,
 				"attendance_date": date,
-				"status": status
+				"status": status,
+				"company": "_Test Company"
 		})
 		attendance.save()
 		attendance.submit()
diff --git a/erpnext/hr/doctype/department/test_department.py b/erpnext/hr/doctype/department/test_department.py
index 2eeca26..a6e8aae 100644
--- a/erpnext/hr/doctype/department/test_department.py
+++ b/erpnext/hr/doctype/department/test_department.py
@@ -16,7 +16,7 @@
         'is_group': 0,
         'parent_department': parent_department,
         'department_name': department_name,
-        'company': frappe.defaults.get_defaults().company
+        'company': frappe.defaults.get_defaults().company or 'Wind Power LLC'
     }).insert()
 
     return doc
diff --git a/erpnext/hr/doctype/employee/test_employee.py b/erpnext/hr/doctype/employee/test_employee.py
index f4b214a..b92b8e7 100644
--- a/erpnext/hr/doctype/employee/test_employee.py
+++ b/erpnext/hr/doctype/employee/test_employee.py
@@ -60,7 +60,7 @@
 			"doctype": "Employee",
 			"naming_series": "EMP-",
 			"first_name": user,
-			"company": company or erpnext.get_default_company(),
+			"company": company or erpnext.get_default_company() or 'Wind Power LLC',
 			"user_id": user,
 			"date_of_birth": "1990-05-08",
 			"date_of_joining": "2013-01-01",
diff --git a/erpnext/hr/doctype/employee_tax_exemption_declaration/test_employee_tax_exemption_declaration.py b/erpnext/hr/doctype/employee_tax_exemption_declaration/test_employee_tax_exemption_declaration.py
index 9549fd1..e22948c 100644
--- a/erpnext/hr/doctype/employee_tax_exemption_declaration/test_employee_tax_exemption_declaration.py
+++ b/erpnext/hr/doctype/employee_tax_exemption_declaration/test_employee_tax_exemption_declaration.py
@@ -20,7 +20,7 @@
 		declaration = frappe.get_doc({
 			"doctype": "Employee Tax Exemption Declaration",
 			"employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"),
-			"company": erpnext.get_default_company(),
+			"company": erpnext.get_default_company() or 'Wind Power LLC',
 			"payroll_period": "_Test Payroll Period",
 			"declarations": [
 				dict(exemption_sub_category = "_Test Sub Category",
@@ -37,7 +37,7 @@
 		declaration = frappe.get_doc({
 			"doctype": "Employee Tax Exemption Declaration",
 			"employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"),
-			"company":  erpnext.get_default_company(),
+			"company":  erpnext.get_default_company()  or 'Wind Power LLC',
 			"payroll_period": "_Test Payroll Period",
 			"declarations": [
 				dict(exemption_sub_category = "_Test Sub Category",
@@ -52,7 +52,7 @@
 		duplicate_declaration = frappe.get_doc({
 			"doctype": "Employee Tax Exemption Declaration",
 			"employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"),
-			"company":  erpnext.get_default_company(),
+			"company":  erpnext.get_default_company()  or 'Wind Power LLC',
 			"payroll_period": "_Test Payroll Period",
 			"declarations": [
 				dict(exemption_sub_category = "_Test Sub Category",
@@ -68,7 +68,7 @@
 		declaration = frappe.get_doc({
 			"doctype": "Employee Tax Exemption Declaration",
 			"employee": frappe.get_value("Employee", {"user_id":"employee@taxexepmtion.com"}, "name"),
-			"company":  erpnext.get_default_company(),
+			"company":  erpnext.get_default_company()  or 'Wind Power LLC',
 			"payroll_period": "_Test Payroll Period",
 			"declarations": [
 				dict(exemption_sub_category = "_Test Sub Category",
@@ -88,7 +88,7 @@
 		payroll_period = frappe.get_doc(dict(
 			doctype = 'Payroll Period',
 			name = "_Test Payroll Period",
-			company =  erpnext.get_default_company(),
+			company =  erpnext.get_default_company() or 'Wind Power LLC',
 			start_date = date(date.today().year, 1, 1),
 			end_date = date(date.today().year, 12, 31)
 		)).insert()
diff --git a/erpnext/hr/doctype/expense_claim/test_expense_claim.py b/erpnext/hr/doctype/expense_claim/test_expense_claim.py
index 6e97f05..e7ee108 100644
--- a/erpnext/hr/doctype/expense_claim/test_expense_claim.py
+++ b/erpnext/hr/doctype/expense_claim/test_expense_claim.py
@@ -94,6 +94,7 @@
 		payable_account = get_payable_account(company_name)
 		expense_claim = frappe.get_doc({
 			 "doctype": "Expense Claim",
+			 "company": "_Test Company",
 			 "employee": "_T-Employee-00001",
 			 "payable_account": payable_account,
 			 "approval_status": "Rejected",
diff --git a/erpnext/hr/doctype/job_offer/test_job_offer.py b/erpnext/hr/doctype/job_offer/test_job_offer.py
index 8886596..1da107b 100644
--- a/erpnext/hr/doctype/job_offer/test_job_offer.py
+++ b/erpnext/hr/doctype/job_offer/test_job_offer.py
@@ -55,7 +55,8 @@
 		"job_applicant": args.job_applicant or job_applicant.name,
 		"offer_date": args.offer_date or nowdate(),
 		"designation": args.designation or "Researcher",
-		"status": args.status or "Accepted"
+		"status": args.status or "Accepted",
+		"company": "_Test Company"
 	})
 	return job_offer
 
@@ -68,6 +69,7 @@
 	staffing_plan = frappe.get_doc({
 		"doctype": "Staffing Plan",
 		"name": args.name or "Test",
+		"company": "_Test Company",
 		"from_date": args.from_date or nowdate(),
 		"to_date": args.to_date or add_days(nowdate(), 10),
 		"staffing_details": args.staffing_details or [{
diff --git a/erpnext/hr/doctype/leave_period/test_leave_period.py b/erpnext/hr/doctype/leave_period/test_leave_period.py
index 1762cf9..06e5836 100644
--- a/erpnext/hr/doctype/leave_period/test_leave_period.py
+++ b/erpnext/hr/doctype/leave_period/test_leave_period.py
@@ -45,7 +45,7 @@
 
 def create_leave_period(from_date, to_date, company=None):
 	leave_period = frappe.db.get_value('Leave Period',
-		dict(company=company or erpnext.get_default_company(),
+		dict(company=company or erpnext.get_default_company()  or 'Wind Power LLC',
 			from_date=from_date,
 			to_date=to_date,
 			is_active=1), 'name')
@@ -54,7 +54,7 @@
 
 	leave_period = frappe.get_doc({
 		"doctype": "Leave Period",
-		"company": company or erpnext.get_default_company(),
+		"company": company or erpnext.get_default_company() or 'Wind Power LLC',
 		"from_date": from_date,
 		"to_date": to_date,
 		"is_active": 1
diff --git a/erpnext/hr/doctype/payroll_entry/test_payroll_entry.py b/erpnext/hr/doctype/payroll_entry/test_payroll_entry.py
index 3c318e7..f1393b1 100644
--- a/erpnext/hr/doctype/payroll_entry/test_payroll_entry.py
+++ b/erpnext/hr/doctype/payroll_entry/test_payroll_entry.py
@@ -27,7 +27,7 @@
 		frappe.db.set_value("HR Settings", None, "email_salary_slip_to_employee", 0)
 
 	def test_payroll_entry(self): # pylint: disable=no-self-use
-		company = erpnext.get_default_company()
+		company = erpnext.get_default_company()  or 'Wind Power LLC'
 		for data in frappe.get_all('Salary Component', fields = ["name"]):
 			if not frappe.db.get_value('Salary Component Account',
 				{'parent': data.name, 'company': company}, 'name'):
@@ -157,7 +157,7 @@
 	args = frappe._dict(args)
 
 	payroll_entry = frappe.new_doc("Payroll Entry")
-	payroll_entry.company = args.company or erpnext.get_default_company()
+	payroll_entry.company = args.company or erpnext.get_default_company() or 'Wind Power LLC'
 	payroll_entry.start_date = args.start_date or "2016-11-01"
 	payroll_entry.end_date = args.end_date or "2016-11-30"
 	payroll_entry.payment_account = get_payment_account()
@@ -183,7 +183,7 @@
 
 def get_payment_account():
 	return frappe.get_value('Account',
-		{'account_type': 'Cash', 'company': erpnext.get_default_company(),'is_group':0}, "name")
+		{'account_type': 'Cash', 'company': erpnext.get_default_company() or 'Wind Power LLC', 'is_group':0}, "name")
 
 def make_holiday(holiday_list_name):
 	if not frappe.db.exists('Holiday List', holiday_list_name):
diff --git a/erpnext/hr/doctype/salary_slip/test_salary_slip.py b/erpnext/hr/doctype/salary_slip/test_salary_slip.py
index 3eff738..d002e54 100644
--- a/erpnext/hr/doctype/salary_slip/test_salary_slip.py
+++ b/erpnext/hr/doctype/salary_slip/test_salary_slip.py
@@ -242,7 +242,7 @@
 		self.assertEqual(ss.net_pay, (flt(ss.gross_pay) - (flt(ss.total_deduction) + flt(ss.total_loan_repayment))))
 
 	def test_payroll_frequency(self):
-		fiscal_year = get_fiscal_year(nowdate(), company=erpnext.get_default_company())[0]
+		fiscal_year = get_fiscal_year(nowdate(), company=erpnext.get_default_company() or 'Wind Power LLC')[0]
 		month = "%02d" % getdate(nowdate()).month
 		m = get_month_details(fiscal_year, month)
 
@@ -270,7 +270,7 @@
 		# as per assigned salary structure 40500 in monthly salary so 236000*5/100/12
 		frappe.db.sql("""delete from `tabPayroll Period`""")
 		frappe.db.sql("""delete from `tabSalary Component`""")
-	
+
 		payroll_period = create_payroll_period()
 
 		create_tax_slab(payroll_period, allow_tax_exemption=True)
@@ -414,7 +414,7 @@
 		get_salary_component_account(salary_component["salary_component"], company_list)
 
 def get_salary_component_account(sal_comp, company_list=None):
-	company = erpnext.get_default_company()
+	company = erpnext.get_default_company() or 'Wind Power LLC'
 
 	if company_list and company not in company_list:
 		company_list.append(company)
@@ -560,7 +560,7 @@
 		"doctype": "Employee Tax Exemption Declaration",
 		"employee": employee,
 		"payroll_period": payroll_period,
-		"company": erpnext.get_default_company()
+		"company": erpnext.get_default_company() or 'Wind Power LLC'
 	})
 	declaration.append("declarations", {
 		"exemption_sub_category": "_Test Sub Category",
@@ -667,7 +667,7 @@
 	frappe.get_doc({
 		"doctype": "Additional Salary",
 		"employee": employee,
-		"company": erpnext.get_default_company(),
+		"company": erpnext.get_default_company() or 'Wind Power LLC',
 		"salary_component": "Performance Bonus",
 		"payroll_date": salary_date,
 		"amount": amount,
diff --git a/erpnext/hr/doctype/salary_structure/test_salary_structure.py b/erpnext/hr/doctype/salary_structure/test_salary_structure.py
index eb5311e..ba3a968 100644
--- a/erpnext/hr/doctype/salary_structure/test_salary_structure.py
+++ b/erpnext/hr/doctype/salary_structure/test_salary_structure.py
@@ -22,7 +22,7 @@
 			frappe.db.sql("delete from `tab%s`" % dt)
 
 		self.make_holiday_list()
-		frappe.db.set_value("Company", erpnext.get_default_company(), "default_holiday_list", "Salary Structure Test Holiday List")
+		frappe.db.set_value("Company", erpnext.get_default_company() or 'Wind Power LLC', "default_holiday_list", "Salary Structure Test Holiday List")
 		make_employee("test_employee@salary.com")
 		make_employee("test_employee_2@salary.com")
 
@@ -116,7 +116,7 @@
 		details = {
 			"doctype": "Salary Structure",
 			"name": salary_structure,
-			"company": company or erpnext.get_default_company(),
+			"company": company or erpnext.get_default_company() or "_Test Company",
 			"earnings": make_earning_salary_component(test_tax=test_tax, company_list=["_Test Company"]),
 			"deductions": make_deduction_salary_component(test_tax=test_tax, company_list=["_Test Company"]),
 			"payroll_frequency": payroll_frequency,
@@ -151,7 +151,7 @@
 	salary_structure_assignment.variable = 5000
 	salary_structure_assignment.from_date = from_date or add_days(nowdate(), -1)
 	salary_structure_assignment.salary_structure = salary_structure
-	salary_structure_assignment.company = company or erpnext.get_default_company()
+	salary_structure_assignment.company = company or erpnext.get_default_company() or 'Wind Power LLC'
 	salary_structure_assignment.save(ignore_permissions=True)
 	salary_structure_assignment.income_tax_slab = "Tax Slab: _Test Payroll Period"
 	salary_structure_assignment.submit()
diff --git a/erpnext/hr/doctype/training_event/test_training_event.py b/erpnext/hr/doctype/training_event/test_training_event.py
index 57123e3..5ddb99b 100644
--- a/erpnext/hr/doctype/training_event/test_training_event.py
+++ b/erpnext/hr/doctype/training_event/test_training_event.py
@@ -32,7 +32,8 @@
 		frappe.get_doc({
 			"doctype": "Training Program",
 			"training_program": training_program,
-			"description": training_program
+			"description": training_program,
+			"company": "Wind Power LLC"
 		}).insert()
 
 def get_attendees(employee, employee2):
diff --git a/erpnext/manufacturing/doctype/bom/test_records.json b/erpnext/manufacturing/doctype/bom/test_records.json
index 25730f9..3913268 100644
--- a/erpnext/manufacturing/doctype/bom/test_records.json
+++ b/erpnext/manufacturing/doctype/bom/test_records.json
@@ -32,7 +32,8 @@
   "is_active": 1,
   "is_default": 1,
   "item": "_Test Item Home Desktop Manufactured",
-  "quantity": 1.0
+  "quantity": 1.0,
+  "company": "_Test Company"
  },
  {
   "scrap_items":[
@@ -78,7 +79,8 @@
   "is_default": 1,
   "currency": "USD",
   "item": "_Test FG Item",
-  "quantity": 1.0
+  "quantity": 1.0,
+  "company":"_Test Company"
  },
  {
   "operations": [
@@ -160,6 +162,7 @@
   "currency": "USD",
   "item": "_Test Variant Item",
   "quantity": 1.0,
-  "with_operations": 1
+  "with_operations": 1,
+  "company": "_Test Company"
  }
 ]
diff --git a/erpnext/projects/doctype/project/test_project.py b/erpnext/projects/doctype/project/test_project.py
index 06c62b6..0c4f6f1 100644
--- a/erpnext/projects/doctype/project/test_project.py
+++ b/erpnext/projects/doctype/project/test_project.py
@@ -7,7 +7,7 @@
 test_records = frappe.get_test_records('Project')
 test_ignore = ["Sales Order"]
 
-from erpnext.projects.doctype.project_template.test_project_template import get_project_template
+from erpnext.projects.doctype.project_template.test_project_template import get_project_template, make_project_template
 from erpnext.projects.doctype.project.project import set_project_status
 
 from frappe.utils import getdate
@@ -43,4 +43,24 @@
 		expected_start_date = '2019-01-01'
 	)).insert()
 
+	return project
+
+def make_project(args):
+	args = frappe._dict(args)
+	if args.project_template_name:
+		template = make_project_template(args.project_template_name)
+	else:
+		template = get_project_template()
+
+	project = frappe.get_doc(dict(
+		doctype = 'Project',
+		project_name = args.project_name,
+		status = 'Open',
+		project_template = template.name,
+		expected_start_date = args.start_date
+	))
+
+	if not frappe.db.exists("Project", args.project_name):
+		project.insert()
+
 	return project
\ No newline at end of file
diff --git a/erpnext/projects/doctype/project_template/test_project_template.py b/erpnext/projects/doctype/project_template/test_project_template.py
index efcb2ea..2c5831a 100644
--- a/erpnext/projects/doctype/project_template/test_project_template.py
+++ b/erpnext/projects/doctype/project_template/test_project_template.py
@@ -26,4 +26,23 @@
 			]
 		)).insert()
 
-	return frappe.get_doc('Project Template', 'Test Project Template')
\ No newline at end of file
+	return frappe.get_doc('Project Template', 'Test Project Template')
+
+def make_project_template(project_template_name, project_tasks=[]):
+	if not frappe.db.exists('Project Template', project_template_name):
+		frappe.get_doc(dict(
+			doctype = 'Project Template',
+			name = project_template_name,
+			tasks = project_tasks or [
+				dict(subject='Task 1', description='Task 1 description',
+					start=0, duration=3),
+				dict(subject='Task 2', description='Task 2 description',
+					start=0, duration=2),
+				dict(subject='Task 3', description='Task 3 description',
+					start=2, duration=4),
+				dict(subject='Task 4', description='Task 4 description',
+					start=3, duration=2),
+			]
+		)).insert()
+
+	return frappe.get_doc('Project Template', project_template_name)
\ No newline at end of file
diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py
index 0d70d91..56899d5 100644
--- a/erpnext/setup/setup_wizard/operations/install_fixtures.py
+++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py
@@ -437,7 +437,6 @@
 	global_defaults.update({
 		'current_fiscal_year': current_fiscal_year.name,
 		'default_currency': args.get('currency'),
-		'default_company':args.get('company_name')	,
 		"country": args.get("country"),
 	})
 
diff --git a/erpnext/stock/doctype/delivery_note/test_delivery_note.py b/erpnext/stock/doctype/delivery_note/test_delivery_note.py
index a921a56..13bd02f 100644
--- a/erpnext/stock/doctype/delivery_note/test_delivery_note.py
+++ b/erpnext/stock/doctype/delivery_note/test_delivery_note.py
@@ -192,6 +192,7 @@
 		serial_no = frappe.get_doc({
 			"doctype": "Serial No",
 			"item_code": "_Test Serialized Item With Series",
+			"company": "Wind Power LLC",
 			"serial_no": make_autoname("SR", "Serial No")
 		})
 		serial_no.save()
@@ -537,11 +538,8 @@
 		dt = make_delivery_trip(dn.name)
 		self.assertEqual(dn.name, dt.delivery_stops[0].delivery_note)
 
-	def test_delivery_note_for_enable_allow_cost_center_in_entry_of_bs_account(self):
+	def test_delivery_note_with_cost_center(self):
 		from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
-		accounts_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 1
-		accounts_settings.save()
 		cost_center = "_Test Cost Center for BS Account - TCP1"
 		create_cost_center(cost_center_name="_Test Cost Center for BS Account", company="_Test Company with perpetual inventory")
 
@@ -567,37 +565,6 @@
 		}
 		for i, gle in enumerate(gl_entries):
 			self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center)
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 0
-		accounts_settings.save()
-
-	def test_delivery_note_for_disable_allow_cost_center_in_entry_of_bs_account(self):
-		accounts_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 0
-		accounts_settings.save()
-		cost_center = "Main - TCP1"
-
-		company = frappe.db.get_value('Warehouse', 'Stores - TCP1', 'company')
-
-		set_valuation_method("_Test Item", "FIFO")
-
-		make_stock_entry(target="Stores - TCP1", qty=5, basic_rate=100)
-
-		stock_in_hand_account = get_inventory_account('_Test Company with perpetual inventory')
-		dn = create_delivery_note(company='_Test Company with perpetual inventory', warehouse='Stores - TCP1', cost_center = 'Main - TCP1', expense_account = "Cost of Goods Sold - TCP1")
-
-		gl_entries = get_gl_entries("Delivery Note", dn.name)
-
-		self.assertTrue(gl_entries)
-		expected_values = {
-			"Cost of Goods Sold - TCP1": {
-				"cost_center": cost_center
-			},
-			stock_in_hand_account: {
-				"cost_center": None
-			}
-		}
-		for i, gle in enumerate(gl_entries):
-			self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center)
 
 	def test_make_sales_invoice_from_dn_for_returned_qty(self):
 		from erpnext.selling.doctype.sales_order.sales_order import make_delivery_note
diff --git a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json
index 7ea2de2..7c92ac7 100644
--- a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json
+++ b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json
@@ -1,5 +1,4 @@
 {
- "actions": [],
  "autoname": "hash",
  "creation": "2013-04-22 13:15:44",
  "doctype": "DocType",
@@ -82,6 +81,7 @@
   "accounting_dimensions_section",
   "cost_center",
   "dimension_col_break",
+  "project",
   "section_break_72",
   "page_break"
  ],
@@ -702,6 +702,12 @@
    "fieldtype": "Column Break"
   },
   {
+   "fieldname": "project",
+   "fieldtype": "Link",
+   "label": "Project",
+   "options": "Project"
+  },
+  {
    "fieldname": "dn_detail",
    "fieldtype": "Data",
    "hidden": 1,
@@ -714,7 +720,7 @@
  "idx": 1,
  "istable": 1,
  "links": [],
- "modified": "2020-03-05 14:18:33.131672",
+ "modified": "2020-03-11 12:25:06.177894",
  "modified_by": "Administrator",
  "module": "Stock",
  "name": "Delivery Note Item",
diff --git a/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py b/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py
index eeea6da..da2c97c 100644
--- a/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py
+++ b/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py
@@ -172,7 +172,7 @@
 
 	delivery_trip = frappe.get_doc({
 		"doctype": "Delivery Trip",
-		"company": erpnext.get_default_company(),
+		"company": erpnext.get_default_company() or 'Wind Power LLC',
 		"departure_time": add_days(now_datetime(), 5),
 		"driver": driver.name,
 		"driver_address": address.name,
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json
index 467a206..02f72e2 100755
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json
@@ -1,5 +1,4 @@
 {
- "actions": [],
  "allow_import": 1,
  "autoname": "naming_series:",
  "creation": "2013-05-21 16:16:39",
@@ -106,6 +105,7 @@
   "amended_from",
   "range",
   "column_break4",
+  "project",
   "per_billed",
   "is_internal_supplier",
   "inter_company_reference",
@@ -930,6 +930,12 @@
    "width": "50%"
   },
   {
+   "fieldname": "project",
+   "fieldtype": "Link",
+   "label": "Project",
+   "options": "Project"
+  },
+  {
    "fieldname": "per_billed",
    "fieldtype": "Percent",
    "label": "% Amount Billed",
diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
index 649cfdc..af25ba6 100644
--- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
@@ -403,11 +403,8 @@
 
 		pr_return.submit()
 
-	def test_purchase_receipt_for_enable_allow_cost_center_in_entry_of_bs_account(self):
+	def test_purchase_receipt_cost_center(self):
 		from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
-		accounts_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 1
-		accounts_settings.save()
 		cost_center = "_Test Cost Center for BS Account - TCP1"
 		create_cost_center(cost_center_name="_Test Cost Center for BS Account", company="_Test Company with perpetual inventory")
 
@@ -435,37 +432,6 @@
 		for i, gle in enumerate(gl_entries):
 			self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center)
 
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 0
-		accounts_settings.save()
-
-	def test_purchase_receipt_for_disable_allow_cost_center_in_entry_of_bs_account(self):
-		accounts_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
-		accounts_settings.allow_cost_center_in_entry_of_bs_account = 0
-		accounts_settings.save()
-
-		if not frappe.db.exists('Location', 'Test Location'):
-			frappe.get_doc({
-				'doctype': 'Location',
-				'location_name': 'Test Location'
-			}).insert()
-		pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1")
-
-		stock_in_hand_account = get_inventory_account(pr.company, pr.get("items")[0].warehouse)
-		gl_entries = get_gl_entries("Purchase Receipt", pr.name)
-
-		self.assertTrue(gl_entries)
-
-		expected_values = {
-			"Stock Received But Not Billed - TCP1": {
-				"cost_center": None
-			},
-			stock_in_hand_account: {
-				"cost_center": None
-			}
-		}
-		for i, gle in enumerate(gl_entries):
-			self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center)
-
 	def test_make_purchase_invoice_from_pr_for_returned_qty(self):
 		from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order, create_pr_against_po
 
diff --git a/erpnext/stock/doctype/serial_no/test_serial_no.py b/erpnext/stock/doctype/serial_no/test_serial_no.py
index ab06107..7b06ef9 100644
--- a/erpnext/stock/doctype/serial_no/test_serial_no.py
+++ b/erpnext/stock/doctype/serial_no/test_serial_no.py
@@ -24,6 +24,7 @@
 		frappe.delete_doc_if_exists("Serial No", "_TCSER0001")
 
 		sr = frappe.new_doc("Serial No")
+		sr.company = '_Test Company'
 		sr.item_code = "_Test Serialized Item"
 		sr.warehouse = "_Test Warehouse - _TC"
 		sr.serial_no = "_TCSER0001"