Search code examples
javaodoo

How To Create Record with many2one, many2many data in JAVA ODOO XMLRPC


Here is my function for creating record with Mpa Data This function take as input the model name and the data to create record.

My data: {"categ_id":[1,"All"],"website_meta_keywords":false,"available_in_pos":true}

My error: psycopg2.errors.InvalidTextRepresentation: ERREUR: syntaxe en entrée invalide pour l'entier : « All » LINE 1: ...w() at time zone 'UTC'), true, true, 0.0, ARRAY[1,'All'], 'A...

public Integer createRecord (String modelName, Map data) {
    Integer recordId = -1;
    try {
        client.setConfig(objectConfig);
        recordId = (Integer) client.execute("execute_kw", asList(
                this.database, this.uid, this.password,
                modelName, "create",
                asList(
                       data
                )
        ));

    } catch (Exception e) {
        LOGGER.error("[OdooXmlRpc.createRecord] Exception when creating record in " + modelName + ". Details: " + e.getMessage());
    }
    return recordId;
}

Solution

  • Odoo raised that error because of the value of categ_id, the value of a Many2one field should be an existing record ID (of type integer, which can also be passed as a string).

    Use a special commands format to manipulate the set of records stored in/associated with the x2many fields.

    Example (order_line field value):

    Arrays.asList(Arrays.asList(0, 0, new HashMap() {{ put("product_id", product_id); ...}} ))