Help

3

OpenERP Java API

Avatar
Arnaud

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 ;-)

Avatar
Discard
1 Answer
3
Avatar
TestUser
Best Answer

Try this way:

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

Avatar
Discard