Skip to content

Commit

Permalink
feat: configuration to notify reposting errors to specific role
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed May 4, 2023
1 parent 9aa6465 commit c7b6201
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down Expand Up @@ -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",
Expand All @@ -76,5 +89,6 @@
],
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit c7b6201

Please sign in to comment.