Skip to Content
Menú
This question has been flagged
841 Vistes

Hello.


I am trying to assign a client to a helpdesk ticket, I am doing it through the phone number, I search for it in the contacts and the name found should be written in the partner_id field. In certain phone numbers, a modification of the payload message must be made. But in no case does it find the contact even though the phone number registered in Odoo exists.




# Payload data

ticket_contact_phone = payload.get('freshdesk_webhook', {}).get('ticket_contact_phone')


# Delete number '1' in some numbers (MEX ) 

if ticket_contact_phone.startswith('+521'):

    ticket_contact_phone = ticket_contact_phone.replace('+521', '+52', 1)


formatted_phone = ticket_contact_phone

partner_id = False


# Search the contact in Odoo using the full number

partner = env['res.partner'].search([('phone', '=', formatted_phone)], limit=1)


# If the contact is not found, search without the country code

if not partner and len(ticket_contact_phone) > 7:

    formatted_phone_without_country_code = formatted_phone[-7:]

    partner = env['res.partner'].search([('phone', 'ilike', formatted_phone_without_country_code)], limit=1)


if partner:

    partner_id = partner.id


# Create ticket

ticket = env['helpdesk.ticket'].with_user(SUPERUSER_ID).create({

...


    'partner_id': partner_id,


....


})

Avatar
Descartar
Related Posts Respostes Vistes Activitat
1
de jul. 25
400
1
de febr. 25
1213
0
de set. 23
2159
2
de juny 23
3923
1
d’ag. 22
12691