@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)Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Bogføring
- Lager
- PoS
- Projekt
- MRP
Dette spørgsmål er blevet anmeldt
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.
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Tilmeld dig| Related Posts | Besvarelser | Visninger | Aktivitet | |
|---|---|---|---|---|
|
|
3
mar. 25
|
5982 | ||
|
|
1
jan. 22
|
5875 | ||
|
|
0
jan. 22
|
3618 | ||
|
|
0
maj 21
|
4833 | ||
|
|
1
apr. 25
|
3347 |
Informative, i will copying for future.
Thanks Pradip, I am referring to the customer who will raise the ticket