Good day everyone, I'm currently building a custom module and utilizing its controllers to create an external api with custom logic for endpoints like /api/auth/login , /api/auth/whoami etc. Basically it's an attendance logging api for my custom module and is integrated to a mobile application. Currently, I was looking how to make it so that my endpoint for attendnace logging could send notifications to the mobile application. I was thinking of utilizing a websocket and odoo has it's own websocket but i'm having a hard time how to implement it. For reference, here is the endpoint where i want to integrate a notification and basically establish a websocket connection.
# ───────────────────────────────────────────────────────────────
# ATTENDANCE – /api/attendance/log (POST)
# ───────────────────────────────────────────────────────────────
@http.route(
"/api/attendance/log", type="http", auth="public", csrf=False, methods=["POST"]
)
def log_attendance(self):
user = self._current_user()
if not user:
return self._json({"error": "Unauthorized"}, 401)
if user.share:
return self._json({"error": "Access denied: internal users only"}, 403)
try:
data = json.loads(request.httprequest.data or "{}")
except Exception:
return self._json({"error": "Malformed JSON body"}, 400)
enrollment_id = data.get("enrollment_id")
log_type = data.get("log_type")
if not enrollment_id or not log_type:
return self._json({"error": "enrollment_id and log_type are required"}, 400)
enrollment = request.env["sis.enrollment"].sudo().browse(int(enrollment_id))
if not enrollment.exists():
return self._json({"error": "Student does not exist"}, 404)
try:
log = (
request.env["sis.student.attendance.log"]
.sudo()
.create(
{
"enrollment_id": enrollment.id,
"log_type": log_type,
}
)
)
except ValidationError as ve:
return self._json({"error": str(ve)}, 400)
except Exception as e:
_logger.exception("Failed to log attendance")
return self._json({"error": str(e)}, 500)
return self._json(
{
"status": "success",
"log_id": log.id,
"student_name": enrollment.full_name,
"section_name": enrollment.section_id.display_name,
},
201,
)
So basically it is an attendance logging of a student and i want to notify their parent in the mobile application once their son/daughter times in/out of their school