Remove Sitar API fallback logic from get_all method in USTariffFractionService
This commit is contained in:
@@ -63,44 +63,43 @@ class USTariffFractionService:
|
||||
Estrategia: Sitar API -> Fallback Local DB
|
||||
"""
|
||||
|
||||
# 1. Try Sitar API
|
||||
try:
|
||||
sitar_service = FraccionesUSAService.get_instance()
|
||||
|
||||
sitar_fraccion = None
|
||||
has_filters = False
|
||||
|
||||
if filters and filters.get("search"):
|
||||
term = filters["search"]
|
||||
# Sitar only filters by fraction code
|
||||
if term.replace(".", "").isdigit():
|
||||
sitar_fraccion = term
|
||||
has_filters = True
|
||||
|
||||
sitar_items = await sitar_service.search(
|
||||
fraccion=sitar_fraccion,
|
||||
skip=skip,
|
||||
limit=limit
|
||||
)
|
||||
|
||||
# If Sitar returns empty list, attempt fallback to local DB
|
||||
if not sitar_items:
|
||||
logger.info(f"Sitar returned no results for USA query (filters={has_filters}). Attempting fallback to local DB.")
|
||||
return USTariffFractionService._get_all_local(db, tenant_id, company_id, skip, limit, filters)
|
||||
## 1. Try Sitar API
|
||||
#try:
|
||||
# sitar_service = FraccionesUSAService.get_instance()
|
||||
#
|
||||
# sitar_fraccion = None
|
||||
# has_filters = False
|
||||
#
|
||||
# if filters and filters.get("search"):
|
||||
# term = filters["search"]
|
||||
# # Sitar only filters by fraction code
|
||||
# if term.replace(".", "").isdigit():
|
||||
# sitar_fraccion = term
|
||||
# has_filters = True
|
||||
#
|
||||
# sitar_items = await sitar_service.search(
|
||||
# fraccion=sitar_fraccion,
|
||||
# skip=skip,
|
||||
# limit=limit
|
||||
# )
|
||||
#
|
||||
# # If Sitar returns empty list, attempt fallback to local DB
|
||||
# if not sitar_items:
|
||||
# logger.info(f"Sitar returned no results for USA query (filters={has_filters}). Attempting fallback to local DB.")
|
||||
# return USTariffFractionService._get_all_local(db, tenant_id, company_id, skip, limit, filters)
|
||||
#
|
||||
# # Map items
|
||||
# items = [USTariffFractionMapper.to_domain(item, tenant_id, company_id) for item in sitar_items]
|
||||
#
|
||||
# # Estimate total
|
||||
# total = len(items) + skip
|
||||
# if len(items) == limit:
|
||||
# total += 1
|
||||
#
|
||||
# return items, total
|
||||
|
||||
# Map items
|
||||
items = [USTariffFractionMapper.to_domain(item, tenant_id, company_id) for item in sitar_items]
|
||||
|
||||
# Estimate total
|
||||
total = len(items) + skip
|
||||
if len(items) == limit:
|
||||
total += 1
|
||||
|
||||
return items, total
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error fetching USA Fractions from Sitar API, falling back to local DB: {e}")
|
||||
return USTariffFractionService._get_all_local(db, tenant_id, company_id, skip, limit, filters)
|
||||
#except Exception as e:
|
||||
return USTariffFractionService._get_all_local(db, tenant_id, company_id, skip, limit, filters)
|
||||
|
||||
@staticmethod
|
||||
def _get_all_local(
|
||||
|
||||
Reference in New Issue
Block a user