Odoo 10 XMLRPC如何映射one2many和many2one

问题描述 投票:1回答:2

我最近在使用XMLRPC使用Odoo 10 API在python 2.7中进行了一些开发。我的问题是:

  1. 如何通过xmlrpc将od2many字段写入odoo中的字段
  2. 如何通过xmlrpc在odoo中的字段中写入many2one字段

非常感谢您的帮助,非常感谢!

塞缪尔

openerp one-to-many xml-rpc many-to-one odoo-10
2个回答
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,
}])

Many2manyOne2many领域有点特别。在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])],
}])

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

© www.soinside.com 2019 - 2024. All rights reserved.