Skip to content

Commit

Permalink
feat: add retry sent to financial manager on admin
Browse files Browse the repository at this point in the history
Add an action to Django Admin that allows to retry send the
information to financial manager.
  • Loading branch information
igobranco committed Apr 12, 2024
1 parent 240862c commit d2b7a1a
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion nau_extensions/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from pprint import pformat

from django.contrib import admin
from django.contrib import admin, messages
from django.utils.html import format_html
from django.utils.translation import gettext_lazy as _
from nau_extensions.financial_manager import \
send_to_financial_manager_if_enabled
from nau_extensions.models import (BasketBillingInformation,
BasketTransactionIntegration)

Expand All @@ -28,3 +31,29 @@ def formatted_response(self, obj):

# Use format_html() to escape user-provided inputs, avoiding an XSS vulnerability.
return format_html('<br><br><pre>{}</pre>', pretty_response)

@admin.action(description=_("Retry Send to Financial Manager"))
def retry_send_to_financial_manager(self, request, queryset):
"""
Django admin action that permit to retry send information to financial manager.
"""
for bti in queryset:
sent = send_to_financial_manager_if_enabled(bti)
if sent:
self.message_user(
request,
_(
"Sent to financial manager with success.",
),
messages.SUCCESS,
)
else:
self.message_user(
request,
_(
"Sent to financial manager finished with an error.",
),
messages.ERROR,
)

actions = [retry_send_to_financial_manager]

0 comments on commit d2b7a1a

Please sign in to comment.