fix(repair): populate assigned_technician_name and ensure model imports

This commit is contained in:
iFixKart Dev 2026-11-16 18:54:30 +05:30
parent 96599e9562
commit c5ba684bdc
4 changed files with 20 additions and 0 deletions

View file

@ -5,6 +5,7 @@ import ulid
from app.core.database.db_session import Base from app.core.database.db_session import Base
from app.models.audit_base import AuditMixin from app.models.audit_base import AuditMixin
from app.models.CrmModel import CrmCustomer
class CrmCustomerDevice(Base, AuditMixin): class CrmCustomerDevice(Base, AuditMixin):
__tablename__ = "crm_customer_devices" __tablename__ = "crm_customer_devices"

View file

@ -2,6 +2,7 @@ from sqlalchemy import Column, String, Boolean, DateTime, Integer, Numeric, Fore
from sqlalchemy.sql import func from sqlalchemy.sql import func
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from app.core.database.db_session import Base from app.core.database.db_session import Base
from app.models.CustomerDeviceModel import CustomerDevice
class ServiceCatalog(Base): class ServiceCatalog(Base):
__tablename__ = "service_catalog" __tablename__ = "service_catalog"

View file

@ -26,6 +26,7 @@ class CrmRepairTicketCreate(BaseModel):
device_id: str device_id: str
issue_description: str issue_description: str
assigned_technician_id: Optional[str] = None assigned_technician_id: Optional[str] = None
assigned_technician_name: Optional[str] = None
is_warranty_claim: Optional[bool] = False is_warranty_claim: Optional[bool] = False
notes: Optional[str] = None notes: Optional[str] = None
@ -51,6 +52,7 @@ class CrmRepairTicketResponse(BaseModel):
customer_id: str customer_id: str
device_id: str device_id: str
assigned_technician_id: Optional[str] = None assigned_technician_id: Optional[str] = None
assigned_technician_name: Optional[str] = None
stage: str stage: str
issue_description: str issue_description: str
diagnostic_checklist_json: Optional[Dict[str, Any]] = None diagnostic_checklist_json: Optional[Dict[str, Any]] = None

View file

@ -117,6 +117,11 @@ class RepairErpService:
) )
) )
ticket = self.db.execute(stmt).scalar_one_or_none() ticket = self.db.execute(stmt).scalar_one_or_none()
if ticket and ticket.assigned_technician_id:
from app.models.UserModel import User
tech_user = self.db.query(User).filter(User.user_id == ticket.assigned_technician_id).first()
if tech_user:
ticket.assigned_technician_name = (tech_user.display_name or f"{tech_user.first_name} {tech_user.last_name}").strip()
return self._enrich_ticket(ticket) return self._enrich_ticket(ticket)
def list_tickets(self, skip: int = 0, limit: int = 50, stage: Optional[str] = None, technician_id: Optional[str] = None) -> List[CrmRepairTicket]: def list_tickets(self, skip: int = 0, limit: int = 50, stage: Optional[str] = None, technician_id: Optional[str] = None) -> List[CrmRepairTicket]:
@ -135,8 +140,19 @@ class RepairErpService:
stmt = stmt.offset(skip).limit(limit).order_by(CrmRepairTicket.created_at.desc()) stmt = stmt.offset(skip).limit(limit).order_by(CrmRepairTicket.created_at.desc())
tickets = list(self.db.execute(stmt).scalars().all()) tickets = list(self.db.execute(stmt).scalars().all())
tech_ids = {t.assigned_technician_id for t in tickets if t.assigned_technician_id}
tech_map = {}
if tech_ids:
from app.models.UserModel import User
tech_users = self.db.query(User).filter(User.user_id.in_(tech_ids)).all()
tech_map = {
u.user_id: (u.display_name or f"{u.first_name} {u.last_name}").strip()
for u in tech_users
}
for t in tickets: for t in tickets:
self._enrich_ticket(t) self._enrich_ticket(t)
if t.assigned_technician_id:
t.assigned_technician_name = tech_map.get(t.assigned_technician_id)
return tickets return tickets
def update_stage(self, ticket_id: str, data: CrmRepairTicketUpdateStage) -> Optional[CrmRepairTicket]: def update_stage(self, ticket_id: str, data: CrmRepairTicketUpdateStage) -> Optional[CrmRepairTicket]: