Rework of workflow, added the dock back. This is now the beginning of the SKU mismatch issues. FKN FUN TIMES AHEAD

This commit is contained in:
2026-09-04 12:09:49 -05:00
parent a1b438a61f
commit 52bd6f5da2
8 changed files with 395 additions and 68 deletions
+25 -9
View File
@@ -273,9 +273,25 @@ def send_order_to_shipstation_api(order: Order) -> dict:
VALID_CHARGE_EVENTS = {"on_creation", "on_carrier_acceptance", "carrier_default"}
def _return_address_for_company(company: str) -> dict:
def _return_config_prefix(order: Order) -> str:
"""
Normally keyed off company, but RMD-prefixed SKUs (RubiconMD, an Oak
Street subsidiary) use their own UPS account and return address even
though the ticket is still classified as Oak Street Health for every
other purpose - so this checks the ticket's actual SKUs, not just
order.company. (The IE prefix seen in Signify's catalog is deprecated
and deliberately not handled here - not expected on current tickets.)
"""
if any((sku or "").strip().upper().startswith("RMD") for sku in (order.skus or [])):
return "RUBICONMD_RETURN_"
if order.company == "Signify Health":
return "SIGNIFY_RETURN_"
return "OAKSTREET_RETURN_"
def _return_address_for_order(order: Order) -> dict:
settings = config.load_settings()
prefix = "SIGNIFY_RETURN_" if company == "Signify Health" else "OAKSTREET_RETURN_"
prefix = _return_config_prefix(order)
return {
"name": settings.get(f"{prefix}NAME", ""),
"phone": settings.get(f"{prefix}PHONE", ""),
@@ -288,12 +304,12 @@ def _return_address_for_company(company: str) -> dict:
}
def _return_carrier_for_company(company: str) -> tuple[str, str]:
"""Each company has its own UPS account (different carrier_id) even
though they share a warehouse - matches how store/warehouse IDs are
already split per company elsewhere in this app."""
def _return_carrier_for_order(order: Order) -> tuple[str, str]:
"""Each shipping account (Signify, Oak Street, and RubiconMD as its own
subsidiary account) has its own UPS carrier_id, even where the physical
warehouse is shared."""
settings = config.load_settings()
prefix = "SIGNIFY_RETURN_" if company == "Signify Health" else "OAKSTREET_RETURN_"
prefix = _return_config_prefix(order)
return settings.get(f"{prefix}CARRIER_ID", ""), settings.get(f"{prefix}SERVICE_CODE", "")
@@ -321,14 +337,14 @@ def create_return_label(order: Order, packages: List[dict], charge_event: str |
if not api_key:
raise ShipStationSendError("ShipStation API Key is not set. Add it in Settings.")
carrier_id, service_code = _return_carrier_for_company(order.company)
carrier_id, service_code = _return_carrier_for_order(order)
if not carrier_id or not service_code:
raise ShipStationSendError(
f"No return-label Carrier ID/Service Code configured for '{order.company}'. "
"Add them in Settings under Return Labels."
)
return_address = _return_address_for_company(order.company)
return_address = _return_address_for_order(order)
if not (
return_address["address_line1"]
and return_address["city_locality"]