diff --git a/project_tasks_from_templates/__manifest__.py b/project_tasks_from_templates/__manifest__.py
index 10c357e22..80e721ecb 100755
--- a/project_tasks_from_templates/__manifest__.py
+++ b/project_tasks_from_templates/__manifest__.py
@@ -40,6 +40,7 @@
'security/ir.model.access.csv',
'views/project_project_views.xml',
'views/project_sub_task_views.xml',
+ 'views/project_stage_views.xml',
'views/project_task_template_views.xml'
],
'images': ['static/description/banner.jpg'],
diff --git a/project_tasks_from_templates/models/project_project.py b/project_tasks_from_templates/models/project_project.py
index 823de2be8..cc65e1a36 100755
--- a/project_tasks_from_templates/models/project_project.py
+++ b/project_tasks_from_templates/models/project_project.py
@@ -44,15 +44,23 @@ class ProjectProject(models.Model):
Returns:
dict: Action configuration to open the project form.
"""
- for item in self.project_template_id.task_ids:
- self._create_task(item, False)
- return {
- 'view_mode': 'form',
- 'res_model': 'project.project',
- 'res_id': self.id,
- 'type': 'ir.actions.act_window',
- 'context': self._context
- }
+ if not self.project_template_id.stage_ids:
+ for item in self.project_template_id.task_ids:
+ self._create_task(item, False)
+ return {
+ 'view_mode': 'form',
+ 'res_model': 'project.project',
+ 'res_id': self.id,
+ 'type': 'ir.actions.act_window',
+ 'context': self._context
+ }
+ else:
+ for item in self.project_template_id.stage_ids:
+ if self.id not in item.project_stage_id.project_ids.ids:
+ item.project_stage_id.project_ids = [(4, self.id)]
+ for task in item.task_ids:
+ self._create_task_with_stage(task, item.project_stage_id,
+ False)
def _create_task(self, item, parent):
"""Creates a new project task for the given item and attaches it to
@@ -61,6 +69,7 @@ class ProjectProject(models.Model):
item (models.Model): project task
parent (int): id of parent project task
"""
+
task = self.env['project.task'].sudo().create({
'project_id': self.id,
'name': item.name,
@@ -68,7 +77,28 @@ class ProjectProject(models.Model):
'stage_id': self.env['project.task.type'].search(
[('sequence', '=', 1)], limit=1).id,
'user_ids': item.user_ids,
- 'description': item.description
- })
+ 'description': item.description,
+ 'state': item.state or '01_in_progress',
+ })
for sub_task in item.child_ids:
self._create_task(sub_task, task.id)
+
+ def _create_task_with_stage(self, item, stage, parent=False):
+ """Creates a new project task with stage for the given item and attaches it to
+ the current project.
+ Args:
+ item (models.Model): project task
+ parent (int): id of parent project task
+ """
+
+ task = self.env['project.task'].sudo().create({
+ 'project_id': self.id,
+ 'name': item.name,
+ 'parent_id': parent,
+ 'stage_id': stage.id,
+ 'user_ids': item.user_ids,
+ 'description': item.description,
+ 'state': item.state or '01_in_progress',
+ })
+ for sub_task in item.child_ids:
+ self._create_task_with_stage(sub_task, stage, task.id)
diff --git a/project_tasks_from_templates/models/project_sub_task.py b/project_tasks_from_templates/models/project_sub_task.py
index a7a39a29b..d01b6b018 100644
--- a/project_tasks_from_templates/models/project_sub_task.py
+++ b/project_tasks_from_templates/models/project_sub_task.py
@@ -21,6 +21,11 @@
###############################################################################
from odoo import fields, models
+CLOSED_STATES = {
+ '1_done': 'Done',
+ '1_canceled': 'Canceled',
+}
+
class ProjectSubTask(models.Model):
"""Customized version of the 'project.task' model to support templates
@@ -53,6 +58,14 @@ class ProjectSubTask(models.Model):
string="Show Tasks Page",
readonly=False)
+ state = fields.Selection([
+ ('01_in_progress', 'In Progress'),
+ ('02_changes_requested', 'Changes Requested'),
+ ('03_approved', 'Approved'),
+ *CLOSED_STATES.items(),
+ ('04_waiting_normal', 'Waiting'),
+ ], string='State', default='01_in_progress')
+
def action_open_task(self):
""" Action method to open the current task in a form view.
Returns:
diff --git a/project_tasks_from_templates/models/project_task_template.py b/project_tasks_from_templates/models/project_task_template.py
index 9e67699e9..0493582af 100644
--- a/project_tasks_from_templates/models/project_task_template.py
+++ b/project_tasks_from_templates/models/project_task_template.py
@@ -19,7 +19,7 @@
# If not, see .
#
###############################################################################
-from odoo import fields, models
+from odoo import fields, models , api
class ProjectTaskTemplate(models.Model):
@@ -33,3 +33,32 @@ class ProjectTaskTemplate(models.Model):
'project.sub.task', 'project_template_id',
string='Tasks',
help='List of the tasks associated with this template.')
+ stage_ids = fields.One2many(
+ 'project.stage', 'project_template_id',
+ string='Stages',
+ help='List of the stages associated with this template.')
+
+
+class ProjectStage(models.Model):
+ """A model to define task templates for projects."""
+ _name = 'project.stage'
+ _order = "sequence,id"
+
+ project_template_id = fields.Many2one(
+ 'project.task.template', string='Project Template',
+ help='Select a project task template to use for this task.')
+ project_stage_id = fields.Many2one(
+ 'project.task.type', string='Project Stage',
+ help='Select a project stage. ',required=True)
+ task_ids = fields.Many2many(
+ 'project.sub.task',
+ help='Choose the tasks corresponding to each stage')
+
+ sequence = fields.Integer(related="project_stage_id.sequence",readonly=False)
+
+
+class ProjectTaskType(models.Model):
+ _inherit = "project.task.type"
+
+ project_template_id = fields.Many2one(
+ 'project.task.template')
diff --git a/project_tasks_from_templates/security/ir.model.access.csv b/project_tasks_from_templates/security/ir.model.access.csv
index cc697a045..883a3685c 100755
--- a/project_tasks_from_templates/security/ir.model.access.csv
+++ b/project_tasks_from_templates/security/ir.model.access.csv
@@ -1,3 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_project_task_template_manager,access.project.task.template.manager,model_project_task_template,project.group_project_manager,1,1,1,1
access_project_sub_task_manager,access.project.sub.task.manager,model_project_sub_task,project.group_project_manager,1,1,1,1
+access_project_stage,access.project.stage,model_project_stage,project.group_project_manager,1,1,1,1
diff --git a/project_tasks_from_templates/views/project_stage_views.xml b/project_tasks_from_templates/views/project_stage_views.xml
new file mode 100644
index 000000000..5de9b5998
--- /dev/null
+++ b/project_tasks_from_templates/views/project_stage_views.xml
@@ -0,0 +1,16 @@
+
+
+
+
+ project.stage.tree
+ project.stage
+
+
+
+
+
+
+
+
+
+
diff --git a/project_tasks_from_templates/views/project_sub_task_views.xml b/project_tasks_from_templates/views/project_sub_task_views.xml
index 75d217e8f..cde11883f 100644
--- a/project_tasks_from_templates/views/project_sub_task_views.xml
+++ b/project_tasks_from_templates/views/project_sub_task_views.xml
@@ -14,9 +14,12 @@
-
-
-
+
+
+
+
+
+
diff --git a/project_tasks_from_templates/views/project_task_template_views.xml b/project_tasks_from_templates/views/project_task_template_views.xml
index eb3b46a1d..1e0cce24c 100644
--- a/project_tasks_from_templates/views/project_task_template_views.xml
+++ b/project_tasks_from_templates/views/project_task_template_views.xml
@@ -28,11 +28,16 @@
+
+
+
+
+