parent
972aa554cd
commit
cc1faa541c
6 changed files with 11 additions and 8 deletions
Binary file not shown.
|
|
@ -11,21 +11,17 @@ class SaleOrderLine(models.Model):
|
||||||
Override to add the logic needed to implement task templates."""
|
Override to add the logic needed to implement task templates."""
|
||||||
|
|
||||||
def _create_task_from_template(project, template, parent):
|
def _create_task_from_template(project, template, parent):
|
||||||
""" Recursively generates the task and any subtasks from a project.task.template. Subtasks are left without
|
""" Recursively generates the task and any subtasks from a project.task.template.
|
||||||
a specific project_id so that only the top-level tasks shows up on the project task list/kanban views.
|
|
||||||
|
|
||||||
:param project: project.project record to set on the task's project_id field.
|
:param project: project.project record to set on the task's project_id field.
|
||||||
Pass the project.project model to leave task project_id blank. DO NOT pass False or None as this will
|
|
||||||
cause an error in _timesheet_create_task_prepare_values(project).
|
|
||||||
:param template: project.task.template to use to create the task.
|
:param template: project.task.template to use to create the task.
|
||||||
:param parent: project.task to set as the parent to this task.
|
:param parent: project.task to set as the parent to this task.
|
||||||
"""
|
"""
|
||||||
values = _timesheet_create_task_prepare_values_from_template(project, template, parent)
|
values = _timesheet_create_task_prepare_values_from_template(project, template, parent)
|
||||||
task = self.env['project.task'].sudo().create(values)
|
task = self.env['project.task'].sudo().create(values)
|
||||||
subtasks = []
|
subtasks = []
|
||||||
for subtask in tmpl.subtasks:
|
for t in template.subtasks:
|
||||||
# Recurse, but pass the Project model so that no project_id gets set on the subtasks
|
subtask = _create_task_from_template(project, t, task)
|
||||||
subtask = _create_task_from_template(self.env['project.project'], tmpl, task)
|
|
||||||
subtasks.append(subtask)
|
subtasks.append(subtask)
|
||||||
task.write({'child_ids': [Command.set([t.id for t in subtasks])]})
|
task.write({'child_ids': [Command.set([t.id for t in subtasks])]})
|
||||||
return task
|
return task
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
from . import test_task_template
|
from . import test_task_template
|
||||||
|
from . import test_task_template_sale_order
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -31,13 +31,14 @@ class TestTaskTemplateCommon(TransactionCase):
|
||||||
'email': 'mrpm@testco.com',
|
'email': 'mrpm@testco.com',
|
||||||
'signature': 'Mr. PM',
|
'signature': 'Mr. PM',
|
||||||
'groups_id': [(6, 0, [user_group_employee.id, user_group_project_user.id, user_group_project_manager.id,
|
'groups_id': [(6, 0, [user_group_employee.id, user_group_project_user.id, user_group_project_manager.id,
|
||||||
user_group_sales_user.id])]
|
user_group_sales_user.id])],
|
||||||
})
|
})
|
||||||
hours_uom = cls.env['uom.uom'].search([('name', '=', 'Hour')]) or False
|
hours_uom = cls.env['uom.uom'].search([('name', '=', 'Hour')]) or False
|
||||||
# Test product to use with the various tests
|
# Test product to use with the various tests
|
||||||
cls.task1 = cls.env['project.task.template'].create({
|
cls.task1 = cls.env['project.task.template'].create({
|
||||||
'name': 'Template 1',
|
'name': 'Template 1',
|
||||||
})
|
})
|
||||||
|
|
||||||
cls.project = cls.env['project.project'].create({
|
cls.project = cls.env['project.project'].create({
|
||||||
'name': 'Test Project',
|
'name': 'Test Project',
|
||||||
})
|
})
|
||||||
|
|
@ -50,11 +51,15 @@ class TestTaskTemplateCommon(TransactionCase):
|
||||||
'uom_id': hours_uom.id,
|
'uom_id': hours_uom.id,
|
||||||
'uom_po_id': hours_uom.id,
|
'uom_po_id': hours_uom.id,
|
||||||
})
|
})
|
||||||
|
cls.project_template = cls.env['project.project'].create({
|
||||||
|
'name': 'Test Project Template',
|
||||||
|
})
|
||||||
cls.product_task_in_project = cls.env['product.product'].create({
|
cls.product_task_in_project = cls.env['product.product'].create({
|
||||||
'name': 'Test Product 2',
|
'name': 'Test Product 2',
|
||||||
'type': 'service',
|
'type': 'service',
|
||||||
'service_tracking': 'task_in_project',
|
'service_tracking': 'task_in_project',
|
||||||
'task_template_id': cls.task1.id,
|
'task_template_id': cls.task1.id,
|
||||||
|
'project_template_id': cls.project_template.id,
|
||||||
'uom_po_id': hours_uom.id,
|
'uom_po_id': hours_uom.id,
|
||||||
'uom_id': hours_uom.id,
|
'uom_id': hours_uom.id,
|
||||||
})
|
})
|
||||||
|
|
@ -93,6 +98,7 @@ class TestTaskTemplateCommon(TransactionCase):
|
||||||
'type': 'service',
|
'type': 'service',
|
||||||
'service_tracking': 'task_in_project',
|
'service_tracking': 'task_in_project',
|
||||||
'task_template_id': cls.parent_task.id,
|
'task_template_id': cls.parent_task.id,
|
||||||
|
'project_template_id': cls.project_template.id,
|
||||||
'uom_po_id': hours_uom.id,
|
'uom_po_id': hours_uom.id,
|
||||||
'uom_id': hours_uom.id,
|
'uom_id': hours_uom.id,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue