2017-10-16 3 views
0

J'ai ajouté trois champs supplémentaires au modèle project.task: Maintenant, j'ai besoin d'ajouter le bouton à la vue du formulaire de tâche pour voir la tâche parent ou les sous-tâches. Le bouton n'apparaît pas.Le bouton ne fonctionne pas dans odoo 10 communauté

modèle:

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") 
Code

pour le bouton:

@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> 

Répondre

0

il ne fonctionnera pas, le nom de la fonction doit être Bouton Nom Vous

0

ont créé "action "bouton. Donc, pour ce nom du bouton est "action_open_parent_task" insted de "500".

Et vous devez écrire le nom en XML comme ceci:

  <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

Votre code de bouton ne semble que son travail. Mauvaise implémentation.

0

XML vue Button:

<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