Odoo 10 XMLRPC 如何映射one2many和many2one
Odoo 10 XMLRPC How to map one2many and many2one
我最近在 python 2.7 和 Odoo 10 API 中使用 XMLRPC 进行了一些开发。
我的问题是:
如何通过xmlrpc将one2many字段写入odoo中的字段
如何通过xmlrpc将many2one字段写入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])],
}])
使用 Php API 在 CRM 表单中创建 Activity(One2many 字段)在@v11 Odoo 社区中:
$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 字段,它将创建 activity)
重要:
要创建 One2many 字段,您必须传递相关的 many2one Id
您也可以参考下图在图像中看到:
enter image description here
我最近在 python 2.7 和 Odoo 10 API 中使用 XMLRPC 进行了一些开发。 我的问题是:
如何通过xmlrpc将one2many字段写入odoo中的字段
如何通过xmlrpc将many2one字段写入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])],
}])
使用 Php API 在 CRM 表单中创建 Activity(One2many 字段)在@v11 Odoo 社区中:
$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 字段,它将创建 activity)
重要: 要创建 One2many 字段,您必须传递相关的 many2one Id
您也可以参考下图在图像中看到: enter image description here