我最近一直在使用XMLRPC在Odoo 10 API的Python 2.7中进行一些开发。 我的问题是:Odoo 10 XMLRPC如何映射one2many和many2one
如何通过XML-RPC
您是如何通过XMLRPC写many2one场的场odoo写one2many场的场odoo
非常感谢您的帮助,非常感谢!
塞缪尔
我最近一直在使用XMLRPC在Odoo 10 API的Python 2.7中进行一些开发。 我的问题是:Odoo 10 XMLRPC如何映射one2many和many2one
如何通过XML-RPC
您是如何通过XMLRPC写many2one场的场odoo写one2many场的场odoo
非常感谢您的帮助,非常感谢!
塞缪尔
对于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])],
}])
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标识
你可以看到图像也请参阅下面的图片: enter image description here
是的,感谢这个马kes感觉! –