如何通过XML-RPC和PHP填充OpenERP订单

时间:2013-04-16 14:18:08

标签: php xml-rpc openerp

我的PHP脚本可能如下所示:

function neworder($uid,$pwd,$objname,$methname,$params){
    $client = new xmlrpc_client("/xmlrpc/object", "localhost", 8069);

    $message = new xmlrpcmsg('execute');
    $message->addparam(xmlrpc_encode($uid));
    $message->addparam(xmlrpc_encode($pwd));
    $message->addparam(xmlrpc_encode($objname));
    $message->addparam(xmlrpc_encode($methname));
    $message->addparam(xmlrpc_encode($params));

    $resp = $client->send($message);

    if ($resp->errno!=0)  trigger_error ("sock_execute error ".$resp->errstr);
            return xmlrpc_decode($resp->value());
}

$uid = 1;
$pwd = 'password';

$order = array(
    'name'=> 'order22',
    'shop_id'=> 1,
    'state'=> 'draft',
    'user_id'=> 4,
    'partner_id'=> 7,
    'partner_invoice_id'=> 1,
    'partner_order_id'=> 1
);

$order_id = neworder($uid, $pwd, 'sale.order', 'create', $order);
echo("a new order ".$order_id." is added");

我正在使用Ubuntu和OpenERP 7.当我运行脚本时,我收到错误。

2 个答案:

答案 0 :(得分:2)

这是一个填充销售订单的工作脚本。

function createNewOrder($params,$model_name)
    {
        $client = new xmlrpc_client($this->server . "object");
        $client->return_type = 'phpvals';

        $msg = new xmlrpcmsg('execute');


        $nval = array();
        foreach($params as $k=>$v){
            $nval[$k] = new xmlrpcval( $v, xmlrpc_get_type($v) );
        }




        $msg->addParam(new xmlrpcval($this->database, "string"));  //* database name */
        $msg->addParam(new xmlrpcval($this->uid, "int")); /* useid */
        $msg->addParam(new xmlrpcval($this->password, "string"));
        /** password */
        $msg->addParam(new xmlrpcval($model_name, "string"));
        /** model name where operation will held * */
        $msg->addParam(new xmlrpcval("create", "string"));
        /** method which u like to execute */

        $msg->addParam(new xmlrpcval($nval, "struct"));/** parameters of the methods with values....  */


        /** parameters of the methods with values....  */



        $resp = $client->send($msg);

        if ($resp->errno != 0)
            trigger_error("sock_execute error " . $resp->errstr);

        return xmlrpc_decode($resp->value());
    }

答案 1 :(得分:0)

您要求缺少DATABASE名称,您要在其中创建销售订单。