phase-5: contracts, warranties, insurance, demo equipment, and department visits

This commit is contained in:
Atharv1705
2026-11-12 14:31:01 +05:30
parent d3f22ba444
commit ba4777b182
32 changed files with 6379 additions and 38 deletions
@@ -1,6 +1,7 @@
from pathlib import Path
from uuid import uuid4
from fastapi import UploadFile
from sqlalchemy import func
from sqlalchemy.orm import Session, joinedload
from ..core.config import settings
@@ -302,3 +303,15 @@ def delete_attachment(db: Session, user: User, attachment_id: int) -> None:
)
db.delete(att)
db.commit()
def get_attachment_counts(db: Session, entity_type: str, entity_ids: list[int]) -> dict[int, int]:
if not entity_ids:
return {}
rows = (
db.query(Attachment.entity_id, func.count(Attachment.id))
.filter(Attachment.entity_type == entity_type, Attachment.entity_id.in_(entity_ids))
.group_by(Attachment.entity_id)
.all()
)
return {eid: cnt for eid, cnt in rows}