feat: complete requirements gaps - backup/restore, uat signoff, pm attachments, templates, and filters

This commit is contained in:
Atharv1705
2026-11-13 18:15:32 +05:30
parent cd9eb27a98
commit d9ca4bbb02
38 changed files with 1403 additions and 69 deletions
+34 -9
View File
@@ -144,6 +144,7 @@ def _to_complaint_out(
received_at=recv_at,
assigned_to_id=c.assigned_to_id,
assigned_to_name=user_names.get(c.assigned_to_id) if c.assigned_to_id else None,
assigned_team=c.assigned_team,
assigned_at=asg_at,
attended_by_id=c.attended_by_id,
attended_by_name=user_names.get(c.attended_by_id) if c.attended_by_id else None,
@@ -233,6 +234,7 @@ def _sync_asset_status(db: Session, asset: Asset, exclude_complaint_id: int, req
def list_complaints(
q: Optional[str] = None,
department_id: Optional[int] = None,
location_id: Optional[int] = None,
asset_id: Optional[int] = None,
call_status: Optional[str] = None,
priority: Optional[str] = None,
@@ -260,6 +262,9 @@ def list_complaints(
elif department_id is not None:
query = query.filter(Asset.department_id == department_id)
if location_id is not None:
query = query.filter(Asset.location_id == location_id)
if asset_id is not None:
query = query.filter(Complaint.asset_id == asset_id)
if call_status:
@@ -372,6 +377,7 @@ def create_complaint(
breakdown_details=payload.breakdown_details,
priority=payload.priority,
notes=payload.notes,
assigned_team=payload.assigned_team,
registered_at=reg_at,
registered_by_id=current_user.id,
received_by_id=recv_by_id,
@@ -555,19 +561,34 @@ def assign_complaint(
current_user: User = Depends(require_roles(Role.system_admin, Role.biomedical)),
):
comp = _load_complaint_or_404(db, complaint_id)
assignee = db.query(User).filter(User.id == payload.assigned_to_id, User.is_active.is_(True)).first()
if assignee is None:
raise HTTPException(status_code=404, detail="Assigned user not found or inactive.")
if payload.assigned_to_id is None and not payload.assigned_team:
raise HTTPException(status_code=422, detail="Either assigned_to_id or assigned_team must be provided.")
assignee: Optional[User] = None
target_name = payload.assigned_team or ""
if payload.assigned_to_id is not None:
assignee = db.query(User).filter(User.id == payload.assigned_to_id, User.is_active.is_(True)).first()
if assignee is None:
raise HTTPException(status_code=404, detail="Assigned user not found or inactive.")
target_name = assignee.name
if payload.assigned_team:
target_name = f"{assignee.name} ({payload.assigned_team})"
old_name: Optional[str] = None
event_type = "assigned"
if comp.assigned_to_id is not None:
if comp.assigned_to_id is not None or comp.assigned_team:
event_type = "reassigned"
old_user = db.query(User.name).filter(User.id == comp.assigned_to_id).first()
old_name = old_user[0] if old_user else str(comp.assigned_to_id)
if comp.assigned_to_id is not None:
old_user = db.query(User.name).filter(User.id == comp.assigned_to_id).first()
old_name = old_user[0] if old_user else str(comp.assigned_to_id)
if comp.assigned_team:
old_name = f"{old_name} ({comp.assigned_team})" if old_name else comp.assigned_team
now = utc_now()
comp.assigned_to_id = assignee.id
if assignee:
comp.assigned_to_id = assignee.id
if payload.assigned_team is not None:
comp.assigned_team = payload.assigned_team.strip() or None
comp.assigned_at = now
if comp.call_status == "open":
comp.call_status = "in_progress"
@@ -578,7 +599,7 @@ def assign_complaint(
complaint_id=comp.id,
event_type=event_type,
from_value=old_name,
to_value=assignee.name,
to_value=target_name,
by_user_id=current_user.id,
at=now,
note=payload.note,
@@ -589,7 +610,11 @@ def assign_complaint(
entity_type="complaint",
entity_id=comp.id,
action=event_type,
changes={"assigned_to_id": assignee.id, "note": payload.note},
changes={
"assigned_to_id": comp.assigned_to_id,
"assigned_team": comp.assigned_team,
"note": payload.note,
},
user_id=current_user.id,
)
db.commit()