feature/api-sittar-actualizacion
This commit is contained in:
@@ -164,16 +164,13 @@ class TariffFractionService:
|
||||
search_description = term
|
||||
|
||||
try:
|
||||
usa_items = await usa_service.search(
|
||||
usa_items, total = await usa_service.search_with_total(
|
||||
fraccion=search_term,
|
||||
descripcion=search_description,
|
||||
skip=skip,
|
||||
limit=limit,
|
||||
)
|
||||
items = [TariffFractionMapper.to_domain_usa(item) for item in usa_items]
|
||||
total = len(items) + skip
|
||||
if len(items) == limit:
|
||||
total += 1
|
||||
return items, total
|
||||
except Exception as e:
|
||||
import traceback
|
||||
@@ -245,30 +242,25 @@ class TariffFractionService:
|
||||
# Note: Sitar search might not return total count.
|
||||
# We fetch page items. Pagination might be tricky if Sitar doesn't return total.
|
||||
# Assuming Sitar returns a list.
|
||||
sitar_items = await sitar_service.search(
|
||||
sitar_items, total = await sitar_service.search_with_total(
|
||||
fraccion=sitar_fraccion,
|
||||
nico=sitar_nico,
|
||||
description=sitar_description,
|
||||
nivel=level_filter, # Dynamic level
|
||||
skip=skip,
|
||||
limit=limit
|
||||
limit=limit,
|
||||
)
|
||||
|
||||
|
||||
# STRICT API USAGE:
|
||||
# We do NOT fallback to local DB on empty list, as user requested strict API consumption.
|
||||
# We also do NOT attempt enrichment as codes mismatch (API uses '010191A' vs Local '01012101').
|
||||
|
||||
|
||||
# Map items
|
||||
items = [TariffFractionMapper.to_domain(item) for item in sitar_items]
|
||||
# Legacy browse behavior: keep table in ascending fracción order.
|
||||
items = sorted(items, key=lambda row: ((row.code or ""), (row.nico or "")))
|
||||
|
||||
# Estimate total (Sitar service doesn't return total currently)
|
||||
# If we got full limit, assume there are more.
|
||||
total = len(items) + skip
|
||||
if len(items) == limit:
|
||||
total += 1 # Indicate more pages
|
||||
|
||||
|
||||
# total comes from SITAR PaginatedFraccionesResponse (matches API-wide count for the query).
|
||||
return items, total
|
||||
|
||||
except Exception as e:
|
||||
|
||||
@@ -103,7 +103,7 @@ async def list_us_tariff_fractions(
|
||||
search_description = search
|
||||
|
||||
try:
|
||||
sitar_items = await svc.search(
|
||||
sitar_items, total = await svc.search_with_total(
|
||||
fraccion=search_term,
|
||||
descripcion=search_description,
|
||||
skip=skip,
|
||||
@@ -118,10 +118,6 @@ async def list_us_tariff_fractions(
|
||||
"pages": 0,
|
||||
}
|
||||
|
||||
total = len(sitar_items) + skip
|
||||
if len(sitar_items) == page_size:
|
||||
total += 1
|
||||
|
||||
items = [
|
||||
USTariffFractionResponseDTO.model_validate(_sitar_row_to_us_response_payload(row))
|
||||
for row in sitar_items
|
||||
|
||||
Reference in New Issue
Block a user