Hey all,
I stumbled upon quite a cumbersome problem while creating a data processing workflow.
I have data returned from an API. I want to save each of these fields to the Odoo model custom.info.value
.
[
{
"phone_number": "+11234567890",
"name": "Cool Corp",
"latitude": 90.11,
"longitude": 20.20,
"review_count": 100,
"rating": 5
}
]
For context, this model comes from a module called custom_info
. It features three main models:
-
custom.info.property
- Where you define properties and their type -
custom.info.value
- Where property values are stored -
custom.info.template
- Where you build templates by assembling properties
Example
Usually when you save data to Odoo using n8n - let’s say - creating a new partner, here’s what you do:
In this workflow, you already know the name of the field you wish to save your expression value to. You simply need to map your expression containing your value to the appropriate field and that’s it.
Now, in the case of the custom_info
module, it’s not that simple.
Custom Info Module
Knowing that each row in the custom.info.value
model must be linked to a property_id
(a row inside the custom.info.property
model), you can easily create “blank rows” in the latter. Meaning that you’d then have to update each of these rows with your desired value - in this case, the ones coming from the API data.
This means that your value is implictly linked to the property_id
.
Let’s say you have a property_id
1
with the name of Longitude
and wish to save the value longitude
from your API into a new line. This would be easily feasible using a node per value, but in the case of a loop, you don’t want to do all of that manually.
The issue is that you’d have to match the property with both the field name of your value the value itself:
Any clues?
Make sure to ping me if there’s a need for clarifications.