2017-04-17 7 views
0

私のXMLビューファイルでモデル間でフィルタを実行しようとしています。私は外部モデルからの値を使用することはできません。外部モデルを使用するドメイン - Odoo 9

は、実際に私は、以前の選択に基づいてフィールド(M2O)のオプションをフィルタリングするtryngです。 [リストから属性を選択]

バージョン:[(以前に選択した属性のために利用可能なバージョンから)ここで選択したバージョン]

Myview.xmlこの

属性をレンダリングするためにtrys

そこは私のモデルである

alternative_model 
    code     = fields.Char('code', required=True, size=6) 
    description    = fields.Char('description', required=True) 
    attribute_type_id  = fields.Many2one('attribute', required=True) 
    attribute_version_id = fields.Many2one('version', required=True) 

alternative_model 
    code   = fields.Char('code', required=True, size=2) 
    description  = fields.Char('description', required=True) 
    alternative_ids = fields.One2many('alternative','attribute_version_id') 

alternative_model 
    code   = fields.Char('code',required=True,size=6) 
    attribute_id = fields.Many2one('attribute',required=True) 
    description  = fields.Char('description',required=True) 
    tag_ids   = fields.One2many('tag','attribute_version_id') 

私は次のドメインを使用しています: <field string="version" name="attribute_version_id" domain="[([attribute_type_id.code], '=',[attribute_version_id.attribute_id.code])]"/>

答えて

1

私はあなたがあなたのmany2oneフィールドのドメイン を更新するための方法を使用する必要があるのonchangeこの場合:

@api.onchange('attribute_type_id') 
    def onchage_attribute(self): 
    if self.attribute_type_id:# check if the user has selected an attribute 
     # cancel the selected version 
     #but you can check if it much the domain before seting to False 
     self.attribute_version_id = False 
     # return the new domain 
     return {'domain':{'attribute_version_id':[('attribute_id', '=', self.attribute_type_id.id)]} 
    else: # remove the domain 
     return {'domain':{'attribute_version_id':[]} 
素晴らしい作品
+0

。私はまだ関数とAPIデコレータでもっと練習しなければならない – NMenam

+0

はいonchangeは今、新しいAPI – Cherif

0

あなたのXMLは間違っているようです。

1 /あなたは間違っている、画面に表示しようとしている、同じフィールドを使用してドメインをしようとしています。それは他のモデルは、演算子の右側に属性にアクセスすることを許可しませんよう

2. /このドメインは、動作しません、あなたのケースでは、ある「=」

「attribute_version_id」ため「name_search」方法を使用してみてください、あなたはコンテキストとそれに基づいてを使用して、必要な値を渡すことができ、あなたは「attribute_version_id」のレコードをフィルタリングすることができます。

は、 "関連" 分野を取って試してみてください。