feat: configuration to notify reposting errors to specific role
This commit is contained in:
		
							parent
							
								
									9aa646512a
								
							
						
					
					
						commit
						c7b62011db
					
				| @ -300,9 +300,7 @@ def _get_directly_dependent_vouchers(doc): | ||||
| 
 | ||||
| 
 | ||||
| def notify_error_to_stock_managers(doc, traceback): | ||||
| 	recipients = get_users_with_role("Stock Manager") | ||||
| 	if not recipients: | ||||
| 		recipients = get_users_with_role("System Manager") | ||||
| 	recipients = get_recipients() | ||||
| 
 | ||||
| 	subject = _("Error while reposting item valuation") | ||||
| 	message = ( | ||||
| @ -319,6 +317,17 @@ def notify_error_to_stock_managers(doc, traceback): | ||||
| 	frappe.sendmail(recipients=recipients, subject=subject, message=message) | ||||
| 
 | ||||
| 
 | ||||
| def get_recipients(): | ||||
| 	role = ( | ||||
| 		frappe.db.get_single_value("Stock Reposting Settings", "notify_reposting_error_to_role") | ||||
| 		or "Stock Manager" | ||||
| 	) | ||||
| 
 | ||||
| 	recipients = get_users_with_role(role) | ||||
| 
 | ||||
| 	return recipients | ||||
| 
 | ||||
| 
 | ||||
| def repost_entries(): | ||||
| 	""" | ||||
| 	Reposts 'Repost Item Valuation' entries in queue. | ||||
|  | ||||
| @ -12,7 +12,9 @@ | ||||
|   "start_time", | ||||
|   "end_time", | ||||
|   "limits_dont_apply_on", | ||||
|   "item_based_reposting" | ||||
|   "item_based_reposting", | ||||
|   "errors_notification_section", | ||||
|   "notify_reposting_error_to_role" | ||||
|  ], | ||||
|  "fields": [ | ||||
|   { | ||||
| @ -52,12 +54,23 @@ | ||||
|    "fieldname": "item_based_reposting", | ||||
|    "fieldtype": "Check", | ||||
|    "label": "Use Item based reposting" | ||||
|   }, | ||||
|   { | ||||
|    "fieldname": "notify_reposting_error_to_role", | ||||
|    "fieldtype": "Link", | ||||
|    "label": "Notify Reposting Error to Role", | ||||
|    "options": "Role" | ||||
|   }, | ||||
|   { | ||||
|    "fieldname": "errors_notification_section", | ||||
|    "fieldtype": "Section Break", | ||||
|    "label": "Errors Notification" | ||||
|   } | ||||
|  ], | ||||
|  "index_web_pages_for_search": 1, | ||||
|  "issingle": 1, | ||||
|  "links": [], | ||||
|  "modified": "2021-11-02 01:22:45.155841", | ||||
|  "modified": "2023-05-04 16:14:29.080697", | ||||
|  "modified_by": "Administrator", | ||||
|  "module": "Stock", | ||||
|  "name": "Stock Reposting Settings", | ||||
| @ -76,5 +89,6 @@ | ||||
|  ], | ||||
|  "sort_field": "modified", | ||||
|  "sort_order": "DESC", | ||||
|  "states": [], | ||||
|  "track_changes": 1 | ||||
| } | ||||
| @ -1,9 +1,40 @@ | ||||
| # Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors | ||||
| # See license.txt | ||||
| 
 | ||||
| # import frappe | ||||
| import unittest | ||||
| 
 | ||||
| import frappe | ||||
| 
 | ||||
| from erpnext.stock.doctype.repost_item_valuation.repost_item_valuation import get_recipients | ||||
| 
 | ||||
| 
 | ||||
| class TestStockRepostingSettings(unittest.TestCase): | ||||
| 	pass | ||||
| 	def test_notify_reposting_error_to_role(self): | ||||
| 		role = "Notify Reposting Role" | ||||
| 
 | ||||
| 		if not frappe.db.exists("Role", role): | ||||
| 			frappe.get_doc({"doctype": "Role", "role_name": role}).insert(ignore_permissions=True) | ||||
| 
 | ||||
| 		user = "notify_reposting_error@test.com" | ||||
| 		if not frappe.db.exists("User", user): | ||||
| 			frappe.get_doc( | ||||
| 				{ | ||||
| 					"doctype": "User", | ||||
| 					"email": user, | ||||
| 					"first_name": "Test", | ||||
| 					"language": "en", | ||||
| 					"time_zone": "Asia/Kolkata", | ||||
| 					"send_welcome_email": 0, | ||||
| 					"roles": [{"role": role}], | ||||
| 				} | ||||
| 			).insert(ignore_permissions=True) | ||||
| 
 | ||||
| 		frappe.db.set_single_value("Stock Reposting Settings", "notify_reposting_error_to_role", "") | ||||
| 
 | ||||
| 		users = get_recipients() | ||||
| 		self.assertFalse(user in users) | ||||
| 
 | ||||
| 		frappe.db.set_single_value("Stock Reposting Settings", "notify_reposting_error_to_role", role) | ||||
| 
 | ||||
| 		users = get_recipients() | ||||
| 		self.assertTrue(user in users) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user