bemade_fsm: Unit tests complete for #1 and #2.

This commit is contained in:
Marc Durepos 2023-06-09 13:51:29 -04:00
parent 4391066b08
commit 9b7e970f9c
6 changed files with 11 additions and 8 deletions

View file

@ -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

View file

@ -1 +1,2 @@
from . import test_task_template
from . import test_task_template_sale_order

View file

@ -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,
})