Im new with Odoo development, I am currently setting up a Python script that takes all products from the product.product model and return them to a JSON file. (id, name, display_name, list_price, product_tmpl_id, qty_available).
I saw many names with (kopie) in, (duplicate) in english. In the UI of odoo the names are correct and dont have (duplicate) in the name.
What I analyse from this is that the names when exported using the API are not always the same than in the UI of odoo. The product.product id and product.template id point to eachother
An example:
Scraped using the API:
name: Apple (kopie)
product.product id: 1234
product.template id: 5678
In odoo UI:
Scraped using the API:
name: Orange
product.product id: 1234
product.template id: 5678
My question is how, hoe does this happen? I am currently manually fixing them with code to be the same name in the database than in the UI. I appreciate the help and couldn't really find a good answer on this.
Pertanyaan ini telah diberikan tanda
2
Replies
1155
Tampilan
If you have names in different languages, you need to specify in the API call which language you want the name for.
Send via Context the language {'lang': 'en_AU'} (for English, Australian) during all API calls to get what you expect when using the translation framework.
record = models.execute_kw(db, uid, password,'product.template', 'read',[product_id],
{'context': {'lang': 'en_AU'},
'fields': ['id', 'name', 'default_code', 'display_name', 'description']
})
This is a common confusion when working with Odoo's product model for the first time.
The reason you are seeing (kopie) or (duplicate) in the API response is because those are duplicated product templates that were created at some point, possibly during testing or data migration, and the name was never cleaned up. In the Odoo UI, the display_name is sometimes rendered differently based on context, which is why it looks correct on screen but shows the raw stored name via the API.
To fix this cleanly:
Instead of pulling from product.product, try pulling from product.template first and use the name field there. product.product inherits its name from product.template, and duplicates often carry over the (kopie) suffix from the template level.
Add a filter in your Python script to exclude any product where the name contains kopie or duplicate while you clean the data:
products = models.execute_kw(db, uid, password, 'product.product', 'search_read', [[['name', 'not like', 'kopie']]], {'fields': ['id', 'name', 'display_name', 'list_price', 'product_tmpl_id', 'qty_available']})
Long term, go into Odoo Settings, enable developer mode, and do a bulk cleanup of duplicate product templates so the root data is clean before export.
The core issue is dirty product data at the template level, not the API itself. Once the source data is clean, your JSON export will be accurate.
Hope that helps. Let me know if you run into anything else.
Menikmati diskusi? Jangan hanya membaca, ikuti!
Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!
Daftar| Post Terkait | Replies | Tampilan | Aktivitas | |
|---|---|---|---|---|
|
|
3
Feb 26
|
3342 | ||
|
|
0
Des 25
|
1857 | ||
|
|
2
Mar 24
|
5747 | ||
|
|
0
Agu 21
|
5548 | ||
|
How to add sale order with lines with JSON2 API?
Diselesaikan
|
|
1
Feb 26
|
2262 |