2017-07-10 113 views
1

我最近一直在使用XMLRPC在Odoo 10 API的Python 2.7中進行一些開發。 我的問題是:Odoo 10 XMLRPC如何映射one2many和many2one

  1. 如何通過XML-RPC

  2. 您是如何通過XMLRPC寫many2one場的場odoo寫one2many場的場odoo

非常感謝您的幫助,非常感謝!

塞繆爾

回答

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

是的,感謝這個馬kes感覺! –

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標識

你可以看到圖像也請參閱下面的圖片: enter image description here