Abri amend_job amends an OpenHousing appointment and returns the echoed booking 🟩

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Daniel Roth 2026-07-03 16:17:41 +00:00
parent 2cfed0c33d
commit c542a57ae5

View file

@ -7,6 +7,7 @@ from domain.abri.models import (
AbriRequestRejected,
AmendJobRequest,
AmendJobResult,
AppointmentAmended,
JobLogged,
LogJobRequest,
LogJobResult,
@ -48,7 +49,20 @@ class AbriClient:
return self._parse_job_logged(outcome)
def amend_job(self, request: AmendJobRequest) -> AmendJobResult:
raise NotImplementedError
outcome = self._exchange(
request_type="amendoptiappt",
parameters=[
("job_no", request.job_no),
("action", "amend"),
("appointment_date", request.appointment_date.strftime("%d/%m/%Y")),
("appointment_time", request.appointment_time),
],
)
if isinstance(outcome, AbriRequestRejected):
return outcome
return self._parse_appointment_amended(outcome)
def _exchange(
self, request_type: str, parameters: List[Tuple[str, str]]
@ -106,6 +120,31 @@ class AbriClient:
return JobLogged(job_no=job_no, logged_info=logged_info)
@staticmethod
def _parse_appointment_amended(root: ET.Element) -> AppointmentAmended:
amended = root.find("AmendOptiAppt")
if amended is None:
raise AbriResponseParseError(
"AmendOptiAppt element missing from relay response"
)
job_no = amended.get("job_no")
appointment_date = amended.get("appointment_date")
appointment_time = amended.get("appointment_time")
if job_no is None or appointment_date is None or appointment_time is None:
raise AbriResponseParseError(
"AmendOptiAppt element missing job_no, appointment_date "
"or appointment_time"
)
return AppointmentAmended(
job_no=job_no,
appointment_date=appointment_date,
appointment_time=appointment_time,
)
@staticmethod
def _parse_rejection(root: ET.Element) -> AbriRequestRejected:
success = root.findtext("success")