2017-08-25 25 views
0

我有2個模型:product.templateproduct.brand。 我想顯示來自product.template及其品牌的詳細數據,我可以從product.brand的模型中獲取品牌。在model.brand中,product.template中包含與id有關的product_id。這是我目前的代碼。此代碼僅顯示來自product.template的數據。如何使用ripcord在xmlrpc中加入模型?

<?php  
$products = $ripcord->execute_kw('myDB', 1, 'myPassword', 
         'product.template', 'search_read', 
         array(
          array(
          array('name', 'ilike', 'pixma'), 
          array('type', 'ilike', 'product'), 
         ['fields'=>array('name', 'description'), 'limit'=>5] 
        ))); 
?> 

如何加入product.template模型與product.brand,以便我可以獲取數據的產品品牌。謝謝。

回答

1

您需要在fields中包含品牌的參考。

<?php 

$db = 'myDB'; 
$uid = 1; 
$password = 'myPassword'; 

# You will need to include a reference to the Many2one field 
# that exists on your product.template record. I'm assuming it's 
# called something like "brand" or "brand_id" 
$fields = array('name', 'description', 'brand'); 


$products = $ripcord->execute_kw($db, $uid, $password, 
    'product.template', 'search_read', array(array(
     array('name', 'ilike', 'pixma'), 
     array('type', 'ilike', 'product'), 
     ['fields'=> $fields, 'limit'=>5]))); 
+1

我明白了。 但是讓我們在'product.template'中包含字段:'id','name','type','brand'和'description'。並且在'product.brand'中包含字段:'id','brand_name','category_brand'和'price'。 'product.template'中的'brand'與'product.brand'中的'id'相關。我想要顯示的是'product.template'的'name'和'description','product.brand'的'category_brand'和'price'。 如果我只是把'品牌'領域像你說的,它只是顯示ID的品牌。我怎樣才能顯示'category_brand'和'price'? 謝謝:) – adn

+0

據我所知,你必須提出多個請求。因此,您只需從product.brand中提取id,並針對該字段對該模型發出另一個「search_read」請求。可以編寫自己的幫助器方法來使用點符號並自動拉取關係,但Odoo的api不直接提供這些功能。 – holdenrehg

+0

okey謝謝你的信息 – adn