OpenERP-XMLRPC(编写方法-PHP)
我正在努力正确设置调用的格式,以便能够使用“write”方法更新记录 我已经看了文档,但仍然无法计算出来。有没有什么例子我可以看看,因为我找不到。这是我的密码:OpenERP-XMLRPC(编写方法-PHP),php,openerp,xml-rpc,Php,Openerp,Xml Rpc,我正在努力正确设置调用的格式,以便能够使用“write”方法更新记录 我已经看了文档,但仍然无法计算出来。有没有什么例子我可以看看,因为我找不到。这是我的密码: $arrayVal1 = array( new xmlrpcval(1, "int"), //update the linked record new xmlrpcval(20, "int"), //with id = 20 new xmlrpcval(array
$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'
谢谢您的帮助。我想问题出在这一行:
$msg1->addParam(new xmlrpcval("hr.applicant.question.list","string"));
如果您试图更新/写入one2many字段,则必须构造一个包含o2m命令的类型为“array”的xmlrpcval()和一个类型为“struct”的xmlrpcval数组,然后将该对象分配给one2many字段名
这应该模仿Python代码:
[(0,0,data1),(0,0,data2),....]
例如,要写入销售订单对象的订单行字段:
$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接口”,请看一下
问候