Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

How can i parse xml-rpc respnse (Odoo API read method), using Java

Subscribe

Get notified when there's activity on this post

This question has been flagged
apixmlrpcjavareadparse
2 Replies
9342 Views
Avatar
Simeon Damyanov

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?

0
Avatar
Discard
Avatar
Simeon Damyanov
Author Best Answer

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("]}");
}
 

1
Avatar
Discard
Elhamdaoui Abdelmajid

You're the best.

Avatar
Paresh Wagh
Best Answer

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

1
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Java xmlrpc not working
external api xmlrpc java
Avatar
Avatar
1
Dec 22
3630
XML-RPC API search_read method 100 records' limitation
api xmlrpc
Avatar
Avatar
Avatar
3
Jan 23
9443
how to retrieve selection field string value through External API search_read while retrieving model records
api read
Avatar
0
Sep 22
3680
XMLRPC API Search and Read - How to Supply Multiple Filters Solved
api xmlrpc
Avatar
1
Mar 22
6541
(\'Error, a partner cannot follow twice the same object.\', None)\n'>
api xmlrpc
Avatar
Avatar
1
Feb 22
6689
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now