Improve the frontend 2

This commit is contained in:
Urtzi Alfaro
2025-10-29 06:58:05 +01:00
parent 858d985c92
commit 36217a2729
98 changed files with 6652 additions and 4230 deletions

View File

@@ -150,3 +150,72 @@ class EquipmentRepository(ProductionBaseRepository):
except Exception as e:
logger.error("Error deleting equipment", error=str(e), equipment_id=str(equipment_id))
raise
async def hard_delete_equipment(self, equipment_id: UUID) -> bool:
"""Permanently delete equipment from database"""
try:
equipment = await self.get(equipment_id)
if not equipment:
return False
await self.session.delete(equipment)
await self.session.flush()
return True
except Exception as e:
logger.error("Error hard deleting equipment", error=str(e), equipment_id=str(equipment_id))
raise
async def get_equipment_deletion_summary(self, tenant_id: UUID, equipment_id: UUID) -> Dict[str, Any]:
"""Get summary of what will be affected by deleting equipment"""
try:
equipment = await self.get_equipment_by_id(tenant_id, equipment_id)
if not equipment:
return {
"can_delete": False,
"warnings": ["Equipment not found"],
"production_batches_count": 0,
"maintenance_records_count": 0,
"temperature_logs_count": 0
}
# Check for related production batches
from app.models.production import ProductionBatch
batch_query = select(func.count(ProductionBatch.id)).filter(
and_(
ProductionBatch.tenant_id == tenant_id,
ProductionBatch.equipment_id == equipment_id
)
)
batch_result = await self.session.execute(batch_query)
batches_count = batch_result.scalar() or 0
# For now, we'll use placeholder counts for maintenance and temperature logs
# These would need to be implemented based on your actual models
maintenance_count = 0
temperature_logs_count = 0
warnings = []
if batches_count > 0:
warnings.append(f"{batches_count} production batch(es) are using this equipment")
# Equipment can be deleted even with dependencies, but warn the user
can_delete = True
return {
"can_delete": can_delete,
"warnings": warnings,
"production_batches_count": batches_count,
"maintenance_records_count": maintenance_count,
"temperature_logs_count": temperature_logs_count,
"equipment_name": equipment.name,
"equipment_type": equipment.type.value,
"equipment_location": equipment.location
}
except Exception as e:
logger.error("Error getting equipment deletion summary",
error=str(e),
equipment_id=str(equipment_id),
tenant_id=str(tenant_id))
raise

View File

@@ -132,6 +132,16 @@ class QualityTemplateRepository(ProductionBaseRepository):
existing = await self.get_by_filters(and_(*filters))
return existing is not None
async def get_by_filters(self, *filters):
"""Get a single record by filters"""
try:
query = select(self.model).where(and_(*filters))
result = await self.session.execute(query)
return result.scalar_one_or_none()
except Exception as e:
logger.error("Error getting record by filters", error=str(e), filters=str(filters))
raise
async def get_templates_by_ids(
self,
tenant_id: str,
@@ -149,4 +159,4 @@ class QualityTemplateRepository(ProductionBaseRepository):
QualityCheckTemplate.is_required.desc(),
QualityCheckTemplate.weight.desc()
]
)
)