2017-10-16 89 views
0

我已經添加了三個額外的領域project.task模型: 現在我需要添加按鈕到任務表單視圖來查看父任務或子任務。 該按鈕不出現。按鈕不工作在odoo 10社區

型號:用於按鈕

parent_id = fields.Many2one('project.task', string='Parent Task') 
child_ids = fields.One2many('project.task', 'parent_id', string="Sub-tasks") 
subtask_count = fields.Integer(compute='_compute_subtask_count', type='integer', string="Sub-task count") 

代碼:

@api.multi 
def _compute_subtask_count(self): 
    for task in self: 
     task.subtask_count = self.search_count([('id', 'child_of', task.id), ('id', '!=', task.id)]) 

def action_open_parent_task(self): 
    return { 
     'name': _('Parent Task'), 
     'view_type': 'form', 
     'view_mode': 'form', 
     'res_model': 'project.task', 
     'res_id': self.parent_id.id, 
     'type': 'ir.actions.act_window' 
    } 

view.xml用

<button class="oe_stat_button" icon="fa-tasks" type="object" name="action_open_parent_task" string="Parent Task" attrs="{'invisible' : [('parent_id', '=', False)]}" groups="project.group_subtask_project"/> 
      <button name="500" type="action" class="oe_stat_button" icon="fa-tasks" attrs="{'invisible' : [('parent_id', '!=', False)]}" context="{'project_id': subtask_project_id, 'name': name, 'partner_id': partner_id}" groups="project.group_subtask_project"> 
       <field string="Sub-tasks" name="subtask_count" widget="statinfo"/> 
      </button> 

回答

0

它不會工作,函數名應該是按鈕的名稱

0

你已創建「動作「按鈕。所以對於該名稱的按鈕是「action_open_parent_task」insted的「500」

而且你必須在XML寫的名字是這樣的:

  <button name="%(action_open_parent_task)d" type="action" class="oe_stat_button" icon="fa-tasks" attrs="{'invisible' : [('parent_id', '!=', False)]}" context="{'project_id': subtask_project_id, 'name': name, 'partner_id': partner_id}" groups="project.group_subtask_project"> 
0

按鈕代碼是不是看起來像它的工作。錯誤的實施。

0

XML按鈕來查看:

<div class="oe_button_box" name="button_box" groups="project.group_subtask_project"/> 
    <button name="action_open_parent_task" type="object" class="oe_stat_button" icon="fa-tasks" attrs="{'invisible' : [('parent_id', '!=', False)]}" context="{'project_id': subtask_project_id, 'name': name, 'partner_id': partner_id}"> 
     <field string="Sub-tasks" name="subtask_count" widget="statinfo"/> 
    </button> 
</div