fix: Test Cases

(cherry picked from commit ded3ab1cd778389ab348bcb5628379f129a8d02d)
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 2f2f959..3cd57d4 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -588,16 +588,18 @@
 						amount = flt(item.base_net_amount + item.item_tax_amount, item.precision("base_net_amount"))
 
 					auto_accounting_for_non_stock_items = cint(frappe.db.get_value('Company', self.company, 'enable_perpetual_inventory_for_non_stock_items'))
-					service_received_but_not_billed_account = self.get_company_default("service_received_but_not_billed")
 
-					if item.purchase_receipt and auto_accounting_for_non_stock_items:
-						# Post reverse entry for Stock-Received-But-Not-Billed if it is booked in Purchase Receipt
-						expense_booked_in_pr = frappe.db.get_value('GL Entry', {'is_cancelled': 0,
-							'voucher_type': 'Purchase Receipt', 'voucher_no': item.purchase_receipt, 'voucher_detail_no': item.pr_detail,
-							'account':service_received_but_not_billed_account}, ['name'])
+					if auto_accounting_for_non_stock_items:
+						service_received_but_not_billed_account = self.get_company_default("service_received_but_not_billed")
 
-						if expense_booked_in_pr:
-							expense_account = service_received_but_not_billed_account
+						if item.purchase_receipt:
+							# Post reverse entry for Stock-Received-But-Not-Billed if it is booked in Purchase Receipt
+							expense_booked_in_pr = frappe.db.get_value('GL Entry', {'is_cancelled': 0,
+								'voucher_type': 'Purchase Receipt', 'voucher_no': item.purchase_receipt, 'voucher_detail_no': item.pr_detail,
+								'account':service_received_but_not_billed_account}, ['name'])
+
+							if expense_booked_in_pr:
+								expense_account = service_received_but_not_billed_account
 
 					gl_entries.append(self.get_gl_dict({
 							"account": expense_account,
diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py
index 8bcaa28..47b41a9 100644
--- a/erpnext/setup/doctype/company/company.py
+++ b/erpnext/setup/doctype/company/company.py
@@ -46,6 +46,7 @@
 		self.validate_currency()
 		self.validate_coa_input()
 		self.validate_perpetual_inventory()
+		self.validate_perpetual_inventory_for_non_stock_items()
 		self.check_country_change()
 		self.set_chart_of_accounts()
 		self.validate_parent_company()
@@ -182,6 +183,12 @@
 				frappe.msgprint(_("Set default inventory account for perpetual inventory"),
 					alert=True, indicator='orange')
 
+	def validate_perpetual_inventory_for_non_stock_items(self):
+		if not self.get("__islocal"):
+			if cint(self.enable_perpetual_inventory_for_non_stock_items) == 1 and not self.service_received_but_not_billed:
+				frappe.throw(_("Set default {0} account for perpetual inventory for non stock items").format(
+					frappe.bold('Service Received But Not Billed')))
+
 	def check_country_change(self):
 		frappe.flags.country_change = False
 
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
index 15068ec..d0ba001 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -211,7 +211,6 @@
 		stock_rbnb = self.get_company_default("stock_received_but_not_billed")
 		landed_cost_entries = get_item_account_wise_additional_cost(self.name)
 		expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation")
-		service_received_but_not_billed_account = self.get_company_default("service_received_but_not_billed")
 		auto_accounting_for_non_stock_items = cint(frappe.db.get_value('Company', self.company, 'enable_perpetual_inventory_for_non_stock_items'))
 
 		gl_entries = []
@@ -305,6 +304,7 @@
 						warehouse_with_no_account.append(d.warehouse)
 			elif d.item_code not in stock_items and flt(d.qty) and auto_accounting_for_non_stock_items:
 
+				service_received_but_not_billed_account = self.get_company_default("service_received_but_not_billed")
 				credit_currency = get_account_currency(service_received_but_not_billed_account)
 
 				gl_entries.append(self.get_gl_dict({