Email procedure (beta), WorkFlow update

This commit is contained in:
2026-09-02 11:44:54 -05:00
parent 826a70bdf6
commit edd5f2a886
12 changed files with 450 additions and 8 deletions
+37 -2
View File
@@ -45,6 +45,7 @@ import requests
from PyQt6.QtCore import QRunnable, QThreadPool
from app import config
from app.companies import parse_mapping
from app.services.base import OrderService, NormalizedOrder
from app.tracking import suggest_jira_status
@@ -64,6 +65,22 @@ SHIPMENT_LOOKBACK_DAYS = 7
MAX_CONCURRENT_REQUESTS = 5
def _resolve_shipping_method(service_code: str) -> str:
"""Maps a ShipStation service_code (e.g. 'ups_ground') to your team's
JIRA-facing term (e.g. 'Ground') via SHIPPING_METHOD_LABELS. Falls back
to a prettified version of the raw code for anything not mapped, so an
unmapped service still shows something readable rather than nothing."""
if not service_code:
return ""
settings = config.load_settings()
mapping = parse_mapping(
settings.get("SHIPPING_METHOD_LABELS", "") or config.DEFAULT_SHIPPING_METHOD_LABELS
)
if service_code in mapping:
return mapping[service_code]
return service_code.replace("_", " ").title()
class ShipStationServiceError(Exception):
"""Raised for any ShipStation fetch failure, with a message safe to show in the UI."""
@@ -124,6 +141,7 @@ class ShipStationService(OrderService):
# --- Sort/correlate now, entirely in memory, after both batches landed ---
tracking_by_ticket: Dict[str, List[dict]] = {}
raw_by_ticket: Dict[str, dict] = {}
shipping_method_by_ticket: Dict[str, str] = {}
self.unmatched_labels = []
for label in usable_labels:
@@ -144,9 +162,20 @@ class ShipStationService(OrderService):
raw_by_ticket.setdefault(ticket_number, {"labels": [], "shipment": shipment})
raw_by_ticket[ticket_number]["labels"].append(label)
# Shipping Method reflects the OUTBOUND label specifically (matches
# the Ship Sheet's usage) - only set from the first non-return label
# seen per ticket, so a return label's service doesn't overwrite it.
if not label.get("is_return_label") and ticket_number not in shipping_method_by_ticket:
shipping_method_by_ticket[ticket_number] = _resolve_shipping_method(
label.get("service_code", "")
)
return [
self._to_normalized_order(
ticket_number, tracking_by_ticket[ticket_number], raw_by_ticket[ticket_number]
ticket_number,
tracking_by_ticket[ticket_number],
raw_by_ticket[ticket_number],
shipping_method_by_ticket.get(ticket_number, ""),
)
for ticket_number in tracking_by_ticket
]
@@ -280,7 +309,7 @@ class ShipStationService(OrderService):
@staticmethod
def _to_normalized_order(
ticket_number: str, tracking_numbers: List[dict], raw: dict
ticket_number: str, tracking_numbers: List[dict], raw: dict, shipping_method: str
) -> NormalizedOrder:
suggested_status = suggest_jira_status(tracking_numbers) or "Tracking Pulled"
numbers_display = ", ".join(
@@ -294,7 +323,13 @@ class ShipStationService(OrderService):
ticket_number=ticket_number,
company="", # not used - the JIRA row this merges onto already has one
skus=[],
line_items=[],
shipping_info={},
creator=None,
assignee=None,
description=None,
tracking_numbers=tracking_numbers,
shipping_method=shipping_method,
summary=numbers_display,
status=suggested_status,
source_created_at=None,