Hi guys, new to Odoo, i have to fetch the category a product is related to, using the read method of Odoo API. I get a list of objects, then for each category i need to extract the field product_tmpl_ids, a list of integers. I'm not sure how to do it. This is the method:
public List readModelfields(String modelName, List<Integer>ids, List<String> fields, Integer uid)throws XmlRpcException {
List record = (List)Arrays.asList((Object[])models.execute("execute_kw", Arrays.asList(
db, uid, password,
modelName, "read",
ids,
new HashMap() {{
put("fields", fields);
}}
)));
return record;
}
This is the rest of the code:
List<String> fields = new ArrayList<>();
fields.add("product_tmpl_ids");
List categoryIds = (List<Integer>)service.searchByStrParameter("product.public.category", "name", "A - Administration / Office", uid);
List result = (List)service.readModelfields("product.public.category", categoryIds, fields, uid);
Can anybody help? how to extract the fields from the fetched objects?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Boekhouding
- Voorraad
- PoS
- Project
- MRP
Deze vraag is gerapporteerd
This is the solution to my problem:
public List searchReadModelfields(String modelName, List domain, List<String> fields, Integer uid) throws XmlRpcException {
return (List)Arrays.asList((Object[])models.execute("execute_kw", Arrays.asList(
db, uid, password,
modelName,
"search_read",
Arrays.asList(domain),
new HashMap() {{
put("fields", fields);
}}
)));
}
List<String> fields = new ArrayList<>();
fields.add("product_tmpl_ids");
List domain = Arrays.asList(Arrays.asList("name", "=", "A - Administration / Office"));
// return list of hashmaps)
List result = (List)service.searchReadModelfields("product.public.category", domain, fields, uid);
HashMap values;
Integer partner_id;
Object[] category_ids;
for(Object partner_data: result) {
values = (HashMap)partner_data;
partner_id = (Integer) values.get("id");
category_ids = (Object [])values.get("product_tmpl_ids");
System.out.printf("{partner_id: %s, ", partner_id);
System.out.print("category_ids:[");
for(Object category_id: category_ids) {
System.out.printf("%s,",
category_id
);
}
System.out.println("]}");
}
You're the best.
Hi Simeon:
You may find the following useful. There are examples of Java code on the right for each of the calls.
https://www.odoo.com/documentation/13.0/webservices/odoo.html
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!
Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!
AanmeldenGerelateerde posts | Antwoorden | Weergaven | Activiteit | |
---|---|---|---|---|
|
1
dec. 22
|
2627 | ||
|
3
jan. 23
|
7514 | ||
|
0
sep. 22
|
2949 | ||
|
1
mrt. 22
|
5380 | ||
|
1
feb. 22
|
5538 |