fix UI 1
This commit is contained in:
@@ -342,11 +342,67 @@ class InventoryService:
|
||||
|
||||
logger.info("Stock added successfully", stock_id=stock.id, quantity=stock.current_quantity)
|
||||
return response
|
||||
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Failed to add stock", error=str(e), tenant_id=tenant_id)
|
||||
raise
|
||||
|
||||
async def bulk_add_stock(
|
||||
self,
|
||||
bulk_data: 'BulkStockCreate',
|
||||
tenant_id: UUID,
|
||||
user_id: Optional[UUID] = None
|
||||
) -> 'BulkStockResponse':
|
||||
"""Bulk add stock entries for efficient batch operations"""
|
||||
import uuid as uuid_lib
|
||||
from app.schemas.inventory import BulkStockCreate, BulkStockResult, BulkStockResponse
|
||||
|
||||
transaction_id = str(uuid_lib.uuid4())
|
||||
results = []
|
||||
total_created = 0
|
||||
total_failed = 0
|
||||
|
||||
for index, stock_data in enumerate(bulk_data.stocks):
|
||||
try:
|
||||
stock_response = await self.add_stock(stock_data, tenant_id, user_id)
|
||||
results.append(BulkStockResult(
|
||||
index=index,
|
||||
success=True,
|
||||
stock=stock_response,
|
||||
error=None
|
||||
))
|
||||
total_created += 1
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
"Failed to create stock in bulk operation",
|
||||
index=index,
|
||||
ingredient_id=stock_data.ingredient_id,
|
||||
error=str(e)
|
||||
)
|
||||
results.append(BulkStockResult(
|
||||
index=index,
|
||||
success=False,
|
||||
stock=None,
|
||||
error=str(e)
|
||||
))
|
||||
total_failed += 1
|
||||
|
||||
logger.info(
|
||||
"Bulk stock operation completed",
|
||||
transaction_id=transaction_id,
|
||||
total_requested=len(bulk_data.stocks),
|
||||
total_created=total_created,
|
||||
total_failed=total_failed
|
||||
)
|
||||
|
||||
return BulkStockResponse(
|
||||
total_requested=len(bulk_data.stocks),
|
||||
total_created=total_created,
|
||||
total_failed=total_failed,
|
||||
results=results,
|
||||
transaction_id=transaction_id
|
||||
)
|
||||
|
||||
async def consume_stock(
|
||||
self,
|
||||
ingredient_id: UUID,
|
||||
|
||||
Reference in New Issue
Block a user