Browse Source

Jun 21: [FIX] Bug Fixed 'project_tasks_from_templates'

pull/331/head
RisvanaCybro 10 months ago
parent
commit
f72659b8c9
  1. 1
      project_tasks_from_templates/__manifest__.py
  2. 52
      project_tasks_from_templates/models/project_project.py
  3. 13
      project_tasks_from_templates/models/project_sub_task.py
  4. 31
      project_tasks_from_templates/models/project_task_template.py
  5. 1
      project_tasks_from_templates/security/ir.model.access.csv
  6. 16
      project_tasks_from_templates/views/project_stage_views.xml
  7. 9
      project_tasks_from_templates/views/project_sub_task_views.xml
  8. 5
      project_tasks_from_templates/views/project_task_template_views.xml

1
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'],

52
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)

13
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:

31
project_tasks_from_templates/models/project_task_template.py

@ -19,7 +19,7 @@
# If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
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')

1
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

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_project_task_template_manager access.project.task.template.manager model_project_task_template project.group_project_manager 1 1 1 1
3 access_project_sub_task_manager access.project.sub.task.manager model_project_sub_task project.group_project_manager 1 1 1 1
4 access_project_stage access.project.stage model_project_stage project.group_project_manager 1 1 1 1

16
project_tasks_from_templates/views/project_stage_views.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<!-- Tree view for project.stage -->
<record id="project_stage_custom_view_tree" model="ir.ui.view">
<field name="name">project.stage.tree</field>
<field name="model">project.stage</field>
<field name="arch" type="xml">
<tree editable="bottom" >
<field name='sequence' widget='handle'/>
<field name="project_stage_id" domain="[('project_template_id', '=', project_template_id)]" context="{'default_project_template_id': project_template_id, 'default_sequence': sequence}" options="{'no_create_edit':True}"/>
<field name="project_template_id" column_invisible="True"/>
<field name="task_ids" domain="[('project_template_id', '=', project_template_id)]" widget="many2many_tags"/>
</tree>
</field>
</record>
</odoo>

9
project_tasks_from_templates/views/project_sub_task_views.xml

@ -14,9 +14,12 @@
</group>
<notebook>
<page name="tasks_page" string="Tasks" invisible="show_tasks_page == False">
<tree editable="bottom" >
<field name="child_ids"/>
</tree>
<field name="child_ids">
<tree editable="bottom">
<field name="name"/>
<field name="state"/>
</tree>
</field>
</page>
</notebook>
</sheet>

5
project_tasks_from_templates/views/project_task_template_views.xml

@ -28,11 +28,16 @@
<field name="description" type="html"/>
<field name="user_ids" widget="many2many_avatar_user"
optional="show" domain="[('share', '=', False), ('active', '=', True)]"/>
<field name="state"/>
<button name="action_open_task" type="object" title="View Task"
string="View Task" class="btn btn-link pull-right"/>
</tree>
</field>
</page>
<page name="stages_page" string="Stages">
<field name="stage_ids">
</field>
</page>
</notebook>
</sheet>
</form>

Loading…
Cancel
Save