feat/fedex customer references full support#1089
Conversation
|
@ChrisNolan is attempting to deploy a commit to the karrio Team on Vercel. A member of the Team first needs to authorize it. |
70c110f to
1db4e8b
Compare
|
This is great! I was about to put together a PR to address this very issue, but you beat me to it 🥳 |
|
Also about to submit a PR for this same functionality, but glad to see it's already been done! |
|
Reviewed — looks good, approving. Thanks @ChrisNolan — this fixes the long-standing REF-field gap (#1082) and the test coverage is excellent. We're going to apply some cleanups in the release branch (2026.1.32) to bring it in line with karrio conventions, and I'll leave inline notes on the specific spots. In short: build the Merging so it ships in 2026.1.32. |
…1089) Cleanup of the merged #1089 to fit karrio conventions: - Build the customerReferences lists inline in the request tree (the lib.identity / comprehension idiom used by UPS + the rest of FedEx) instead of a collect_customer_references() helper that returned a keyed dict and was called twice per request. - Declare fedex_department_number / fedex_po_number / fedex_rma_association as proper OptionEnums (+ i18n) so they're accessed via options.* and surface in the schema, instead of raw payload.options dict lookups with dual spellings. - Remove now-dead helpers (build_customer_reference, collect_customer_references, CUSTOMER_REFERENCE_MAX_LENGTH) and their imports from utils.py. - Replace the mock-based helper unit tests (test_utils.py) with a request-level assertion in test_shipment.py; the canonical full-dict tests already cover INVOICE_NUMBER + CUSTOMER_REFERENCE output. Serialized output unchanged (51 fedex tests pass).
…1089) Cleanup of the merged #1089 to fit karrio conventions: - Build the customerReferences lists inline in the request tree (the lib.identity / comprehension idiom used by UPS + the rest of FedEx) instead of a collect_customer_references() helper that returned a keyed dict and was called twice per request. - Declare fedex_department_number / fedex_po_number / fedex_rma_association as proper OptionEnums (+ i18n) so they're accessed via options.* and surface in the schema, instead of raw payload.options dict lookups with dual spellings. - Remove now-dead helpers (build_customer_reference, collect_customer_references, CUSTOMER_REFERENCE_MAX_LENGTH) and their imports from utils.py. - Replace the mock-based helper unit tests (test_utils.py) with a request-level assertion in test_shipment.py; the canonical full-dict tests already cover INVOICE_NUMBER + CUSTOMER_REFERENCE output. Serialized output unchanged (51 fedex tests pass).
There was a problem hiding this comment.
Cleanup applied in the 2026.1.32 release branch (patch/2026.1.32): build_customer_reference and collect_customer_references were removed from here.
Why: karrio builds the request tree inline at the call site (see UPS ReferenceNumber and the rest of FedEx's create.py). A helper that returns a {commercial_invoice, package} dict — and is called twice per shipment (once per key) — adds indirection without reuse value, and indexing it by string key is the opposite of inline-tree construction. The per-type length limits are now applied inline via lib.text(value, max=30|20).
There was a problem hiding this comment.
In the release branch both collect_customer_references(...)["..."] calls are now built inline in the request tree as [_ref for _ref in [fedex.CustomerReferenceType(...), ...] if _ref.value] — computed once per site, and each site shows exactly which references it includes.
Also: fedex_department_number, fedex_po_number and fedex_rma_association are now declared as OptionEnums in units.py (with i18n), so they're read via options.<name>.state and surface in the schema — instead of raw payload.options.get("fedex_x") or .get("x") lookups with dual key spellings.
There was a problem hiding this comment.
Removed in the release branch along with the helpers it covered. These also used mock.MagicMock() for payload/customs/options, whereas karrio tests drive gateway.mapper and assert the serialized request. Coverage is now a request-level test (test_shipment.py::test_create_shipment_request_with_customer_references) plus the canonical full-dict tests, which already assert INVOICE_NUMBER + CUSTOMER_REFERENCE output. Thanks for the thorough original coverage — much appreciated.
#1096, #1120, #1095, #1089, #1114, #1118 were merged directly to main by mistake — they belong on the 2026.1.32 release branch (#1128), where the same changes already live (cherry-picks + conventions cleanups). No work is lost; this only removes their effect from main. They will reach main via #1128.
…ovements - pickupType settable via the fedex_pickup_type shipping option, typed with the FedExPickupType enum (#1095, @ChrisNolan). - full multi-type customerReferences (CUSTOMER_REFERENCE/INVOICE_NUMBER/ DEPARTMENT_NUMBER/P_O_NUMBER/RMA_ASSOCIATION), built inline in the request tree; fixes the REF field on labels (#1089, @ChrisNolan; disc #1082). - pickup: map instruction -> remarks, type fedex_pickup_address_type as an enum option, resolve package_location via the FedExPackageLocation enum (#1114, @ChrisNolan). Multi-recipient notification emails deferred (EBE-124).
…es (#1128) * fix(server): critical ops + security fixes for 2026.1.32 - providers: guard migration 0093 against cascade data-loss (#1116) — depend on manager/0079 so carrier FK columns are dropped before the legacy carrier delete. - manager: make migration 0078 production-safe — chunked iterator + bulk_update, idempotent (#1123). - events: batch periodic_data_archiving deletes to avoid first-run OOM (#1125). - settings: import workers before apm so huey binds REDIS_HOST under OTEL (#1124). - settings: scope MD5 PASSWORD_HASHERS to the test runner only (#1096, @mgradalska). - core: clean up async DB connections to stop the tracing connection leak (#1119/#1120 phase 1, @ChrisNolan) + phase-2 PRD. * fix(usps): correct v3 API hosts + vendor official OpenAPI specs - usps + usps_international: update server URLs to apis.usps.com / apis-tem.usps.com after USPS retired the legacy Web Tools / api-cat hosts (#1118, @zebradots). - vendor the official USPS Developer Portal v3 specs (captured 2026-06-23) for usps and usps_international, each with a provenance README. * feat(fedex): pickupType option, full customer references, pickup improvements - pickupType settable via the fedex_pickup_type shipping option, typed with the FedExPickupType enum (#1095, @ChrisNolan). - full multi-type customerReferences (CUSTOMER_REFERENCE/INVOICE_NUMBER/ DEPARTMENT_NUMBER/P_O_NUMBER/RMA_ASSOCIATION), built inline in the request tree; fixes the REF field on labels (#1089, @ChrisNolan; disc #1082). - pickup: map instruction -> remarks, type fedex_pickup_address_type as an enum option, resolve package_location via the FedExPackageLocation enum (#1114, @ChrisNolan). Multi-recipient notification emails deferred (EBE-124). * chore(rules): require explicit permission before writing to main Add a hard guardrail to CLAUDE.md + .claude/rules/git-workflow.md: never merge/push/force-push/revert main (incl. gh pr merge) without explicit per-action permission; contributor PRs integrate into the release branch, not main. Adds the rule that was missing when six PRs were merged to main in error. * fix(dashboard): align tracker client usage with regenerated API types The 2026.1.32 metadata regen renamed the Trackers retrieve/remove path param idOrTrackingNumber -> identifier and made TrackingEvent.description nullable. Update consumers: tracker delete/retrieve calls use { identifier }, and getEventIcon accepts string | null. * release: 2026.1.32 Version bump 2026.1.31 -> 2026.1.32 across packages, regenerated API metadata (REST/GraphQL types, OpenAPI, schemas), CHANGELOG, and frozen requirements. Removes SPRINT_MCP.md. Bumps community + ee/platform submodules to their release commits; ee/insiders stays at v2026.1.29 (its main carries #32 / task_backend, which ship with 2026.5).
…es (karrioapi#1128) * fix(server): critical ops + security fixes for 2026.1.32 - providers: guard migration 0093 against cascade data-loss (karrioapi#1116) — depend on manager/0079 so carrier FK columns are dropped before the legacy carrier delete. - manager: make migration 0078 production-safe — chunked iterator + bulk_update, idempotent (karrioapi#1123). - events: batch periodic_data_archiving deletes to avoid first-run OOM (karrioapi#1125). - settings: import workers before apm so huey binds REDIS_HOST under OTEL (karrioapi#1124). - settings: scope MD5 PASSWORD_HASHERS to the test runner only (karrioapi#1096, @mgradalska). - core: clean up async DB connections to stop the tracing connection leak (karrioapi#1119/karrioapi#1120 phase 1, @ChrisNolan) + phase-2 PRD. * fix(usps): correct v3 API hosts + vendor official OpenAPI specs - usps + usps_international: update server URLs to apis.usps.com / apis-tem.usps.com after USPS retired the legacy Web Tools / api-cat hosts (karrioapi#1118, @zebradots). - vendor the official USPS Developer Portal v3 specs (captured 2026-06-23) for usps and usps_international, each with a provenance README. * feat(fedex): pickupType option, full customer references, pickup improvements - pickupType settable via the fedex_pickup_type shipping option, typed with the FedExPickupType enum (karrioapi#1095, @ChrisNolan). - full multi-type customerReferences (CUSTOMER_REFERENCE/INVOICE_NUMBER/ DEPARTMENT_NUMBER/P_O_NUMBER/RMA_ASSOCIATION), built inline in the request tree; fixes the REF field on labels (karrioapi#1089, @ChrisNolan; disc karrioapi#1082). - pickup: map instruction -> remarks, type fedex_pickup_address_type as an enum option, resolve package_location via the FedExPackageLocation enum (karrioapi#1114, @ChrisNolan). Multi-recipient notification emails deferred (EBE-124). * chore(rules): require explicit permission before writing to main Add a hard guardrail to CLAUDE.md + .claude/rules/git-workflow.md: never merge/push/force-push/revert main (incl. gh pr merge) without explicit per-action permission; contributor PRs integrate into the release branch, not main. Adds the rule that was missing when six PRs were merged to main in error. * fix(dashboard): align tracker client usage with regenerated API types The 2026.1.32 metadata regen renamed the Trackers retrieve/remove path param idOrTrackingNumber -> identifier and made TrackingEvent.description nullable. Update consumers: tracker delete/retrieve calls use { identifier }, and getEventIcon accepts string | null. * release: 2026.1.32 Version bump 2026.1.31 -> 2026.1.32 across packages, regenerated API metadata (REST/GraphQL types, OpenAPI, schemas), CHANGELOG, and frozen requirements. Removes SPRINT_MCP.md. Bumps community + ee/platform submodules to their release commits; ee/insiders stays at v2026.1.29 (its main carries karrioapi#32 / task_backend, which ship with 2026.5).
This change expands FedEx shipment
customerReferencessupport from a single hardcoded invoice reference to full multi-type handling.What changed
CUSTOMER_REFERENCE(from shipment reference)INVOICE_NUMBER(from customs invoice, with options fallback)DEPARTMENT_NUMBER(from options)P_O_NUMBER(from options)RMA_ASSOCIATION(from options)CUSTOMER_REFERENCElimit for Ground compatibility).What is now available (was not before)
fedex_po_number,fedex_department_number,fedex_rma_association) and have them forwarded to FedEx correctly.