0

I am struggling to format my call correctly, so that I am able to use the 'write' method, which updates a record.

I have looked at the documentation here, and still cannot work it out. Is there any example where I can have a look at as I could not find any. Here is my code:

        $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"));

And I receive the following 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' [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'

Thank you for any help.

Ray Meyer
  • 143
  • 12

1 Answers1

1

i think the problem is in this line:

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

if you are trying to update/write a one2many fields, then you must construct an xmlrpcval() with type "array" containing the o2m commands and an array of xmlrpcval with type "struct", then assign that object to the one2many field name.

This should mimic the Python code:

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

Example, to write the order_line field of sale order object:

$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);

I've wrote a book in Google Play titled "Advanced PHP and OpenERP Interfacing Using XML-RPC Library", please take a look on that.

Regards