Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

3

OpenERP Java API

By
Arnaud
on 3/2/13, 7:06 AM 3,380 views

Hi everybody.

Sorry to bother you but i'm newbie on using Open ERP webservices functionnalities. So I decided to use the OpenERP Java API in order to communicate with the Open Erp XML-RPC webservices.

At the moment, i manage to get the information about a sale order but i couldn't get data about the partner who order it.

Here is my code sample :

@WebMethod()
public Integer deployDocumentAPI(String nameFile) throws MalformedURLException {
    Session openERPSession = new Session("192.168.0.18", 8069, "hiveSharing", "webservice", "root");
    try {
        // startSession logs into the server and keeps the userid of the logged in user
        openERPSession.startSession();
        ObjectAdapter orderAd = openERPSession.getObjectAdapter("sale.order");
        FilterCollection filters = new FilterCollection();
        filters.add("name","=","SO001");
        RowCollection orders = orderAd.searchAndReadObject(filters, new String[]{"name","state","partner_id"});

        for (Row row : orders){
            System.out.println("Row ID: " + row.getID());
            System.out.println("Name:" + row.get("name"));
            System.out.println("Etat:" + row.get("state"));

            //everything is ok up to here

            //Adapter partner
            ObjectAdapter partnerAd = openERPSession.getObjectAdapter("res.partner");

            //row.get("partner_id") gives me an object that i can't manage to use

            RowCollection partners = partnerAd.readObject((Object[]) row.get("partner_id"), new String[]{"name"});

            for (Row rowP : partners){
                System.out.println("Partner:" + rowP.get("name"));
            }

        }
        return 1;

    } catch (Exception e) {
        System.out.println("Error while reading data from server:\n\n" + e.getMessage());
        return 0;
    }
}

According to the error I get, the readObject method is waiting for a collection of ids but how can i get the ids if I'am unable to read the object .....

It makes me crazy.

If someone is familiar to this APi, please help me ^^

PS : I'm french so sorry for my english ;-)

3
TestUser
On 4/10/13, 3:48 AM

Try this way:

Object partnerID[] = (Object[]) row.get("partner_id"); System.out.println(partnerID[0]);

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 3/2/13, 7:06 AM
Seen: 3380 times
Last updated: 3/16/15, 8:10 AM