diff --git a/InvenTree/InvenTree/models.py b/InvenTree/InvenTree/models.py index cc323a14fe..afc1fa43b6 100644 --- a/InvenTree/InvenTree/models.py +++ b/InvenTree/InvenTree/models.py @@ -887,6 +887,7 @@ def after_error_logged(sender, instance: Error, created: bool, **kwargs): if created: try: + import common.models import common.notifications users = get_user_model().objects.filter(is_staff=True) @@ -902,13 +903,20 @@ def after_error_logged(sender, instance: Error, created: bool, **kwargs): 'link': link } - common.notifications.trigger_notification( - instance, - 'inventree.error_log', - context=context, - targets=users, - delivery_methods={common.notifications.UIMessageNotification, }, - ) + target_users = [] + + for user in users: + if common.models.InvenTreeUserSetting.get_setting('NOTIFICATION_ERROR_REPORT', True, user=user): + target_users.append(user) + + if len(target_users) > 0: + common.notifications.trigger_notification( + instance, + 'inventree.error_log', + context=context, + targets=users, + delivery_methods={common.notifications.UIMessageNotification, }, + ) except Exception as exc: """We do not want to throw an exception while reporting an exception""" diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 489d13eb41..d0f528fcb2 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -2191,6 +2191,13 @@ class InvenTreeUserSetting(BaseInvenTreeSetting): 'default': '', }, + 'NOTIFICATION_ERROR_REPORT': { + 'name': _('Receive error reports'), + 'description': _('Receive notifications for system errors'), + 'default': True, + 'validator': bool, + } + } typ = 'user' diff --git a/InvenTree/templates/InvenTree/settings/user_notifications.html b/InvenTree/templates/InvenTree/settings/user_notifications.html index 829be97c78..4a94f8feb6 100644 --- a/InvenTree/templates/InvenTree/settings/user_notifications.html +++ b/InvenTree/templates/InvenTree/settings/user_notifications.html @@ -13,6 +13,9 @@