test: reset session user if test errors in test_sle (#25042)
This commit is contained in:
		
							parent
							
								
									868c0bf45b
								
							
						
					
					
						commit
						d6c7d8e631
					
				| @ -125,7 +125,7 @@ class TestStockLedgerEntry(unittest.TestCase): | |||||||
| 		pr = make_purchase_receipt(company="_Test Company", posting_date='2020-04-10', | 		pr = make_purchase_receipt(company="_Test Company", posting_date='2020-04-10', | ||||||
| 			warehouse="Stores - _TC", item_code="_Test Item for Reposting", qty=5, rate=100) | 			warehouse="Stores - _TC", item_code="_Test Item for Reposting", qty=5, rate=100) | ||||||
| 
 | 
 | ||||||
| 		return_pr = make_purchase_receipt(company="_Test Company", posting_date='2020-04-15',  | 		return_pr = make_purchase_receipt(company="_Test Company", posting_date='2020-04-15', | ||||||
| 			warehouse="Stores - _TC", item_code="_Test Item for Reposting", is_return=1, return_against=pr.name, qty=-2) | 			warehouse="Stores - _TC", item_code="_Test Item for Reposting", is_return=1, return_against=pr.name, qty=-2) | ||||||
| 
 | 
 | ||||||
| 		# check sle | 		# check sle | ||||||
| @ -278,7 +278,7 @@ class TestStockLedgerEntry(unittest.TestCase): | |||||||
| 
 | 
 | ||||||
| 		frappe.db.set_value("Buying Settings", None, "backflush_raw_materials_of_subcontract_based_on", "BOM") | 		frappe.db.set_value("Buying Settings", None, "backflush_raw_materials_of_subcontract_based_on", "BOM") | ||||||
| 		make_bom(item = subcontracted_item, raw_materials =[rm_item_code], currency="INR") | 		make_bom(item = subcontracted_item, raw_materials =[rm_item_code], currency="INR") | ||||||
| 		 | 
 | ||||||
| 		# Purchase raw materials on supplier warehouse: Qty = 50, Rate = 100 | 		# Purchase raw materials on supplier warehouse: Qty = 50, Rate = 100 | ||||||
| 		pr = make_purchase_receipt(company=company, posting_date='2020-04-10', | 		pr = make_purchase_receipt(company=company, posting_date='2020-04-10', | ||||||
| 			warehouse="Stores - _TC", item_code=rm_item_code, qty=10, rate=100) | 			warehouse="Stores - _TC", item_code=rm_item_code, qty=10, rate=100) | ||||||
| @ -292,7 +292,7 @@ class TestStockLedgerEntry(unittest.TestCase): | |||||||
| 
 | 
 | ||||||
| 		# Update raw material's valuation via LCV, Additional cost = 50 | 		# Update raw material's valuation via LCV, Additional cost = 50 | ||||||
| 		lcv = create_landed_cost_voucher("Purchase Receipt", pr.name, pr.company) | 		lcv = create_landed_cost_voucher("Purchase Receipt", pr.name, pr.company) | ||||||
| 		 | 
 | ||||||
| 		pr1.reload() | 		pr1.reload() | ||||||
| 		self.assertEqual(pr1.items[0].valuation_rate, 125) | 		self.assertEqual(pr1.items[0].valuation_rate, 125) | ||||||
| 
 | 
 | ||||||
| @ -310,31 +310,33 @@ class TestStockLedgerEntry(unittest.TestCase): | |||||||
| 		# Back dated stock transactions are only allowed to stock managers | 		# Back dated stock transactions are only allowed to stock managers | ||||||
| 		frappe.db.set_value("Stock Settings", None, | 		frappe.db.set_value("Stock Settings", None, | ||||||
| 			"role_allowed_to_create_edit_back_dated_transactions", "Stock Manager") | 			"role_allowed_to_create_edit_back_dated_transactions", "Stock Manager") | ||||||
| 		 | 
 | ||||||
| 		# Set User with Stock User role but not Stock Manager | 		# Set User with Stock User role but not Stock Manager | ||||||
| 		frappe.set_user("test@example.com") | 		try: | ||||||
| 		user = frappe.get_doc("User", "test@example.com") | 			frappe.set_user("test@example.com") | ||||||
| 		user.add_roles("Stock User") | 			user = frappe.get_doc("User", "test@example.com") | ||||||
| 		user.remove_roles("Stock Manager") | 			user.add_roles("Stock User") | ||||||
|  | 			user.remove_roles("Stock Manager") | ||||||
| 
 | 
 | ||||||
| 		stock_entry_on_today = make_stock_entry(target="_Test Warehouse - _TC", qty=10, basic_rate=100) | 			stock_entry_on_today = make_stock_entry(target="_Test Warehouse - _TC", qty=10, basic_rate=100) | ||||||
| 		back_dated_se_1 = make_stock_entry(target="_Test Warehouse - _TC", qty=10, basic_rate=100, | 			back_dated_se_1 = make_stock_entry(target="_Test Warehouse - _TC", qty=10, basic_rate=100, | ||||||
| 			posting_date=add_days(today(), -1), do_not_submit=True) | 				posting_date=add_days(today(), -1), do_not_submit=True) | ||||||
| 
 | 
 | ||||||
| 		# Block back-dated entry | 			# Block back-dated entry | ||||||
| 		self.assertRaises(BackDatedStockTransaction, back_dated_se_1.submit) | 			self.assertRaises(BackDatedStockTransaction, back_dated_se_1.submit) | ||||||
| 
 | 
 | ||||||
| 		user.add_roles("Stock Manager") | 			user.add_roles("Stock Manager") | ||||||
| 
 | 
 | ||||||
| 		# Back dated entry allowed to Stock Manager | 			# Back dated entry allowed to Stock Manager | ||||||
| 		back_dated_se_2 = make_stock_entry(target="_Test Warehouse - _TC", qty=10, basic_rate=100, | 			back_dated_se_2 = make_stock_entry(target="_Test Warehouse - _TC", qty=10, basic_rate=100, | ||||||
| 			posting_date=add_days(today(), -1)) | 				posting_date=add_days(today(), -1)) | ||||||
| 
 | 
 | ||||||
| 		back_dated_se_2.cancel() | 			back_dated_se_2.cancel() | ||||||
| 		stock_entry_on_today.cancel() | 			stock_entry_on_today.cancel() | ||||||
| 
 | 
 | ||||||
| 		frappe.db.set_value("Stock Settings", None, "role_allowed_to_create_edit_back_dated_transactions", None) | 		finally: | ||||||
| 		frappe.set_user("Administrator") | 			frappe.db.set_value("Stock Settings", None, "role_allowed_to_create_edit_back_dated_transactions", None) | ||||||
|  | 			frappe.set_user("Administrator") | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def create_repack_entry(**args): | def create_repack_entry(**args): | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user