2016-04-28 24 views

回答

0

您可以直接使用onchange,也可以擴展狀態欄小部件。

+0

如何?一個例子?因爲我在這裏發帖之前嘗試並且不工作 – josemi

0

這裏是步驟:

  1. 在XML使clickable="True"

    <header> 
        <field name="state" widget="statusbar" clickable="True" />   
        </header> 
    
  2. 在模型建立的方法具有象裝飾@api.onchange('state')

    @api.onchange('state') 
    def do_my_job(self): 
    #place your code here 
    pass 
    

希望這可以在你的情況有所幫助。

+0

我試過這樣的事情,明天我會再試一次,如果我工作與否會發布,謝謝,明天再見 – josemi

+0

重要的是狀態沒有被選中,但是很多重要嗎? – josemi

+0

將many2one字段名稱放在onchange中,如@ api.onchange('partner_id') – prakash

0

試試這個:

xml文件

<button name="action_draft" type="object" 
          string="Reset to draft" 
          states="confirm"/> 
<button name="action_confirm" type="object" 
            string="Confirm" states="draft" 
            class="oe_highlight"/> 
<field name="state" widget="statusbar"/> 

.py文件

def action_draft(self): 
    self.state = 'draft' 

def action_confirm(self): 
    self.state = 'confirm'