Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Artificial Intelligence
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Property Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

How to add user email as follower when creating Odoo ticket

Subscribe

Get notified when there's activity on this post

This question has been flagged
pythontickethelpdeskV16
2 Replies
1393 Views
Avatar
Hemanth
I have this FastAPI endpoint that creates a ticket in my Odoo helpdesk (V16) application from an external request. How can I obtain the user’s email and add them as a follower to the ticket so they will receive an email whenever we reply?

@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)


0
Avatar
Discard
nhavna

Informative, i will copying for future.

Hemanth
Author

Thanks Pradip, I am referring to the customer who will raise the ticket

Hemanth
Author

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?

Avatar
Jainesh Shah(Aktiv Software)
Best Answer

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

0
Avatar
Discard
Avatar
Pradip Rangvani
Best Answer
Hi, could you please clarify whether you're referring to an internal user or a customer, and what data you're getting from the request?

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.

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Handling Media in Odoo Helpdesk via External App Solved
ticket helpdesk media V16
Avatar
Avatar
Avatar
2
Jan 26
1409
No Notification or Easy Way to Track Email Replies from Customers
ticket email helpdesk V16
Avatar
Avatar
1
Mar 26
1783
Reply by email to helpdesk ticket problem Solved
ticket helpdesk
Avatar
Avatar
Avatar
3
Mar 25
7558
[ODOO 11]: Creating new ticket from automated action not working Solved
python ticket automated actions helpdesk
Avatar
1
Jan 22
6912
Change sender email address depending on helpdesk
python helpdesk
Avatar
0
Jan 22
4313
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk Slovenščina Español (América Latina) Español Svenska ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now