按钮不工作在odoo 10社区
问题描述:
我已经添加了三个额外的领域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>
答
它不会工作,函数名应该是按钮的名称
答
你已创建“动作“按钮。所以对于该名称的按钮是“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">
答
按钮代码是不是看起来像它的工作。错误的实施。
答
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