feat: Add Canadian fraction management dialog, implement debounced search for historical fractions and sectors, and enhance USA fraction search with description support.
This commit is contained in:
@@ -145,12 +145,23 @@ class TariffFractionService:
|
||||
try:
|
||||
usa_service = FraccionesUSAService.get_instance()
|
||||
search_term = None
|
||||
search_description = None
|
||||
|
||||
if filters and filters.get("search"):
|
||||
search_term = filters["search"]
|
||||
term = filters["search"]
|
||||
# Simple heuristic: if it looks like a code, use code search, else description
|
||||
# FIX: Short numeric codes (e.g. "01") often fail strict 'fraccion' search.
|
||||
# Treat them as description search for partial matching.
|
||||
clean_term = term.replace(".", "")
|
||||
if clean_term.isdigit() and len(clean_term) >= 4:
|
||||
search_term = term
|
||||
else:
|
||||
search_description = term
|
||||
|
||||
# USA Service search signature: fraccion, skip, limit
|
||||
# USA Service search signature: fraccion, descripcion, skip, limit
|
||||
usa_items = await usa_service.search(
|
||||
fraccion=search_term,
|
||||
descripcion=search_description,
|
||||
skip=skip,
|
||||
limit=limit
|
||||
)
|
||||
@@ -161,7 +172,9 @@ class TariffFractionService:
|
||||
total += 1
|
||||
return items, total
|
||||
except Exception as e:
|
||||
import traceback
|
||||
logger.error(f"Error fetching USA fractions (API): {e}")
|
||||
logger.error(traceback.format_exc())
|
||||
# Return empty list on error as per requirement (since API is broken)
|
||||
return [], 0
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ class FraccionesUSAService(SitarAPIBaseService):
|
||||
async def search(
|
||||
self,
|
||||
fraccion: Optional[str] = None,
|
||||
descripcion: Optional[str] = None,
|
||||
skip: int = 0,
|
||||
limit: int = 100,
|
||||
) -> List[FraccionesUSAResponse]:
|
||||
@@ -28,6 +29,8 @@ class FraccionesUSAService(SitarAPIBaseService):
|
||||
params = {"skip": skip, "limit": min(limit, 1000)}
|
||||
if fraccion:
|
||||
params["fraccion"] = fraccion
|
||||
if descripcion:
|
||||
params["descripcion"] = descripcion
|
||||
|
||||
data = await self._make_request("GET", "api/v1/fracciones-usa/", params=params)
|
||||
return [FraccionesUSAResponse(**item) for item in data]
|
||||
|
||||
Reference in New Issue
Block a user