按钮在odoo 10社区中不起作用

时间:2017-10-16 11:28:33

标签: odoo-10 odoo-view

我在project.task模型中添加了三个额外字段: 现在,我需要在任务表单视图中添加一个按钮,以查看父任务或子任务。 该按钮不会出现。

模型:

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>

4 个答案:

答案 0 :(得分:0)

它不起作用,函数名称应该是按钮名称

答案 1 :(得分:0)

您已创建“操作”按钮。因此按钮的名称是“ action_open_parent_task ”,其中包含“ 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">

答案 2 :(得分:0)

您的按钮代码似乎不起作用。错误的实施。

答案 3 :(得分: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
相关问题