gpt4 book ai didi

php - 从 XML-RPC 客户端在 OpenERP/Odoo 上创建潜在客户

转载 作者:太空宇宙 更新时间:2023-11-03 17:45:38 25 4
gpt4 key购买 nike

我正在尝试从 php 表单创建 Odoo v8 的 Lead。

从此表单中,我通过 POST 将消息发送到 xml-rpc 客户端,然后该客户端将其发送到 Odoo 并在其上创建潜在客户。

我正在努力尝试,但到目前为止还没有成功,这是我的 form.php 代码:

<html>
<head>
<title>Contact form</title>
</head>
<body>
<h4>Contact Form</h4>
<form method="post" action="crmlead.php">
<label for="firstname">Firstname</label>
<input type="text" name="name" value="" id="name" class="required text" title="Please, fill in your firstname" data-required="true"><br />
<label for="partner_name">Partner Name</label>
<input type="text" name="partner_name" value="" id="partner_name" class="required text" title="Please, fill in your company name" data-required="true"><br />
<label for="event_date">Event Date</label>
<input type="text" name="event_date" value="" id="event_date" class="required text" title="Please, fill in your job title" data-required="true"><br />
<label for="email">Email</label>
<input type="text" name="email" value="" id="email" class="required email text" title="Please, enter a valid email address" data-required="true"><br />
<label for="phone">Phone</label>
<input type="text" name="phone" value="" id="phone" class="required phone text" title="Please use international format (eg: +32...)" data-required="true">

<label for="guests">Guests</label>
<input type="text" name="guests" value="" id="guests" class="required text" title="Please, fill in your city" data-required="true"><br />
<label for="budget">Budget</label>
<td><input type="text" name="budget" value="" id="budget" class="required text" title="Please, fill in your zipcode" data-required="true"><br />
<label for="description">Description</label>
<td><input type="text" name="description" value="" id="description" class="required text" title="Please, fill in your zipcode" data-required="true"><br />
<label for="location">Location</label><input type="text" name="location" value="" id="location" class="text" title="Please, fill in your state"> <br />
<p>
<input type="submit" value="Send"/> <input type="reset" />
</p>
</form>

</body>
</html>

这是我的 crmlead.php 客户端代码:

<?php

include("xmlrpc.inc");

class Contact
{
private $subject = '', $to = '';

function __construct($to, $sub)
{
$this->to = $to;
$this->subject = $sub;
}


function xmlCallTo($usr, $password, $database, $server, $post)
{
$user = "admin";
$pass = "admin";
$db = "BMWE-001";
$server_url = 'http://localhost:8069/xmlrpc/';

$client = new xmlrpc_client($server_url.'common');

$msg = new xmlrpcmsg('login');
$msg->addParam(new xmlrpcval($db, "string"));
$msg->addParam(new xmlrpcval($user, "string"));
$msg->addParam(new xmlrpcval($pass, "string"));


$res = &$client->send($msg);

if(!$res->faultCode()){

$val = $res->value();
$id = $val->scalarval();

if (empty($id)){

echo "Connection error = ";
exit;
}
else
{

$val = $res->value()->scalarval();

$val = array ("name" => new xmlrpcval($post["New Lead","string"),
"email_from" => new xmlrpcval($post['email'], "string"),
"phone" => new xmlrpcval($post['phone'], "string"),
"partner_name" => new xmlrpcval($post['partner_name'], "string"),
"event_date" => new xmlrpcval($post['event_date'], "string"),
"guests" => new xmlrpcval($post['guests'], "string"),
"location" => new xmlrpcval($post['location'], "string"),
"budget" => new xmlrpcval($post['budget'], "string"),
"stage_id" => new xmlrpcval(2, "int"),
"state" => new xmlrpcval("draft", "string"),
"description" => new xmlrpcval($post['description'], "string")
);

$msg = new xmlrpcmsg('execute');
$msg->addParam(new xmlrpcval($db, "BMWE-001"));
$msg->addParam(new xmlrpcval($id, "1"));
$msg->addParam(new xmlrpcval($pass, "admin"));
$msg->addParam(new xmlrpcval("crm.lead", "string"));
$msg->addParam(new xmlrpcval("create", "string"));
$msg->addParam(new xmlrpcval($val, "struct"));


$res2 = &$client2->send($msg);

if(!$res2->faultCode())
{
$readVal = $res2->value()->scalarval();

}
else
{
echo "<br />Lead is not created";
}
}
else
{
echo "<br />Problem in message sending for create lead";
}
}
}
else
{
echo "<br />Connection not established";
}
}
}
exit;
?>

这两个脚本都在同一台服务器上运行,在本地主机上,通过 nginx php 配置运行得很好,所以,nginx 服务器在这方面没问题。

Odoo v8 显然在同一台机器上独立运行,本地主机也运行。

最佳答案

问题可能是您没有在创建潜在客户的模型上调用 create 方法。上面的代码看起来只会登录到您的 Odoo 服务器。这可能会返回您登录的用户的 uid。

您需要登录,然后传递一个变量数组(供您引导)、相关模型,然后使用您传递的参数传递您希望在此模型上执行的函数。因为您希望创建一个新的潜在客户,所以这将是创建函数。如果您正在编辑线索,那就是写入功能。下面的链接包含有关如何实现您希望的事情的示例。

ODOO xmlrpc EXAMPLES

这应该可以实现您正在寻找的内容(我从上面的链接借用了这个)。您需要将对 res.partner 的引用更改为您需要的模型。您还将变量数组更改为表单中的值。

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
echo '<h2>XML-RPC AVEC OPENERP/ODOO ET PHP</h2>';

include("xmlrpc_lib/xmlrpc.inc.php");
include("xmlrpc_lib/xmlrpcs.inc.php");
$GLOBALS['xmlrpc_internalencoding']='UTF-8';

$user = 'admin';
$password = 'mY5up3rPwd';
$dbname = 'test';

$server_url = 'http://192.168.1.120:8069';
$connexion = new xmlrpc_client($server_url . "/xmlrpc/common");
$connexion->setSSLVerifyPeer(0);

$c_msg = new xmlrpcmsg('login');
$c_msg->addParam(new xmlrpcval($dbname, "string"));
$c_msg->addParam(new xmlrpcval($user, "string"));
$c_msg->addParam(new xmlrpcval($password, "string"));
$c_response = $connexion->send($c_msg);

if ($c_response->errno != 0){
echo '<p>error : ' . $c_response->faultString() . '</p>';
}
else{

$uid = $c_response->value()->scalarval();

$val = array (
"name" => new xmlrpcval("Godin Thierry", "string"),
"street" => new xmlrpcval("Au fond à gauche", "string"),
"city" => new xmlrpcval("Marne la Vallée", "string"),
"zip" => new xmlrpcval("77000", "string"),
"website" => new xmlrpcval("http://www.lapinmoutardepommedauphine.com", "string"),
"lang" => new xmlrpcval("fr_FR", "string"),
"tz" => new xmlrpcval("Europe/Paris", "string"),
);

$client = new xmlrpc_client($server_url . "/xmlrpc/object");
$client->setSSLVerifyPeer(0);

$msg = new xmlrpcmsg('execute');
$msg->addParam(new xmlrpcval($dbname, "string"));
$msg->addParam(new xmlrpcval($uid, "int"));
$msg->addParam(new xmlrpcval($password, "string"));
$msg->addParam(new xmlrpcval("res.partner", "string"));
$msg->addParam(new xmlrpcval("create", "string"));
$msg->addParam(new xmlrpcval($val, "struct"));
$response = $client->send($msg);

echo 'Partner created - partner_id = ' . $response->value()->scalarval();
}
?>

关于php - 从 XML-RPC 客户端在 OpenERP/Odoo 上创建潜在客户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29848181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com