The examples I have seen focus on finding an existing record in Odoo to update it.
How would I create a brand new record?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
The examples I have seen focus on finding an existing record in Odoo to update it.
How would I create a brand new record?
UPDATED FOR Odoo 18.0
Although Odoo does want you to identify an existing record in order for the Webhook to work, you don't need to update it, you can execute any code you like.
In this example, I am using the "User" model, and I am providing the "ID" of 1, which I know will always find the Odoobot User.
The Target Record field is completed with model.browse(int(payload.get('id')))
Note: It is also possible to simplify this to model.search([],limit=1) and use any Model instead of res.user
Then, the code I execute just parses the payload and uses it to create the new record, here I am creating a new Contact (res.partner):
name = payload['name']
env['res.partner'].create({
'name': name,
})
Note that there is no error checking in this example, it will only work if the payload provides the ID of 1 (to find the existing User record) and has a NAME so that I can create a new Contact with that name.
To test, I called the webhook via CURL:
curl -H 'Content-Type: application/json' -d '{ "id": 1,"name": "Ray Carnes (Odoo)" } ' -X POST https://webhooks.odoo.com/web/hook/e63e3705-2fba-4795-98a3-64914be0ba8b
Replace the POST {URL} part with the URL Odoo creates for you
Create an account today to enjoy exclusive features and engage with our awesome community!
Üye Olİlgili Gönderiler | Cevaplar | Görünümler | Aktivite | |
---|---|---|---|---|
|
2
Eki 24
|
4777 | ||
|
1
Oca 20
|
5325 | ||
|
0
Eyl 15
|
3768 | ||
|
2
Şub 25
|
1552 | ||
Problem icon settings new app
Çözüldü
|
|
2
Haz 24
|
1197 |
To create new record: https://www.youtube.com/watch?v=D3urHJ9rB2o