2017-08-17 84 views
0
class myModel(models.Model): 

    _name = 'my.model' 

    state = fields.Selection(selection=_STATES, string='Status', index=True, track_visibility='onchange',required=True, copy=False, default='draft') 
    my_model_line = fields.One2many('my.model.line', 'model_id') 

另一種模式:Odoo隱藏場

class MyModelLine(models.Model): 

    _name = 'my.model.line' 

    name = fields.Char(string='Name') 
    quantity = fields.Integer(string='Quantity', required=True, default=1) 
    remarks = fields.Text(string='Description') 
    my_model_id = fields.Many2one('my.model', 'My Model') 

my_model.xml

   <field name="my_model_line" attrs="{'readonly': [('state','not in', ('draft'))]}"> 
        <tree string="My model Lines" editable="bottom"> 
         <field name="name"/> 
         <field name="quantity"/> 
         <field name="remarks"/> 
         <button name="open_new_view" type="object" string="Add" class="oe_highlight"/> 
         <button icon="terp-face-plain" name="test" type="object" string="Add" class="oe_highlight"/> 
        </tree> 
       </field> 

我想隱藏my.model.line MOEL 備註字段添加按鈕字段取決於my.model狀態。 例如,如果我的模型狀態被批准,則隱藏字段。

據我所知,我不能在我的my_model.xml中使用域的隱形屬性,因爲my.model.line沒有狀態字段。也許有什麼解決方案來做到這一點?

我在想在my.model.line對象中創建狀態字段,螞蟻根據my.model狀態改變它的狀態。

而且我試圖像這樣:

<field name="remarks" attrs="{'invisible': "[('my_model_id .state', '=', 'approved')]"}"/> 

但後來我得到了一個錯誤:「未知領域my_model_id.state域」

回答

1

首先使用在這一領域應加ATTRS場表單視圖不僅僅是模型記住了這一點,即使它意味着添加這個字段並使其不可見。

其次如果你想顯示其他模塊的字段有一個many2one字段,它使用相關的字段。

  state = fields.Selection('put same selzction here too', related='many2one_field.state's, readonly=True) 

相關字段必須具有相同的類型,如果該字段爲字符使用CHAR,如果該字段爲整數使用整數,如果該字段many2one使用many2one。 對於大多數領域只是屬性相關是足夠的,但選擇重新定義相同的選擇。

現在,您可以使用該字段,例如它是當前模型的字段。

Soryy關於我的英語希望你有想法