diff --git a/services/production/app/repositories/production_batch_repository.py b/services/production/app/repositories/production_batch_repository.py index 4a968ede..995f9507 100644 --- a/services/production/app/repositories/production_batch_repository.py +++ b/services/production/app/repositories/production_batch_repository.py @@ -643,9 +643,11 @@ class ProductionBatchRepository(ProductionBaseRepository, BatchCountProvider): if "order_id" in filters: query = query.where(ProductionBatch.order_id == filters["order_id"]) if "start_date" in filters: - query = query.where(ProductionBatch.planned_start_time >= filters["start_date"]) + # Filter batches that START on or after this date + query = query.where(func.date(ProductionBatch.planned_start_time) >= filters["start_date"]) if "end_date" in filters: - query = query.where(ProductionBatch.planned_end_time <= filters["end_date"]) + # Filter batches that START on or before this date + query = query.where(func.date(ProductionBatch.planned_start_time) <= filters["end_date"]) # Apply pagination offset = (page - 1) * page_size @@ -678,9 +680,11 @@ class ProductionBatchRepository(ProductionBaseRepository, BatchCountProvider): if "order_id" in filters: query = query.where(ProductionBatch.order_id == filters["order_id"]) if "start_date" in filters: - query = query.where(ProductionBatch.planned_start_time >= filters["start_date"]) + # Filter batches that START on or after this date + query = query.where(func.date(ProductionBatch.planned_start_time) >= filters["start_date"]) if "end_date" in filters: - query = query.where(ProductionBatch.planned_end_time <= filters["end_date"]) + # Filter batches that START on or before this date + query = query.where(func.date(ProductionBatch.planned_start_time) <= filters["end_date"]) result = await self.session.execute(query) count = result.scalar()