Skip to content

Commit

Permalink
[MIG] project_parent_task_filter: Migration to 15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mariadforgeflow committed Dec 16, 2021
1 parent 79252d3 commit 74af397
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
17 changes: 17 additions & 0 deletions project_parent_task_filter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from . import models

from odoo import api, SUPERUSER_ID


def _add_task_display_project(cr, registry):
"""This hook is used to set display_project_id field to the tasks that have a project_id set
but empty display_project_id.
This makes subtasks created in the Sub-task page of the parent Task visible in the project
kanban view"""

env = api.Environment(cr, SUPERUSER_ID, {})
tasks = env["project.task"].search(
[("parent_id", "!=", False), ("display_project_id", "=", False)]
)
for task in tasks:
task.write({"display_project_id": task.parent_id.project_id.id})
3 changes: 2 additions & 1 deletion project_parent_task_filter/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
{
"name": "Project Parent Task Filter",
"summary": "Add a filter to show the parent tasks",
"version": "14.0.1.1.0",
"version": "15.0.1.0.0",
"category": "Project",
"website": "https://github.com/OCA/project",
"author": "C2i Change 2 improve, " "Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["project"],
"data": ["data/res_config_data.xml", "views/project_task.xml"],
"installable": True,
"post_init_hook": "_add_task_display_project",
}
1 change: 1 addition & 0 deletions project_parent_task_filter/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import project
29 changes: 29 additions & 0 deletions project_parent_task_filter/models/project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from odoo import api, models


class TaskSub(models.Model):
_inherit = "project.task"

@api.model_create_multi
def create(self, vals_list):
res = super(TaskSub, self).create(vals_list)
for vals in vals_list:
if vals.get("parent_id", False):
res["display_project_id"] = (
self.env["project.task"].browse(vals.get("parent_id")).project_id.id
)
return res

def action_subtask(self):
action = {
"type": "ir.actions.act_window",
"name": "Subtasks of " + self.name,
"res_model": "project.task",
"view_mode": "tree,kanban,form,calendar,pivot,graph,activity",
"search_view_id": [
self.env.ref("project.view_task_search_form").id,
"search",
],
"domain": [("id", "!=", self.id), ("id", "child_of", self.id)],
}
return action
12 changes: 12 additions & 0 deletions project_parent_task_filter/views/project_task.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,23 @@
</xpath>
</field>
</record>

<record id="view_task_tree_subtask" model="ir.ui.view">
<field name="name">project.task.tree.substask</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_tree2" />
<field name="arch" type="xml">
<tree position="attributes">
<attribute name="create">0</attribute>
</tree>
</field>
</record>
<record id="view_task_kanban_subtask" model="ir.ui.view">
<field name="name">project.task.kanban</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_kanban" />
<field name="arch" type="xml">

<kanban position="inside">
<field name="allow_subtasks" />
</kanban>
Expand Down

0 comments on commit 74af397

Please sign in to comment.