diff --git a/models/__pycache__/sale_order.cpython-310.pyc b/models/__pycache__/sale_order.cpython-310.pyc index 29c5013..c87196c 100644 Binary files a/models/__pycache__/sale_order.cpython-310.pyc and b/models/__pycache__/sale_order.cpython-310.pyc differ diff --git a/models/sale_order.py b/models/sale_order.py index 6cbc9cb..fa04c34 100644 --- a/models/sale_order.py +++ b/models/sale_order.py @@ -11,21 +11,17 @@ class SaleOrderLine(models.Model): Override to add the logic needed to implement task templates.""" def _create_task_from_template(project, template, parent): - """ Recursively generates the task and any subtasks from a project.task.template. Subtasks are left without - a specific project_id so that only the top-level tasks shows up on the project task list/kanban views. + """ Recursively generates the task and any subtasks from a project.task.template. :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 parent: project.task to set as the parent to this task. """ values = _timesheet_create_task_prepare_values_from_template(project, template, parent) task = self.env['project.task'].sudo().create(values) subtasks = [] - for subtask in tmpl.subtasks: - # Recurse, but pass the Project model so that no project_id gets set on the subtasks - subtask = _create_task_from_template(self.env['project.project'], tmpl, task) + for t in template.subtasks: + subtask = _create_task_from_template(project, t, task) subtasks.append(subtask) task.write({'child_ids': [Command.set([t.id for t in subtasks])]}) return task diff --git a/tests/__init__.py b/tests/__init__.py index 5bad71e..9df0958 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1 +1,2 @@ from . import test_task_template +from . import test_task_template_sale_order diff --git a/tests/__pycache__/__init__.cpython-310.pyc b/tests/__pycache__/__init__.cpython-310.pyc index abb4558..fad4092 100644 Binary files a/tests/__pycache__/__init__.cpython-310.pyc and b/tests/__pycache__/__init__.cpython-310.pyc differ diff --git a/tests/__pycache__/test_task_template.cpython-310.pyc b/tests/__pycache__/test_task_template.cpython-310.pyc index f0e0da4..f21b926 100644 Binary files a/tests/__pycache__/test_task_template.cpython-310.pyc and b/tests/__pycache__/test_task_template.cpython-310.pyc differ diff --git a/tests/test_task_template.py b/tests/test_task_template.py index 62813fd..ad84734 100644 --- a/tests/test_task_template.py +++ b/tests/test_task_template.py @@ -31,13 +31,14 @@ class TestTaskTemplateCommon(TransactionCase): 'email': 'mrpm@testco.com', 'signature': 'Mr. PM', '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 # Test product to use with the various tests cls.task1 = cls.env['project.task.template'].create({ 'name': 'Template 1', }) + cls.project = cls.env['project.project'].create({ 'name': 'Test Project', }) @@ -50,11 +51,15 @@ class TestTaskTemplateCommon(TransactionCase): 'uom_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({ 'name': 'Test Product 2', 'type': 'service', 'service_tracking': 'task_in_project', 'task_template_id': cls.task1.id, + 'project_template_id': cls.project_template.id, 'uom_po_id': hours_uom.id, 'uom_id': hours_uom.id, }) @@ -93,6 +98,7 @@ class TestTaskTemplateCommon(TransactionCase): 'type': 'service', 'service_tracking': 'task_in_project', 'task_template_id': cls.parent_task.id, + 'project_template_id': cls.project_template.id, 'uom_po_id': hours_uom.id, 'uom_id': hours_uom.id, })