1

我的 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。当我运行脚本时出现错误。

4

2 回答 2

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());
    }
于 2015-05-21T13:20:22.260 回答
0

您请求缺少数据库名称,您想在其中创建销售订单。

于 2013-08-20T10:51:38.910 回答