我最近在使用XMLRPC使用Odoo 10 API在python 2.7中进行了一些开发。 我的问题是:
如何通过xmlrpc将od2many字段写入odoo中的字段
如何通过xmlrpc在odoo中的字段中写入many2one字段
非常感谢您的帮助,非常感谢!
塞缪尔
答案 0 :(得分:3)
对于Many2one
字段,您只需使用记录的ID:
my_partner_id = 1 # or use a search to find the correct one
id = models.execute_kw(db, uid, password, 'sale.order', 'create', [{
'partner_id': my_partner_id,
}])
Many2many
或One2many
字段有点特殊。在Odoo中有一些神奇的三胞胎,你必须使用这些领域 - > Model Reference/CRUD/write(vals)
例如,如果您要向客户(Many2many
字段)添加标记:
my_tag_id = 42 # or use a search to find the correct one
id = models.execute_kw(db, uid, password, 'res.partner', 'write',
[my_partner_id], [{
'category_id': [(4, my_tag_id)],
}])
或者如果你想删除所有标签:
my_tag_id = 42 # or use a search to find the correct one
id = models.execute_kw(db, uid, password, 'res.partner', 'write',
[my_partner_id], [{
'category_id': [(5,)],
}])
或者如果您想用其他人替换所有标签:
my_tag_id1 = 42 # or use a search to find the correct one
my_tag_id2 = 7 # or use a search to find the correct one
id = models.execute_kw(db, uid, password, 'res.partner', 'write',
[my_partner_id], [{
'category_id': [(6, None, [my_tag_id1, my_tag_id2])],
}])
答案 1 :(得分:0)
在@ v11 Odoo社区中使用Php API以CRM形式创建活动(One2many字段):
$opportunity_id = 13; (Lead in which you create activity)
$user_id = 1; (User, for whom you assign task)
$c = $_POST["loading_time"]; (Deadline date which you have to set from php)
$enddate = date("Y-m-d H-i-s", strtotime($c));
$model = 'crm.lead';
$res_model_id = $models -> execute_kw($db, $uid, $password,
'ir.model', 'search', array(array(array('model', '=', 'crm.lead'))));
print_r($res_model_id);
$activity_type_id = $models -> execute_kw($db, $uid, $password,
'mail.activity.type', 'search', array(array(array('name', '=', 'Todo')))); (this is activity type like Todo,Call,Email,etc....)
print_r($activity_type_id);
$product_attribute_line = $models -> execute($db, $uid, $password,
'mail.activity', 'create',
array('model'= > $model,
'res_id'= > $opportunity_id,
'note'= > $_POST["question"],
'user_id'= > $user_id,
'date_deadline'=> $_POST["loading_time"],
'res_model_id'= > $res_model_id[0],
'summary'= > $_POST["subject"],
'activity_type_id'= > $activity_type_id[0],
'activity_ids'= > array(array(6, 0, array($opportunity_id))) ));
(activity_ids是一个将创建活动的one2many字段)
重要的: 创建One2many字段您必须传递相关的many2one Id
您还可以通过参考以下图片在图片中看到: enter image description here