Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions track/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from django.urls import path
import logging
from track import orders
from django.contrib import messages
from track import gbf

logger = logging.getLogger(__name__)

Expand All @@ -13,6 +15,35 @@ class OrderAdmin(admin.ModelAdmin):
change_list_template = "track/check_orders.html"

list_display = ["record_id", "order_number", "tracking_nrs", "return_tracking_nrs", "tube_serials", "order_status", "ship_date"]
actions = ['check_orders_status']

def get_actions(self, request):
actions = super().get_actions(request)
return actions

def check_orders_status(self, request, queryset):
if not queryset:
self.message_user(request, "No orders selected to check status.", messages.WARNING)
return

try:
order_numbers = list(queryset.values_list('order_number', flat=True))
queryset.update(order_status=Order.INITIATED)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to change the status here. If we already have checked it before and got a response, we want to leave it what it was. If it has not been placed yet, it has to stay what it was. and it if was already initiated, we don't need to change it.


# Check shipping info for selected orders only
tracking_info = gbf.get_order_confirmations(order_numbers)
if tracking_info:
orders._update_orders_with_shipping_info(tracking_info)
message = f"Successfully checked shipping status for orders: {', '.join(order_numbers)}"
self.message_user(request, message, messages.SUCCESS)
else:
self.message_user(request, "No shipping information available for the selected orders.", messages.INFO)

except Exception as e:
logger.error(f"Error checking order status: {str(e)}")
self.message_user(request, f"Error checking order status: {str(e)}", messages.ERROR)

check_orders_status.short_description = "Check shipping status for selected orders"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you'll need to start a log with the log manager at the beginning and complete it at the end

log_manager.start_confirmation_log()
...
log_manager.complete_log()


class ConfirmationCheckLogAdmin(admin.ModelAdmin):
list_display = ["id", "job_id", "start_time", "end_time", "is_complete"]
Expand Down