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
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
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
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
1
thg 12 22
|
2636 | ||
|
3
thg 1 23
|
7526 | ||
|
0
thg 9 22
|
2951 | ||
|
1
thg 3 22
|
5392 | ||
|
1
thg 2 22
|
5541 |