demo seed change 7
This commit is contained in:
@@ -320,12 +320,20 @@ class SustainabilityService:
|
||||
'damaged_inventory': inventory_waste * 0.3, # Estimate: 30% damaged
|
||||
}
|
||||
|
||||
# Get waste incidents from food safety repository
|
||||
food_safety_repo = FoodSafetyRepository(db)
|
||||
waste_opportunities = await food_safety_repo.get_waste_opportunities(tenant_id)
|
||||
|
||||
# Sum up all waste incidents for the period
|
||||
total_waste_incidents = sum(item['waste_incidents'] for item in waste_opportunities) if waste_opportunities else 0
|
||||
# Count waste incidents from stock movements
|
||||
total_waste_incidents = 0
|
||||
try:
|
||||
# Calculate days back from start_date to now
|
||||
days_back = (end_date - start_date).days if start_date and end_date else 30
|
||||
waste_movements = await stock_movement_repo.get_waste_movements(
|
||||
tenant_id=tenant_id,
|
||||
days_back=days_back,
|
||||
limit=1000 # Get all waste movements
|
||||
)
|
||||
total_waste_incidents = len(waste_movements) if waste_movements else 0
|
||||
except Exception as e:
|
||||
logger.warning("Could not get waste incidents count", error=str(e))
|
||||
total_waste_incidents = 0
|
||||
|
||||
return {
|
||||
'total_waste_kg': total_waste,
|
||||
|
||||
Reference in New Issue
Block a user