我想在openerp中使用我在其他数据库中的数据创建sale.order。我的数据库查询是正确的,因为我已经尝试过了。我已经尝试了create sale.order代码是正确的(输入数据是在代码中手动添加的)。但是当我收集代码时,它变成了错误Array ( [faultCode] => AccessDenied [faultString] => Access denied )
。是因为create sale.order代码无法循环,或者不能在包含其他数据库的配置文件中使用(不是oopenerp' s数据库)。
有人可以给我解决方案吗?谢谢。
<?php
// Ripcord can be cloned from https://github.com/poef/ripcord
require_once('ripcord/ripcord.php');
// Login information
$url = 'http://localhost:8069';
$url_auth = $url . '/xmlrp/common';
$url_exec = $url . '/xmlrpc/object';
$db = 'openerp';
$username = 'admin';
$password = 'admin';
// Login
$common = ripcord::client("$url/xmlrpc/common");
//$common = ripcord::client($url_auth);
$uid = $common->authenticate($db, $username, $password, array());
$models = ripcord::client($url_exec);
include "config.php";
$sql = "SELECT so.id as id,
so.cust_id,
so.numb,
p.ktr,
p.store_id,
so.write_date,
p.store_name,
p.sales_id
FROM sales_order so
INNER JOIN store p on p.store_id = so.store_id
";
$exec = pg_query($sql);
while ($row = pg_fetch_array($exec)){
$query = pg_query(
"SELECT sod.product_id, sod.qty_sales, p.name
FROM sales_order_line sod
INNER JOIN product p on p.id = sod.product_id
WHERE sales_order_id = ".$row['id']
);
while ($data = pg_fetch_array($query)) {
$id = $models->execute_kw($db, $uid, $password,
'sale.order', 'create',
array(array(
'partner_id' => $row['store_id'],
'sales_id' => $row['sales_id'],
'order_line' => [array(
0, false, array(
'product_id' => $data['product_id'],
'name' => $data['name'],
'qty' => $data['quantity'])
)]
)));
var_dump($id);
}
}
?>
答案 0 :(得分:0)
这是因为include
config.php
包含其他数据库(不是您的openerp使用的数据库)。
将配置文件写在同一个文件中:
$config = pg_connect("host= 'yourhost' port='yourport' dbname= 'yourdbname' user='yourdbuser' password='yourdbpass' ") or die('Failed');