简体   繁体   English

通过XMLRPC调用方法-Odoo v9

[英]Calling methods through XMLRPC - Odoo v9

I have a simple function on a custom model to create a record from info passed by xmlrpc (PHP with ripcord library) but when I execute the php the odoo console returns the following error: 我在自定义模型上有一个简单的函数,可以根据xmlrpc(带有ripcord库的PHP)传递的信息来创建记录,但是当我执行php时,odoo控制台返回以下错误:

"cannot marshal recursive dictionaries" TypeError: cannot marshal recursive dictionaries " “无法封送递归词典” TypeError:无法封送递归词典“

The data who I'm passing are a "Json" stored in a text field in a database, so first I resolve the query and get the data from DB and then try to send it to Odoo through XMLRPC 我要传递的数据是“ Json”,存储在数据库的文本字段中,因此首先我解析查询并从数据库中获取数据,然后尝试通过XMLRPC将其发送到Odoo

Here's my code: 这是我的代码:

t_form_main model t_form_main模型

class t_form_main(models.Model):
        _name       =   "t_form_main"   
        _rec_name   =   "form_uid"
        _order      =   "form_uid"
        form_uid    =   fields.Char(string="ID",required=True)
        json_string =   fields.Text(string="JSON_original", required=True)

@api.one
        def infoReceptor(self,info_uid,json_data):
            vals                =   {}
            vals['form_uid']    =   info_uid
            vals['json_string'] =   json_data
            return super(t_form_main,self).create(vals)

The php sentence who I'm using to invoke XMLRPC: 我用来调用XMLRPC的php语句:

  $insert =   $models->execute_kw($db, $uid, $password,'t_form_main','infoReceptor', array(self,"UID",$data));

considering $data as the variable who stores the data from this query: 将$ data作为存储该查询数据的变量:

$query      =   "SELECT raw_json FROM json_archive";
$result     =   $mysqlconn->query($query);
$row        =   $result->fetch_array(MYSQLI_ASSOC);

Solution

The code was right, the problem was caused by a issue in the DB codification, thanks to Phillip Stack for your advice in the return of my function. 代码是正确的,问题是由DB编码中的问题引起的,这要感谢Phillip Stack在我的函数返回中提供的建议。

When returning a response of a create function you need to decorate your create function for the model with @api.returns with a lambda function returning the record id for you newly created record. 返回创建函数的响应时,您需要使用@ api.returns装饰该模型的创建函数,并使用lambda函数返回新创建记录的记录ID。 In your case if you do not want to do that I would add .id to the end of your return line. 在您的情况下,如果您不想这样做,则将.id添加到返回行的末尾。

return super(t_form_main,self).create(vals).id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM