Flow improvements
This commit is contained in:
@@ -564,7 +564,7 @@ async def bulk_log_movement(
|
||||
else:
|
||||
ppr.out_to = entry.to_location or ppr.out_to
|
||||
ppr.pob_out = entry.pob or ppr.pob_out
|
||||
ppr.departed_dt = timestamp
|
||||
ppr.takeoff_dt = timestamp
|
||||
if ppr.status not in (PPRStatus.DELETED, PPRStatus.CANCELED):
|
||||
ppr.status = PPRStatus.DEPARTED
|
||||
if entry.notes:
|
||||
|
||||
@@ -222,13 +222,21 @@ async def update_ppr_status(
|
||||
|
||||
# Send real-time update
|
||||
if hasattr(request.app.state, 'connection_manager'):
|
||||
event_timestamp = None
|
||||
if ppr.status == PPRStatus.LANDED and ppr.landed_dt:
|
||||
event_timestamp = ppr.landed_dt.isoformat()
|
||||
elif ppr.status == PPRStatus.LOCAL and ppr.takeoff_dt:
|
||||
event_timestamp = ppr.takeoff_dt.isoformat()
|
||||
elif ppr.status == PPRStatus.DEPARTED and ppr.qsy_dt:
|
||||
event_timestamp = ppr.qsy_dt.isoformat()
|
||||
|
||||
await request.app.state.connection_manager.broadcast({
|
||||
"type": "status_update",
|
||||
"data": {
|
||||
"id": ppr.id,
|
||||
"ac_reg": ppr.ac_reg,
|
||||
"status": ppr.status.value,
|
||||
"timestamp": ppr.landed_dt.isoformat() if ppr.landed_dt else (ppr.departed_dt.isoformat() if ppr.departed_dt else None)
|
||||
"timestamp": event_timestamp
|
||||
}
|
||||
})
|
||||
|
||||
@@ -348,7 +356,7 @@ async def update_ppr_public(
|
||||
detail="Invalid or expired token"
|
||||
)
|
||||
# Only allow editing if not already processed
|
||||
if ppr.status in [PPRStatus.CANCELED, PPRStatus.DELETED, PPRStatus.LANDED, PPRStatus.DEPARTED]:
|
||||
if ppr.status in [PPRStatus.CANCELED, PPRStatus.DELETED, PPRStatus.LANDED, PPRStatus.LOCAL, PPRStatus.DEPARTED]:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="PPR cannot be edited at this stage"
|
||||
@@ -373,7 +381,7 @@ async def cancel_ppr_public(
|
||||
detail="Invalid or expired token"
|
||||
)
|
||||
# Only allow canceling if not already processed
|
||||
if ppr.status in [PPRStatus.CANCELED, PPRStatus.DELETED, PPRStatus.LANDED, PPRStatus.DEPARTED]:
|
||||
if ppr.status in [PPRStatus.CANCELED, PPRStatus.DELETED, PPRStatus.LANDED, PPRStatus.LOCAL, PPRStatus.DEPARTED]:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="PPR cannot be cancelled at this stage"
|
||||
|
||||
@@ -145,7 +145,8 @@ async def get_public_departures(db: Session = Depends(get_db)):
|
||||
'ac_type': departure.ac_type,
|
||||
'out_to': departure.out_to,
|
||||
'etd': departure.etd,
|
||||
'departed_dt': departure.departed_dt,
|
||||
'takeoff_dt': departure.takeoff_dt,
|
||||
'qsy_dt': departure.qsy_dt,
|
||||
'status': departure.status.value,
|
||||
'isLocalFlight': False,
|
||||
'isDeparture': False
|
||||
|
||||
@@ -58,6 +58,7 @@ class CRUDPPR:
|
||||
PPRRecord.status == PPRStatus.NEW,
|
||||
PPRRecord.status == PPRStatus.CONFIRMED,
|
||||
PPRRecord.status == PPRStatus.LANDED,
|
||||
PPRRecord.status == PPRStatus.LOCAL,
|
||||
PPRRecord.status == PPRStatus.DEPARTED
|
||||
)
|
||||
)
|
||||
@@ -71,6 +72,7 @@ class CRUDPPR:
|
||||
func.date(PPRRecord.etd) == today,
|
||||
or_(
|
||||
PPRRecord.status == PPRStatus.LANDED,
|
||||
PPRRecord.status == PPRStatus.LOCAL,
|
||||
PPRRecord.status == PPRStatus.DEPARTED
|
||||
)
|
||||
)
|
||||
@@ -151,8 +153,10 @@ class CRUDPPR:
|
||||
current_time = timestamp if timestamp is not None else datetime.utcnow()
|
||||
if status == PPRStatus.LANDED:
|
||||
db_obj.landed_dt = current_time
|
||||
elif status == PPRStatus.LOCAL:
|
||||
db_obj.takeoff_dt = current_time
|
||||
elif status == PPRStatus.DEPARTED:
|
||||
db_obj.departed_dt = current_time
|
||||
db_obj.qsy_dt = current_time
|
||||
|
||||
db.add(db_obj)
|
||||
db.commit()
|
||||
|
||||
@@ -9,6 +9,7 @@ class PPRStatus(str, Enum):
|
||||
CONFIRMED = "CONFIRMED"
|
||||
CANCELED = "CANCELED"
|
||||
LANDED = "LANDED"
|
||||
LOCAL = "LOCAL"
|
||||
DELETED = "DELETED"
|
||||
DEPARTED = "DEPARTED"
|
||||
ACTIVATED = "ACTIVATED"
|
||||
@@ -40,7 +41,8 @@ class PPRRecord(Base):
|
||||
phone = Column(String(16), nullable=True)
|
||||
notes = Column(Text, nullable=True)
|
||||
landed_dt = Column(DateTime, nullable=True)
|
||||
departed_dt = Column(DateTime, nullable=True)
|
||||
takeoff_dt = Column(DateTime, nullable=True)
|
||||
qsy_dt = Column(DateTime, nullable=True)
|
||||
created_by = Column(String(16), nullable=True, index=True)
|
||||
submitted_dt = Column(DateTime, nullable=False, server_default=func.current_timestamp(), index=True)
|
||||
acknowledged_dt = Column(DateTime, nullable=True)
|
||||
|
||||
@@ -9,6 +9,7 @@ class PPRStatus(str, Enum):
|
||||
CONFIRMED = "CONFIRMED"
|
||||
CANCELED = "CANCELED"
|
||||
LANDED = "LANDED"
|
||||
LOCAL = "LOCAL"
|
||||
DELETED = "DELETED"
|
||||
DEPARTED = "DEPARTED"
|
||||
ACTIVATED = "ACTIVATED"
|
||||
@@ -85,7 +86,8 @@ class PPRInDBBase(PPRBase):
|
||||
id: int
|
||||
status: PPRStatus
|
||||
landed_dt: Optional[datetime] = None
|
||||
departed_dt: Optional[datetime] = None
|
||||
takeoff_dt: Optional[datetime] = None
|
||||
qsy_dt: Optional[datetime] = None
|
||||
created_by: Optional[str] = None
|
||||
submitted_dt: datetime
|
||||
acknowledged_dt: Optional[datetime] = None
|
||||
@@ -111,7 +113,8 @@ class PPRPublic(BaseModel):
|
||||
out_to: Optional[str] = None
|
||||
etd: Optional[datetime] = None
|
||||
landed_dt: Optional[datetime] = None
|
||||
departed_dt: Optional[datetime] = None
|
||||
takeoff_dt: Optional[datetime] = None
|
||||
qsy_dt: Optional[datetime] = None
|
||||
submitted_dt: datetime
|
||||
|
||||
class Config:
|
||||
|
||||
Reference in New Issue
Block a user