@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)Cette question a été signalée
Hi Hemanth,
@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:
team = env["helpdesk.ticket.team"].sudo().search([
('id', '=', request_user_data.requestTypeId)
])
if not team:
return JSONResponse(
content={"success": "false", "detail": "Request Type id not found"},
status_code=404
)
# -----------------------------------------
# 1. Create Ticket
# -----------------------------------------
ticket = env['helpdesk.ticket'].sudo().create({
'wallet_id': request_user_data.walletId,
'name': team.name,
'description': request_user_data.description,
'team_id': request_user_data.requestTypeId,
})
# -----------------------------------------
#2. CUSTOMER EMAIL from request body
# NOTE: Adjusting logic according to the email you are getting
# -----------------------------------------
customer_email = getattr(request_user_data, "customer_email", None)
if not customer_email:
print("No customer email found")
else:
# -----------------------------------------
#3. Find or create customer partner
# -----------------------------------------
Partner = env['res.partner'].sudo()
partner = Partner.search([('email', '=', customer_email)], limit=1)
if not partner:
partner = Partner.create({
"name": getattr(request_user_data, "customer_name", customer_email),
"email": customer_email,
})
else:
# NEW LINE → Adjust email to match external input
partner.write({"email": customer_email})
# -----------------------------------------
#4. Add customer as follower
# -----------------------------------------
ticket.message_subscribe(partner_ids=[partner.id])
# -----------------------------------------
# Response
# -----------------------------------------
return JSONResponse(content={
"success": "true",
"ticket_id": ticket.id,
"ticket_number": ticket.number,
"detail": "Ticket created and customer subscribed",
})
except Exception as e:
return JSONResponse(
content={"detail": "Error processing ticket", "error": str(e)},
status_code=500
)
If you have any questions, feel free to reach out.
Hope this helps!
Thanks and Regards,
Email: odoo@aktivsoftware.com
If you intend to add an internal user as a follower, you need to assign the user to the user_id field. Alternatively, if you wish to add a customer as a follower, you must assign them to the partner_id field. Based on this, Odoo will automatically add them to the followers list.
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !
Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !
S'inscrire| Publications associées | Réponses | Vues | Activité | |
|---|---|---|---|---|
|
|
2
janv. 26
|
1441 | ||
|
|
1
mars 26
|
1823 | ||
|
|
3
mars 25
|
7639 | ||
|
|
1
janv. 22
|
6925 | ||
|
|
0
janv. 22
|
4338 |
Informative, i will copying for future.
Thanks Pradip, I am referring to the customer who will raise the ticket
Thank you, Jainesh Shah. If a user replies to the email, I’d like their response to appear in Helpdesk. How can we configure this?