feat: add order item exception system for graceful product matching
Replaces the "fail on missing product" behavior with graceful handling: - Orders import even when products aren't found by GTIN - Unmatched items link to a per-vendor placeholder product - Exceptions tracked in order_item_exceptions table for QC resolution - Order confirmation blocked until exceptions are resolved - Auto-matching when products are imported via catalog sync New files: - OrderItemException model and migration - OrderItemExceptionService with CRUD and resolution logic - Admin and vendor API endpoints for exception management - Domain exceptions for error handling Modified: - OrderItem: added needs_product_match flag and exception relationship - OrderService: graceful handling with placeholder products - MarketplaceProductService: auto-match on product import - Letzshop confirm endpoints: blocking check for unresolved exceptions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
21
app/api/v1/vendor/letzshop.py
vendored
21
app/api/v1/vendor/letzshop.py
vendored
@@ -18,7 +18,12 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_current_vendor_api
|
||||
from app.core.database import get_db
|
||||
from app.exceptions import ResourceNotFoundException, ValidationException
|
||||
from app.exceptions import (
|
||||
OrderHasUnresolvedExceptionsException,
|
||||
ResourceNotFoundException,
|
||||
ValidationException,
|
||||
)
|
||||
from app.services.order_item_exception_service import order_item_exception_service
|
||||
from app.services.letzshop import (
|
||||
CredentialsNotFoundError,
|
||||
LetzshopClientError,
|
||||
@@ -434,7 +439,12 @@ def confirm_order(
|
||||
current_user: User = Depends(get_current_vendor_api),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""Confirm inventory units for a Letzshop order."""
|
||||
"""
|
||||
Confirm inventory units for a Letzshop order.
|
||||
|
||||
Raises:
|
||||
OrderHasUnresolvedExceptionsException: If order has unresolved product exceptions
|
||||
"""
|
||||
vendor_id = current_user.token_vendor_id
|
||||
order_service = get_order_service(db)
|
||||
creds_service = get_credentials_service(db)
|
||||
@@ -444,6 +454,13 @@ def confirm_order(
|
||||
except OrderNotFoundError:
|
||||
raise ResourceNotFoundException("LetzshopOrder", str(order_id))
|
||||
|
||||
# Check for unresolved exceptions (blocks confirmation)
|
||||
unresolved_count = order_item_exception_service.get_unresolved_exception_count(
|
||||
db, order_id
|
||||
)
|
||||
if unresolved_count > 0:
|
||||
raise OrderHasUnresolvedExceptionsException(order_id, unresolved_count)
|
||||
|
||||
# Get inventory unit IDs from request or order
|
||||
if confirm_request and confirm_request.inventory_unit_ids:
|
||||
inventory_unit_ids = confirm_request.inventory_unit_ids
|
||||
|
||||
Reference in New Issue
Block a user