ODOO如何使用XMLRPC库从Android Studio创建多条记录? [英] ODOO How to create many2one record from Android Studio using aXMLRPC library?

查看:93
本文介绍了ODOO如何使用XMLRPC库从Android Studio创建多条记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 fleet.vehicle 模型创建新记录.由于记录的类型 Many2One ,因此会引发以下异常.

I am trying to create a new record in fleet.vehicle model. Since the Type of record is Many2One, it throws the following exception.

de.timroes.axmlrpc.XMLRPCServerException: Traceback (most recent call last):

但是我能够使用相同的代码段在 res.user 模型中创建一条记录,因为 Type res.user 的字符>型号.
我的代码段是:

However I was able to create a record in res.user model with the same code snippet because the Type was char for res.user model.
My code Snippet is:

public Integer create(String model, HashMap values) {
        Integer newObjectId = null;
        try {

            XMLRPCClient client = new XMLRPCClient(mUrl);

            Object[] parameters = {mDatabase, mUserId, mPassword, model, "create" ,new Object[]{values}};
            newObjectId = (Integer) client.call("execute_kw", parameters);

        } catch (XMLRPCException e) {
            Log.d(CONNECTOR_NAME, e.toString());
        }
        return newObjectId;
    }  

,日志为:

de.timroes.axmlrpc.XMLRPCServerException: Traceback (most recent call last):
  File "/home/wms/RMS/9040/new_odoo11/odoo/service/wsgi_server.py", line 124, in wsgi_xmlrpc
    result = odoo.http.dispatch_rpc(service, method, params)
  File "/home/wms/RMS/9040/new_odoo11/odoo/http.py", line 115, in dispatch_rpc
    result = dispatch(method, params)
  File "/home/wms/RMS/9040/new_odoo11/odoo/service/model.py", line 39, in dispatch
    res = fn(db, uid, *params)
  File "/home/wms/RMS/9040/new_odoo11/odoo/service/model.py", line 153, in execute_kw
    return execute(db, uid, obj, method, *args, **kw or {})
  File "/home/wms/RMS/9040/new_odoo11/odoo/service/model.py", line 97, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/wms/RMS/9040/new_odoo11/odoo/service/model.py", line 160, in execute
    res = execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/wms/RMS/9040/new_odoo11/odoo/service/model.py", line 149, in execute_cr
    return odoo.api.call_kw(recs, method, args, kw)
  File "/home/wms/RMS/9040/new_odoo11/odoo/api.py", line 687, in call_kw
    return call_kw_model(method, model, args, kwargs)
  File "/home/wms/RMS/9040/new_odoo11/odoo/api.py", line 672, in call_kw_model
    result = method(recs, *args, **kwargs)
  File "/home/wms/RMS/9040/new_odoo11/addons/fleet/models/fleet_vehicle.py", line 197, in create
    vehicle = super(FleetVehicle, self.with_context(mail_create_nolog=True)).create(data)
  File "/home/wms/RMS/9040/ac-ars/ac_rms/models/planner_calender.py", line 422, in create
    res_id = super(MailThread, self).create(values)
  File "/home/wms/RMS/9040/new_odoo11/addons/mail/models/mail_thread.py", line 231, in create
    thread = super(MailThread, self).create(values)
  File "/home/wms/RMS/9040/new_odoo11/odoo/models.py", line 3278, in create
    record = self.browse(self._create(old_vals))
  File "/home/wms/RMS/9040/new_odoo11/odoo/models.py", line 3371, in _create
    cr.execute(query, tuple(u[2] for u in updates if len(u) > 2))
  File "/home/wms/RMS/9040/new_odoo11/odoo/sql_db.py", line 155, in wrapper
    return f(self, *args, **kwargs)
  File "/home/wms/RMS/9040/new_odoo11/odoo/sql_db.py", line 232, in execute
    res = self._obj.execute(query, params)
psycopg2.DataError: invalid input syntax for integer: "Audi A3"
LINE 1: ...et_vehicle_id_seq'), 5, true, 'kilometers', NULL, 'Audi A3',...
 [1]

我还附上了我要创建的图像.任何帮助深表感谢. 我的问题是如何在odoo中从Android/Java创建类型为 Many2One 的新记录?

I have attached a image as well of what I am trying to create. Any help is much appreciated. My question is how to create a new record of type Many2One from Android/Java in odoo?

推荐答案

我正在回答自己的问题.这个问题的答案非常简单,我发现可以使用XMLRPC库进行探索,调试和尝试.这就是我解决的方法.
我尝试更新的字段仅接受odoo中已经预设的数据.例如:我必须首先使用search_read功能搜索该字段的可用预设数据.喜欢.

I am answering my own question. The answer for this problem is very simple which I found out exploring, debugging and trying things out with XMLRPC library. This is how I solved it.
The field I was trying to update only accepts the data that is already preset in odoo. For example: I had to first search for the available preset data for that field by using search_read functionality. Like..

OdooConnect oc = OdooConnect.connect(SERVER_URL, PORT_NO, DB_NAME, USER_ID, PASSWORD);
List<HashMap<String, Object>> data = oc.search_read("fleet.vehicle", new Object[]{
                new Object[]{condition}}, "id");

我在这里正在搜索与要创建的字段相关的所有预设数据,并获取与要在特定条件下更新的字符串匹配的字符串的ID. 条件是

What I am doing here is searching for all the preset data related to the field I want to create and get the id of the string that matches with the one I want to update with certain conditions. here condition is

new Object[]{new Object[]{new Object[]{"name", "=", "Audi A3"}}}

因此,当它与该条件匹配时,它将返回我需要传递给many2one字段的对象的ID. 在上面的代码中,"id" 用于询问与条件匹配的字符串的ID. 现在,我们将在创建新记录的同时将id传递给many2one字段.将ID传递给下面的create方法.

so when it matches with that condition, it returns the id of the object I need to pass to the many2one field. In the above code "id" is for asking for an id of the string that matched the condition. Now we will pass the id while creating a new record to many2one field. Pass the id to below create method.

final Integer idC = oc.create("web.service", new HashMap() {{
                put("name", "Final Test");
                put("value", 29); //
                put("partner_id", id); //many2One field. here we are using pre defined value i,e setting a value of other relation model to partner_id
        }});

希望它对正在寻找答案的人有所帮助. :)

Hope it helps someone who is looking for an answer. :)

这篇关于ODOO如何使用XMLRPC库从Android Studio创建多条记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆