Improve the frontend 2
This commit is contained in:
@@ -1501,6 +1501,9 @@ class ProductionService:
|
||||
# Create equipment
|
||||
equipment = await equipment_repo.create_equipment(equipment_dict)
|
||||
|
||||
# Commit the transaction to persist changes
|
||||
await session.commit()
|
||||
|
||||
logger.info("Created equipment",
|
||||
equipment_id=str(equipment.id), tenant_id=str(tenant_id))
|
||||
|
||||
@@ -1529,6 +1532,9 @@ class ProductionService:
|
||||
equipment_update.model_dump(exclude_none=True)
|
||||
)
|
||||
|
||||
# Commit the transaction to persist changes
|
||||
await session.commit()
|
||||
|
||||
logger.info("Updated equipment",
|
||||
equipment_id=str(equipment_id), tenant_id=str(tenant_id))
|
||||
|
||||
@@ -1554,6 +1560,9 @@ class ProductionService:
|
||||
# Soft delete equipment
|
||||
success = await equipment_repo.delete_equipment(equipment_id)
|
||||
|
||||
# Commit the transaction to persist changes
|
||||
await session.commit()
|
||||
|
||||
logger.info("Deleted equipment",
|
||||
equipment_id=str(equipment_id), tenant_id=str(tenant_id))
|
||||
|
||||
@@ -1564,6 +1573,60 @@ class ProductionService:
|
||||
error=str(e), equipment_id=str(equipment_id), tenant_id=str(tenant_id))
|
||||
raise
|
||||
|
||||
async def hard_delete_equipment(self, tenant_id: UUID, equipment_id: UUID) -> bool:
|
||||
"""Permanently delete an equipment item from database"""
|
||||
try:
|
||||
async with self.database_manager.get_session() as session:
|
||||
from app.repositories.equipment_repository import EquipmentRepository
|
||||
equipment_repo = EquipmentRepository(session)
|
||||
|
||||
# First verify equipment belongs to tenant
|
||||
equipment = await equipment_repo.get_equipment_by_id(tenant_id, equipment_id)
|
||||
if not equipment:
|
||||
return False
|
||||
|
||||
# Get deletion summary first for logging
|
||||
summary = await equipment_repo.get_equipment_deletion_summary(tenant_id, equipment_id)
|
||||
|
||||
# Hard delete equipment
|
||||
success = await equipment_repo.hard_delete_equipment(equipment_id)
|
||||
|
||||
# Commit the transaction to persist changes
|
||||
await session.commit()
|
||||
|
||||
logger.info("Hard deleted equipment",
|
||||
equipment_id=str(equipment_id),
|
||||
tenant_id=str(tenant_id),
|
||||
affected_batches=summary.get("production_batches_count", 0))
|
||||
|
||||
return success
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Error hard deleting equipment",
|
||||
error=str(e), equipment_id=str(equipment_id), tenant_id=str(tenant_id))
|
||||
raise
|
||||
|
||||
async def get_equipment_deletion_summary(self, tenant_id: UUID, equipment_id: UUID) -> Dict[str, Any]:
|
||||
"""Get deletion summary for an equipment item"""
|
||||
try:
|
||||
async with self.database_manager.get_session() as session:
|
||||
from app.repositories.equipment_repository import EquipmentRepository
|
||||
equipment_repo = EquipmentRepository(session)
|
||||
|
||||
summary = await equipment_repo.get_equipment_deletion_summary(tenant_id, equipment_id)
|
||||
|
||||
logger.info("Retrieved equipment deletion summary",
|
||||
equipment_id=str(equipment_id),
|
||||
tenant_id=str(tenant_id),
|
||||
can_delete=summary.get("can_delete", False))
|
||||
|
||||
return summary
|
||||
|
||||
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
|
||||
|
||||
# ================================================================
|
||||
# SUSTAINABILITY / WASTE ANALYTICS
|
||||
# ================================================================
|
||||
|
||||
Reference in New Issue
Block a user