2014-08-30 54 views
0

我正在努力正确地格式化我的调用,以便能够使用'write'方法更新记录。OpenERP - XML RPC(写入方法 - PHP)

我看过文档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' 

感谢您的任何帮助。

回答

1

我认为这个问题是在这条线:

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

如果你正在试图更新/写one2many字段,则必须构建具有类型“阵列”的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); 

我已经写了一本书在谷歌Play的标题为“高级PHP和OpenERP接口使用XML-RPC库“,请看看。

Regards