Add quality template logic
This commit is contained in:
@@ -104,7 +104,7 @@ class ProductionAlertService(BaseAlertService, AlertServiceMixin):
|
||||
JOIN production_capacity pc ON pc.equipment_id = p.equipment_id
|
||||
WHERE p.planned_date >= CURRENT_DATE
|
||||
AND p.planned_date <= CURRENT_DATE + INTERVAL '3 days'
|
||||
AND p.status IN ('planned', 'in_progress')
|
||||
AND p.status IN ('PENDING', 'IN_PROGRESS')
|
||||
AND p.tenant_id = $1
|
||||
GROUP BY p.tenant_id, p.planned_date
|
||||
)
|
||||
@@ -226,10 +226,10 @@ class ProductionAlertService(BaseAlertService, AlertServiceMixin):
|
||||
COALESCE(pb.priority::text, 'medium') as priority_level,
|
||||
1 as affected_orders -- Default to 1 since we can't count orders
|
||||
FROM production_batches pb
|
||||
WHERE pb.status IN ('IN_PROGRESS', 'DELAYED')
|
||||
WHERE pb.status IN ('IN_PROGRESS', 'ON_HOLD', 'QUALITY_CHECK')
|
||||
AND (
|
||||
(pb.planned_end_time < NOW() AND pb.status = 'IN_PROGRESS')
|
||||
OR pb.status = 'DELAYED'
|
||||
OR pb.status IN ('ON_HOLD', 'QUALITY_CHECK')
|
||||
)
|
||||
AND pb.planned_end_time > NOW() - INTERVAL '24 hours'
|
||||
ORDER BY
|
||||
@@ -831,7 +831,7 @@ class ProductionAlertService(BaseAlertService, AlertServiceMixin):
|
||||
FROM production_batches pb
|
||||
JOIN recipe_ingredients ri ON ri.recipe_id = pb.recipe_id
|
||||
WHERE ri.ingredient_id = $1
|
||||
AND pb.status IN ('planned', 'in_progress')
|
||||
AND pb.status IN ('PENDING', 'IN_PROGRESS')
|
||||
AND pb.planned_completion_time > NOW()
|
||||
"""
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class QualityTemplateService:
|
||||
def __init__(self, db: Session):
|
||||
self.db = db
|
||||
|
||||
async def create_template(
|
||||
def create_template(
|
||||
self,
|
||||
tenant_id: str,
|
||||
template_data: QualityCheckTemplateCreate
|
||||
@@ -50,7 +50,7 @@ class QualityTemplateService:
|
||||
|
||||
return template
|
||||
|
||||
async def get_templates(
|
||||
def get_templates(
|
||||
self,
|
||||
tenant_id: str,
|
||||
stage: Optional[ProcessStage] = None,
|
||||
@@ -93,7 +93,7 @@ class QualityTemplateService:
|
||||
|
||||
return templates, total
|
||||
|
||||
async def get_template(
|
||||
def get_template(
|
||||
self,
|
||||
tenant_id: str,
|
||||
template_id: UUID
|
||||
@@ -107,7 +107,7 @@ class QualityTemplateService:
|
||||
)
|
||||
).first()
|
||||
|
||||
async def update_template(
|
||||
def update_template(
|
||||
self,
|
||||
tenant_id: str,
|
||||
template_id: UUID,
|
||||
@@ -115,7 +115,7 @@ class QualityTemplateService:
|
||||
) -> Optional[QualityCheckTemplate]:
|
||||
"""Update a quality check template"""
|
||||
|
||||
template = await self.get_template(tenant_id, template_id)
|
||||
template = self.get_template(tenant_id, template_id)
|
||||
if not template:
|
||||
return None
|
||||
|
||||
@@ -143,14 +143,14 @@ class QualityTemplateService:
|
||||
|
||||
return template
|
||||
|
||||
async def delete_template(
|
||||
def delete_template(
|
||||
self,
|
||||
tenant_id: str,
|
||||
template_id: UUID
|
||||
) -> bool:
|
||||
"""Delete a quality check template"""
|
||||
|
||||
template = await self.get_template(tenant_id, template_id)
|
||||
template = self.get_template(tenant_id, template_id)
|
||||
if not template:
|
||||
return False
|
||||
|
||||
@@ -165,7 +165,7 @@ class QualityTemplateService:
|
||||
|
||||
return True
|
||||
|
||||
async def get_templates_for_stage(
|
||||
def get_templates_for_stage(
|
||||
self,
|
||||
tenant_id: str,
|
||||
stage: ProcessStage,
|
||||
@@ -198,14 +198,14 @@ class QualityTemplateService:
|
||||
QualityCheckTemplate.name
|
||||
).all()
|
||||
|
||||
async def duplicate_template(
|
||||
def duplicate_template(
|
||||
self,
|
||||
tenant_id: str,
|
||||
template_id: UUID
|
||||
) -> Optional[QualityCheckTemplate]:
|
||||
"""Duplicate an existing quality check template"""
|
||||
|
||||
original = await self.get_template(tenant_id, template_id)
|
||||
original = self.get_template(tenant_id, template_id)
|
||||
if not original:
|
||||
return None
|
||||
|
||||
@@ -234,9 +234,9 @@ class QualityTemplateService:
|
||||
}
|
||||
|
||||
create_data = QualityCheckTemplateCreate(**duplicate_data)
|
||||
return await self.create_template(tenant_id, create_data)
|
||||
return self.create_template(tenant_id, create_data)
|
||||
|
||||
async def get_templates_by_recipe_config(
|
||||
def get_templates_by_recipe_config(
|
||||
self,
|
||||
tenant_id: str,
|
||||
stage: ProcessStage,
|
||||
@@ -268,7 +268,7 @@ class QualityTemplateService:
|
||||
|
||||
return templates
|
||||
|
||||
async def validate_template_configuration(
|
||||
def validate_template_configuration(
|
||||
self,
|
||||
tenant_id: str,
|
||||
template_data: dict
|
||||
|
||||
Reference in New Issue
Block a user