Ir al contenido
Menú
Se marcó esta pregunta
7 Respuestas
3607 Vistas

I am creating a webhook that imports customer data from a CSV.

I am fairly new to this as this was recently added to Odoo 17 as a standard feature.

I have seen multi good videos etc and how to setup the automation rules.

However, all samples I see are about changing a record. What I am struggling what if what will the Target record code be for a new record and not a get.id code for an existing record. 

Avatar
Descartar
Mejor respuesta

Hi Laurent,

I happend to have the exact same usecase as you.
We want to trigger webhooks from a remote system to create a new record instead of updating existing records.
After digging in the core code from Odoo (https://github.com/odoo/odoo/blob/ad299c9325e0a0faf18ba8b2709d4be2829b7158/addons/base_automation/models/base_automation.py#L473-L516) I found out that Odoo in fact simply doesn't support it.. *shrugs*

I've opened a pull request (code change) that serves as a basis to discuss a possible solution for this in the core. You can view it at https://github.com/odoo/odoo/pull/154408

Regards,
Yenthe

Avatar
Descartar
Autor

Thanks Yenthe,
You are obviously much more familiar with this coding. However what you are saying, Create record through webhook, get the new record ID and the fill this record with data is exactly what I as novice expected already to be in place. Hopefully soon.

Mejor respuesta

Hi,

To create new record using webhook, see the method explained here:  Create a New Record Using Webhook in Odoo 17

Thanks

Avatar
Descartar
Mejor respuesta

Use this odoo plugin to send or receive data from external website

Odoo Store Plugin: "odoo_dynamic_webhooks".

Avatar
Descartar
Mejor respuesta

Use this odoo plugin to send or receive data from external website

Odoo Store Plugin: "odoo_dynamic_webhooks"

Avatar
Descartar
Mejor respuesta

Hi does anyone have answer to this pls? 

Avatar
Descartar
Mejor respuesta

+1 to trying to figure this out too.

I tried creating a new record in the Target Record field with 

env['crm.lead'].create({'name': payload['name': 'foo']})

but it looks like this happens in a safety evaluation here. I'm not sure what that entails yet but that throws many errors I haven't decided to look into yet.

It also looks like it's not bringing in the env variable like it says it is right above it or I'm not accessing it correctly. I feel like env['crm.leads']​ shouldn't come back with an error that env is undefined.

I tried selecting a dummy record statically and then creating it in my Execute Code block too but that's causing all kinds of 500 page dead errors:

env['crm.lead'].create({
    'name': "FooBar",
    "user_id": 2
})

But this kicks back a 'dict' object has no attribute 'name'​ error from ir.logging when I wrap it in an except block. 

Avatar
Descartar
Mejor respuesta

Have you seen this, which covers sending and receiving records:


Avatar
Descartar
Autor

Thanks Ray, I know this video inside out already. While I certainly recommend it for anyone starting with Webhooks, it does not address the core issue I am facing. The sample shows also use update records etc, there is no example worked out to create a record.
In odoo the Target record field needs to be filled in. However what do I need to fill in there since the"target" record does not exist yet but I want it to be created.

Publicaciones relacionadas Respuestas Vistas Actividad
0
jul 24
1220
4
mar 24
2738
2
jun 16
3130
3
ene 16
4455
0
dic 24
674