@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:
- ลูกค้าสัมพันธ์
- e-Commerce
- ระบบบัญชี
- สินค้าคงคลัง
- PoS
- โปรเจกต์
- MRP
คำถามนี้ถูกตั้งค่าสถานะ
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.
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!
สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!
ลงชื่อ| Related Posts | ตอบกลับ | มุมมอง | กิจกรรม | |
|---|---|---|---|---|
|
|
3
มี.ค. 25
|
5982 | ||
|
|
1
ม.ค. 22
|
5875 | ||
|
|
0
ม.ค. 22
|
3618 | ||
|
|
0
พ.ค. 21
|
4833 | ||
|
|
1
เม.ย. 25
|
3347 |
Informative, i will copying for future.
Thanks Pradip, I am referring to the customer who will raise the ticket