DeBortoliWines / openerp-java-api

A Java API to connect to OpenERP and manage data using the XMLRPC interface.
Apache License 2.0
38 stars 71 forks source link

Limit and Offset not working #56

Closed agucortes closed 4 years ago

agucortes commented 4 years ago

Hi, i'm trying to search and read setting a limit and offset. When i use de function searchAndReadObject an error of formating comes out DataError: invalid input syntax for integer: "name" LINE 2: ... WHERE "product_product".id IN ('name', 'd... so i tried executeCommandWithContext and send there in a hash map the limit and offset (like the examples in the odoo api doc). This way it works, but not limiting the results. Any idea how can i aproach this issue? PS: i'm running odoo 8 and using the upto9 branch

agucortes commented 4 years ago

after i wrote i tried executing this: executeCommandWithContext("product.product","search_read",arrayOf(productoAd.validateFilters(filtro),mapOf("fields" to arrayOf("name", "default_code","list_price")),5,20,"name ASC"))) And it works. Somewhere i read the search allways returns all the elements for pagination. The problem is that searchAndReadObject still not working. I think the problem might comes out because: searchAndReadObject first execute a search (that returns all the values) and the with the returned Id's it perform the read. and the search isn't formating well

agucortes commented 4 years ago

Well... the solution was to re write in ObjectAdapter the function searchAndReadObject. And write a new function in OdooCommand to implement the "search_read". There are the modifications: in ObjectAdapter

public RowCollection searchAndReadObject(final FilterCollection filter, final String[] fields, int offset, int limit, String order) throws XmlRpcException, OdooApiException {

   String[] fieldArray = fields == null ? new String[]{} : fields;
   Object[] preparedFilters = validateFilters(filter);
   Object[] idList = null;
   Response response = command.searchAndReadObject(modelName, preparedFilters,fieldArray,offset,limit,order);
   if (response.isSuccessful()) {
       idList = response.getResponseObjectAsArray();
   }
   FieldCollection fieldCol = new FieldCollection();
   for (String fieldName : fieldArray) {
       for (Field fld : allFields) {
           if (fld.getName().equals(fieldName)) {
               fieldCol.add(fld);
           }
       }
   }
   return new RowCollection(response.getResponseObjectAsArray(), fieldCol);

}

in OdooCommand

public Response searchAndReadObject(String objectName, Object[] filter, String[] fields, int offset, int limit, String order) throws XmlRpcException {

    Response readResult;
    Object offsetParam = offset < 0 ? false : offset;
    Object limitParam = limit < 0 ? false : limit;
    Object orderParam = order == null || order.length() == 0 ? false : order;
    if (this.session.getServerVersion().getMajor() >= 8) {
        readResult = new Response(session.executeCommandWithContext(objectName, "search_read", new Object[]{filter, fields,offsetParam,limitParam,orderParam}));
    } else {
        //TODO: Have to be rewritten/deleted considering the previous call
        readResult = new Response(session.executeCommand(objectName, "search_read", new Object[]{filter, fields, session.getContext(),offsetParam,limitParam,orderParam}));
    }

    return readResult;
}

This is working fine in odoo 8