From 232ef80a6eadbb5aa765269030390a6c3ee35365 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 8 Nov 2025 07:37:12 +0000 Subject: [PATCH] fix: Correct production batch date filtering to check start date only The previous logic required batches to both START and END within the date range, which excluded batches that start today but end later. Now correctly filters batches based on their planned_start_time only, so today's batches include all batches scheduled to start today regardless of their end time. Fixes bug where PENDING batches with today's start date were not appearing in the dashboard production timeline. --- .../app/repositories/production_batch_repository.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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()