【发布时间】:2016-04-05 07:46:55
【问题描述】:
目前我正在使用 odoo 8.0。实际上,我正在使用 XML-RPC API 创建产品。这里是使用 php 从 xml-rpc 创建产品的代码。
$url = "http://localhost:8069";
$db = "xmlcreate";
$username = "admin";
$password = "admin";
require_once('ripcord-master/ripcord.php');
$common = ripcord::client("$url/xmlrpc/2/common");
$uid = $common->authenticate($db, $username, $password, array());
$models = ripcord::client("$url/xmlrpc/2/object");
$product = array('name' => 'Sample',
'type' => 'product',
'list_price' => 4.6,
'standard_price' => 3.25
);
$product_id = $models->execute_kw($db, $uid, $password, 'product.template','create',array($product));
产品已成功创建。然后我手动创建属性名称 Color (attribute_id = 1) 和值 green (value_id = 1)。接下来我将通过下面的代码来更新上面的 varint(Color)。
$attributes = array();
$attributes[] = 0;
$attributes[] = 0;
$attributes['attribute_id'] = 1; // attribute is color (color -> 1)
$attributes['values_id'] = array(1); // attribute value is green(green -> 1)
$existing_prodid = 1;
$up_attr_id = $models->execute_kw($db, $uid, $password,'product.template','write',array($existing_prodid, array('attribute_line_ids' => $attributes)));
print_r($up_attr_id);
没有错误。它打印更新的 id。但是这些变体不会在 odoo 前端的产品表单视图中更新。 'attribute_line_ids' 是 product.template 对象中的 one2many 字段。我认为从 xml-rpc php 更新 one2many 字段的语法不正确。请帮我。提前致谢。
【问题讨论】:
标签: php xml-rpc odoo-8 openerp-8