fix(repair): populate assigned_technician_name and ensure model imports
This commit is contained in:
parent
96599e9562
commit
c5ba684bdc
4 changed files with 20 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ import ulid
|
|||
|
||||
from app.core.database.db_session import Base
|
||||
from app.models.audit_base import AuditMixin
|
||||
from app.models.CrmModel import CrmCustomer
|
||||
|
||||
class CrmCustomerDevice(Base, AuditMixin):
|
||||
__tablename__ = "crm_customer_devices"
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from sqlalchemy import Column, String, Boolean, DateTime, Integer, Numeric, Fore
|
|||
from sqlalchemy.sql import func
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.core.database.db_session import Base
|
||||
from app.models.CustomerDeviceModel import CustomerDevice
|
||||
|
||||
class ServiceCatalog(Base):
|
||||
__tablename__ = "service_catalog"
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ class CrmRepairTicketCreate(BaseModel):
|
|||
device_id: str
|
||||
issue_description: str
|
||||
assigned_technician_id: Optional[str] = None
|
||||
assigned_technician_name: Optional[str] = None
|
||||
is_warranty_claim: Optional[bool] = False
|
||||
notes: Optional[str] = None
|
||||
|
||||
|
|
@ -51,6 +52,7 @@ class CrmRepairTicketResponse(BaseModel):
|
|||
customer_id: str
|
||||
device_id: str
|
||||
assigned_technician_id: Optional[str] = None
|
||||
assigned_technician_name: Optional[str] = None
|
||||
stage: str
|
||||
issue_description: str
|
||||
diagnostic_checklist_json: Optional[Dict[str, Any]] = None
|
||||
|
|
|
|||
|
|
@ -117,6 +117,11 @@ class RepairErpService:
|
|||
)
|
||||
)
|
||||
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)
|
||||
|
||||
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())
|
||||
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:
|
||||
self._enrich_ticket(t)
|
||||
if t.assigned_technician_id:
|
||||
t.assigned_technician_name = tech_map.get(t.assigned_technician_id)
|
||||
return tickets
|
||||
|
||||
def update_stage(self, ticket_id: str, data: CrmRepairTicketUpdateStage) -> Optional[CrmRepairTicket]:
|
||||
|
|
|
|||
Loading…
Reference in a new issue