Fix new services implementation 5

This commit is contained in:
Urtzi Alfaro
2025-08-15 17:53:59 +02:00
parent 03b4d4185d
commit f7de9115d1
43 changed files with 1714 additions and 891 deletions

View File

@@ -97,8 +97,9 @@ class SalesRepository(BaseRepository[SalesData, SalesDataCreate, SalesDataUpdate
# Apply pagination
stmt = stmt.offset(query_params.offset).limit(query_params.limit)
else:
# Default ordering
stmt = stmt.order_by(desc(SalesData.date)).limit(50)
# Default ordering with safety limit for direct repository calls
# Note: API calls always provide query_params, so this only applies to direct usage
stmt = stmt.order_by(desc(SalesData.date)).limit(10000)
result = await self.session.execute(stmt)
records = result.scalars().all()
@@ -279,24 +280,3 @@ class SalesRepository(BaseRepository[SalesData, SalesDataCreate, SalesDataUpdate
logger.error("Failed to validate sales record", error=str(e), record_id=record_id)
raise
async def get_product_statistics(self, tenant_id: str) -> List[Dict[str, Any]]:
"""Get product statistics for tenant"""
try:
# Note: product_name field was removed - product info now managed via inventory service
# This method should be updated to query products from inventory service
# For now, return inventory_product_ids to avoid breaking existing code
stmt = select(SalesData.inventory_product_id).where(
and_(
SalesData.tenant_id == tenant_id,
SalesData.inventory_product_id.is_not(None)
)
).distinct()
result = await self.session.execute(stmt)
products = [str(row[0]) for row in result if row[0]]
return sorted(products)
except Exception as e:
logger.error("Failed to get product categories", error=str(e), tenant_id=tenant_id)
raise