ShipStation tracking pull, status tracking, dashboard rework

This commit is contained in:
2026-08-26 11:28:42 -05:00
parent ffaaa0c8c8
commit 18be8588f6
16 changed files with 769 additions and 304 deletions
+41
View File
@@ -0,0 +1,41 @@
"""
Read-only queries against the local order cache.
Separate from app/workers.py (which owns saving orders and dashboard
stats) because this module is about a service asking "what do I
already know about" before it fetches - a different concern that other
sources (ShipStation, Odoo) will likely need their own version of too.
"""
from __future__ import annotations
from typing import List
from sqlalchemy import select
from app.database import get_session
from app.models import Order
from app.status_rules import status_in
def get_open_ticket_numbers(source: str, terminal_statuses: set[str]) -> List[str]:
"""
Ticket numbers for a source that haven't reached a terminal status
yet - i.e. still worth re-fetching to catch status changes (like a
cancellation) even if the ticket wasn't created today.
"""
session = get_session()
try:
rows = session.execute(
select(Order.ticket_number, Order.status).where(
Order.source == source,
Order.ticket_number.is_not(None),
)
).all()
finally:
session.close()
return [
ticket_number
for ticket_number, status in rows
if ticket_number and not status_in(status, terminal_statuses)
]