Improve AI logic

This commit is contained in:
Urtzi Alfaro
2025-11-05 13:34:56 +01:00
parent 5c87fbcf48
commit 394ad3aea4
218 changed files with 30627 additions and 7658 deletions

View File

@@ -388,7 +388,8 @@ async def resolve_or_create_products_batch(
request: BatchProductResolutionRequest,
tenant_id: UUID = Path(..., description="Tenant ID"),
current_user: Dict[str, Any] = Depends(get_current_user_dep),
db: AsyncSession = Depends(get_db)
db: AsyncSession = Depends(get_db),
classifier: ProductClassifierService = Depends(get_product_classifier)
):
"""Resolve or create multiple products in a single optimized operation for sales import"""
try:
@@ -415,11 +416,14 @@ async def resolve_or_create_products_batch(
resolved_count += 1
logger.debug("Resolved existing product", product=product_name, tenant_id=tenant_id)
else:
category = product_data.get('category', 'general')
# Use the product classifier to determine the appropriate type
suggestion = classifier.classify_product(product_name)
category = product_data.get('category', suggestion.category if hasattr(suggestion, 'category') else 'general')
ingredient_data = {
'name': product_name,
'type': 'finished_product',
'unit': 'unit',
'type': suggestion.product_type.value if hasattr(suggestion, 'product_type') else 'finished_product',
'unit': suggestion.unit_of_measure.value if hasattr(suggestion, 'unit_of_measure') else 'unit',
'current_stock': 0,
'reorder_point': 0,
'cost_per_unit': 0,
@@ -429,7 +433,8 @@ async def resolve_or_create_products_batch(
created = await service.create_ingredient_fast(ingredient_data, tenant_id, db)
product_mappings[product_name] = str(created.id)
created_count += 1
logger.debug("Created new product", product=product_name, tenant_id=tenant_id)
logger.debug("Created new product", product=product_name,
product_type=ingredient_data['type'], tenant_id=tenant_id)
except Exception as e:
logger.warning("Failed to resolve/create product",