[FIX] project: sub-tasks

- Activate sub-tasks in projects
- Enter a project's tasks, click on the stat button 'Sub-tasks'
- Reload the page (F5)

A traceback occurs since `project_id` is undefined.

The fields `project_id` and `partner_id` are only defined in the context
of the stat button.

opw-1844334
This commit is contained in:
Nicolas Martinelli
2018-05-15 08:47:20 +02:00
committed by Nicolas Martinelli
parent 429bcd9464
commit 1dbeda0157
2 changed files with 15 additions and 11 deletions
+14
View File
@@ -877,6 +877,20 @@ class Task(models.Model):
'type': 'ir.actions.act_window'
}
def action_subtask(self):
action = self.env.ref('project.project_task_action_sub_task').read()[0]
ctx = self.env.context.copy()
ctx.update({
'default_parent_id' : self.id,
'default_project_id' : self.env.context.get('project_id', self.subtask_project_id.id),
'default_name' : self.env.context.get('name', self.name) + ':',
'default_partner_id' : self.env.context.get('partner_id', self.partner_id.id),
'search_default_project_id': self.env.context.get('project_id', self.subtask_project_id.id),
})
action['context'] = ctx
action['domain'] = [('id', 'child_of', self.id), ('id', '!=', self.id)]
return action
class AccountAnalyticAccount(models.Model):
_inherit = 'account.analytic.account'
+1 -11
View File
@@ -84,16 +84,6 @@
<field name="name">Sub-tasks</field>
<field name="res_model">project.task</field>
<field name="view_mode">kanban,tree,form,calendar,pivot,graph</field>
<field name="domain">[('id', 'child_of', active_id), ('id', '!=', active_id)]</field>
<field name="context">
{
'default_parent_id' : active_id,
'default_project_id' : project_id,
'default_name' : name + ':',
'default_partner_id' : partner_id,
'search_default_project_id': [project_id],
}
</field>
<field name="search_view_id" ref="project.view_task_search_form"/>
</record>
@@ -403,7 +393,7 @@
<sheet string="Task">
<div class="oe_button_box" name="button_box">
<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="%(project_task_action_sub_task)d" type="action" class="oe_stat_button" icon="fa-tasks"
<button name="action_subtask" 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}" groups="project.group_subtask_project">
<field string="Sub-tasks" name="subtask_count" widget="statinfo"/>