I am currently working with Odoo Helpdesk and have an external application where users can raise support requests. My goal is to ensure that whenever a user submits a request through my app, a corresponding ticket is automatically created in Odoo Helpdesk.
Additionally, once the ticket is created, I want the user to receive an automatic email acknowledgement confirming that their request has been received (I already created a template for this). This email should also serve as the starting point for any further communication related to the ticket.
I am implementing this integration using FastAPI. At the moment, I have a very basic endpoint that collects only minimal information from the user. But, I am unsure about the best approach for handling the email functionality:
@helpdesk_api_router.post("/ticket/add")
async def add_ticket(
current_user: Annotated[schemas.User, Depends(user.get_current_active_user)],
request: Request,
request_user_data: schemas.AddTicket,
env=Depends(odoo_env)
):
try:
search_departnment = env["helpdesk.ticket.team"].sudo().search([('id', '=', request_user_data.requestTypeId)])
if not search_departnment:
data = {
"success": "false",
"detail": "Request Type id not found",
}
return JSONResponse(content=data, status_code=404)
# Create ticket
ticket_data = env['helpdesk.ticket'].sudo().create({
'wallet_id': request_user_data.walletId,
'name': search_departnment.name,
'description': request_user_data.description,
'team_id': request_user_data.requestTypeId,
})
data = {
"success": "true",
"ticket_id": ticket_data.id,
"ticket_number": ticket_data.number,
"detail": "Ticket added successfully",
}
return JSONResponse(content=data)
except Exception as e:
# Handle exceptions, log errors, and return an appropriate response
return JSONResponse(content={"detail": "Error processing the ticket"}, status_code=500)