如何在JAVA ODOO XMLRPC中创建带有many2one和many2many数据的记录

huangapple go评论103阅读模式
英文:

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

问题

    **这是用于创建带有Mpa数据记录的函数**
    此函数以*模型名称**数据*作为输入以创建记录

    **我的数据** *{"categ_id":[1,"All"],"website_meta_keywords":false,"available_in_pos":true}*

    **我的错误** *psycopg2.errors.InvalidTextRepresentation错误无效的输入语法为整数:“All
    第1行...w() at time zone 'UTC'),truetrue0.0ARRAY[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] 在" + modelName + "中创建记录时出现异常。详情:" + e.getMessage());
        }
        return recordId;
    }
英文:

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

答案1

得分: 0

Odoo引发了这个错误是因为categ_id的值,Many2one字段的值应该是一个现有记录的ID(整数类型,也可以作为字符串传递)。

使用特殊的命令格式来操作存储在/与x2many字段相关联的记录集。

示例(order_line字段值):

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

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

huangapple
  • 本文由 发表于 2020年7月25日 10:03:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/63083557.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定