Search code examples
javaodoo-12

How do you search an Odoo Object knowing its id?


Odoo : the following code returns a Array of 'java.lang.Integer' ids.

asList((Object[])models.execute("execute_kw", asList(
db, uid, password,
"res.partner", "search",
asList(asList(
    asList("is_company", "=", true),
    asList("customer", "=", true))))));

[7, 18, 12, 14, 17, 19, 8, 31, 26, 16, 13, 20, 30, 22, 29, 15, 23, 28, 74]

Which reverse call will return the structure and values of each Object associated to each ids?


Solution

  • Its the read command.

    final List ids = asList((Object[])models.execute(
                "execute_kw", asList(
                db, uid, password,
                "res.partner", "search",
                asList(asList(
                    asList("is_company", "=", true),
                    asList("customer", "=", true))))));
    
    final Map record = (Map)((Object[])models.execute(
        "execute_kw", asList(
            db, uid, password,
            "res.partner", "read",
            asList(ids)
        )
    ))[0];
    

    work through those examples:

    https://www.odoo.com/documentation/13.0/webservices/odoo.html