【问题标题】:OpenERP - XML RPC (write method - PHP)OpenERP——XML RPC(写法——PHP)
【发布时间】:2014-08-30 16:53:31
【问题描述】:

我正在努力正确格式化我的调用,以便能够使用更新记录的“写入”方法。

我查看了文档here,但仍然无法解决。有没有我可以看的例子,因为我找不到。这是我的代码:

        $arrayVal1 = array(
        new xmlrpcval(1, "int"),    //update the linked record
        new xmlrpcval(20, "int"),   //with id = 20
        new xmlrpcval(array(
                'answer_id'=>new xmlrpcval(2, "int")                    //IF Question is a selection
                //'answer'=>new xmlrpcval('some_text_here' , "string")              //IF Question is a free text

        ),'struct'));
        $cr = 'hr_applicant_question_list_cursor';
        $ids= array(new xmlrpcval(1, "int"));

        $msg1 = new xmlrpcmsg('execute');
        $msg1->addParam(new xmlrpcval($dbname, "string"));
        $msg1->addParam(new xmlrpcval($user_id, "int"));
        $msg1->addParam(new xmlrpcval($pwd, "string"));
        $msg1->addParam(new xmlrpcval("hr.applicant.question.list", "string"));
        $msg1->addParam(new xmlrpcval("write", "string"));


        $msg1->addParam(new xmlrpcval('hr_applicant_question_list_cursor', "string"));
        $msg1->addParam(new xmlrpcval($ids, "array"));
        $msg1->addParam(new xmlrpcval($arrayVal1, "array"));

我收到以下错误:

        Traceback (most recent call last): File "/opt/openerp/server/openerp/wsgi/core.py", line 79, in xmlrpc_return result = openerp.netsvc.dispatch_rpc(service, method, params) File "/opt/openerp/server/openerp/netsvc.py", line 360, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) 
    File "/opt/openerp/server/openerp/service/web_services.py", line 586, in dispatch res = fn(db, uid, *params) File "/opt/openerp/server/openerp/osv/osv.py", line 129, in wrapper return f(self, dbname, *args, **kwargs) 
File "/opt/openerp/server/openerp/osv/osv.py", line 195, in execute res = self.execute_cr(cr, uid, obj, method, *args, **kw) 
    File "/opt/openerp/server/openerp/osv/osv.py", line 183, in execute_cr return getattr(object, method)(cr, uid, *args, **kw) 
    File "/opt/openerp/server/openerp/osv/orm.py", line 3836, in write for field in vals.copy(): AttributeError: 'list' object has no attribute 'copy' [payload] => [hdrs] => Array ( [content-type] => text/xml [content-length] => 1269 [server] => Werkzeug/0.8.3 Python/2.7.3 [date] => Sat, 30 Aug 2014 16:41:12 GMT ) [_cookies] => Array ( ) [content_type] => text/xml [raw_data] => HTTP/1.0 200 OK Content-Type: text/xml Content-Length: 1269 Server: Werkzeug/0.8.3 Python/2.7.3 Date: Sat, 30 Aug 2014 16:41:12 GMT faultCode 'list' object has no attribute 'copy' faultString Traceback (most recent call last): 
    File "/opt/openerp/server/openerp/wsgi/core.py", line 79, in xmlrpc_return result = openerp.netsvc.dispatch_rpc(service, method, params) 
    File "/opt/openerp/server/openerp/netsvc.py", line 360, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) 
    File "/opt/openerp/server/openerp/service/web_services.py", line 586, in dispatch res = fn(db, uid, *params) File "/opt/openerp/server/openerp/osv/osv.py", line 129, in wrapper return f(self, dbname, *args, **kwargs) 
    File "/opt/openerp/server/openerp/osv/osv.py", line 195, in execute res = self.execute_cr(cr, uid, obj, method, *args, **kw) 
    File "/opt/openerp/server/openerp/osv/osv.py", line 183, in execute_cr return getattr(object, method)(cr, uid, *args, **kw) File "/opt/openerp/server/openerp/osv/orm.py", line 3836, in write for field in vals.copy(): AttributeError: 'list' object has no attribute 'copy' ) Error: Traceback (most recent call last): File "/opt/openerp/server/openerp/wsgi/core.py", line 79, in xmlrpc_return result = openerp.netsvc.dispatch_rpc(service, method, params) 
    File "/opt/openerp/server/openerp/netsvc.py", line 360, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) 
    File "/opt/openerp/server/openerp/service/web_services.py", line 586, in dispatch res = fn(db, uid, *params) 
    File "/opt/openerp/server/openerp/osv/osv.py", line 129, in wrapper return f(self, dbname, *args, **kwargs) 
    File "/opt/openerp/server/openerp/osv/osv.py", line 195, in execute res = self.execute_cr(cr, uid, obj, method, *args, **kw) 
    File "/opt/openerp/server/openerp/osv/osv.py", line 183, in execute_cr return getattr(object, method)(cr, uid, *args, **kw) 
    File "/opt/openerp/server/openerp/osv/orm.py", line 3836, in write for field in vals.copy(): AttributeError: 'list' object has no attribute 'copy'

感谢您的帮助。

【问题讨论】:

    标签: php openerp xml-rpc


    【解决方案1】:

    我认为问题出在这一行:

    $msg1->addParam(new xmlrpcval("hr.applicant.question.list","string"));
    

    如果您尝试更新/写入 one2many 字段,则必须构造一个类型为“array”的 xmlrpcval(),其中包含 o2m 命令和一个类型为“struct”的 xmlrpcval 数组,然后将该对象分配给 one2many字段名称。

    这应该模仿 Python 代码:

    [(0,0,data1),(0,0,data2),....]
    

    例如,编写销售订单对象的order_line字段:

    $data1 = new xmlrpcval(
            array(
                'product_id'     => new xmlrpcval(2, 'int'), 
                'name'           => new xmlrpcval("Product2", 'string'), 
                'product_uom_qty'=> new xmlrpcval(1, 'int'), 
                'price_unit'     => new xmlrpcval(20.2, 'double'), 
                'sub_total'      => new xmlrpcval(20.2, 'double'), 
            ), 
            "struct"
    );
    $data2 = new xmlrpcval(
            array(
                'product_id'     => new xmlrpcval(1, 'int'), 
                'name'           => new xmlrpcval("Product1", 'string'), 
                'product_uom_qty'=> new xmlrpcval(1, 'int'), 
                'price_unit'     => new xmlrpcval(10.2, 'double'), 
                'sub_total'      => new xmlrpcval(10.2, 'double'), 
            ), 
            "struct"
    );
    $lines[] = new xmlrpcval(
                array(
                    new xmlrpcval(0,'int'),
                    new xmlrpcval(0,'int'),
                    $data1
                ),
                "array"
    ); 
    $lines[] = new xmlrpcval(
                array(
                    new xmlrpcval(0,'int'),
                    new xmlrpcval(0,'int'),
                    $data2
                ),
                "array"
    ); 
    $values = array(
        'partner_id'           => new xmlrpcval($partner_id,"int"),
        'partner_shipping_id'  => new xmlrpcval($partner_id,"int"),
        'partner_invoice_id'   => new xmlrpcval($partner_id,"int"),
        'pricelist_id'         => new xmlrpcval($pricelist_id,"int"),
        'order_line'           => new xmlrpcval($lines,"array")
    );
    
    $ret = $openerp->create("sale.order", $values);
    

    我在 Google Play 上写了一本书,名为“使用 XML-RPC 库的高级 PHP 和 OpenERP 接口”,请看一下。

    问候

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-05
      • 1970-01-01
      • 1970-01-01
      • 2013-09-12
      • 2010-11-07
      • 1970-01-01
      • 2017-06-29
      相关资源
      最近更新 更多