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.
This commit is contained in:
Claude
2025-11-08 07:37:12 +00:00
parent fbb76ecc02
commit 232ef80a6e

View File

@@ -643,9 +643,11 @@ class ProductionBatchRepository(ProductionBaseRepository, BatchCountProvider):
if "order_id" in filters: if "order_id" in filters:
query = query.where(ProductionBatch.order_id == filters["order_id"]) query = query.where(ProductionBatch.order_id == filters["order_id"])
if "start_date" in filters: 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: 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 # Apply pagination
offset = (page - 1) * page_size offset = (page - 1) * page_size
@@ -678,9 +680,11 @@ class ProductionBatchRepository(ProductionBaseRepository, BatchCountProvider):
if "order_id" in filters: if "order_id" in filters:
query = query.where(ProductionBatch.order_id == filters["order_id"]) query = query.where(ProductionBatch.order_id == filters["order_id"])
if "start_date" in filters: 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: 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) result = await self.session.execute(query)
count = result.scalar() count = result.scalar()