Iteration is not allowed on browse_record

2014-03-16
2014-03-19
  • Mind And Go
    Mind And Go
    2014-03-16

    Hy,

    I'm trying to execute some commands on the object account.move.
    Here is my code :

    Object[] ids = new Object[] { Integer.valueOf(move_id.toString())};
    OpenERPCommand myCommand = openERPSession.getOpenERPCommand();
    result = myCommand.callObjectFunction("account.move","button_validate", ids);
    

    It works perfectly regrading to the call process except that the ids passed are not correctly set. I have always this problem :

    raise NotImplementedError("Iteration is not allowed on %s" % self)
    NotImplementedError: Iteration is not allowed on browse_record
    

    I'm using a workaround for this :
    1 - Override the called method
    2 - Add this part of code at the beginning :

    if isinstance(ids, (int, long)):
    ids = [ids]
    

    Is there a way to pass good parameters to the called function?

    Moreover, I have the same king of issue when the method is returning a simple Boolean for example. I have to turn

    return True
    

    into

    return [True]
    

    If I don't do this, the Boolean result won't be able to be cast as an Object[]

    Any idea to prevent us from overriding function?

     
  • Hi Mind And Go

    The callObjectFunction assumes that the array passed in is separate parameters.

    For your example I would try:

    Object[] ids = new Object[] { Integer.valueOf(move_id.toString())};
    OpenERPCommand myCommand = openERPSession.getOpenERPCommand();
    Object[] params = new Object[] { ids };
    result = myCommand.callObjectFunction("account.move","button_validate", params);
    

    That means that the list of ids is one parameter in stead of a list of parameters.

    Kind Regards,
    Pieter

     
  • Mind And Go
    Mind And Go
    2014-03-18

    Great thanks!!!!

    Thanks for your eternal support

     
  • Mind And Go
    Mind And Go
    2014-03-18

    Still one problem, how can we do when the result of a call is a boolean.
    the message still to be

    java.lang.Boolean cannot be cast to [Ljava.lang.Object;
    
     
  • Hi Mind And Go

    It looks like a limitation I have placed on the call. I need to fix that. For now you could go back to the session class and use its function to execute commands. It is generally safer to use the Adapter and Command classes, but to work around this bug you will have to use the session class.

    On your example it then becomes:

    Object[] ids = new Object[] { Integer.valueOf(move_id.toString())};
    Object[] params = new Object[] { ids };
    result = (Boolean) openERPSession.executeCommand("account.move","button_validate", params);
    

    Kind Regards,
    Pieter