bemade_fsm: Task naming modified to shorten child task names.
Fixes Dur-Pro/bemade-addons#92
This commit is contained in:
parent
bf45e250a2
commit
f157ba3d9b
5 changed files with 57 additions and 21 deletions
|
|
@ -147,10 +147,6 @@ class SaleOrderLine(models.Model):
|
|||
task.child_ids.write({'sale_order_id': None, 'sale_line_id': None, })
|
||||
return task
|
||||
|
||||
def _generate_task_name(template=None):
|
||||
template_name = template and template.name
|
||||
return f"{self.order_id.name}: {self.order_id.partner_shipping_id.name} - {self.name} ({template_name})"
|
||||
|
||||
def _timesheet_create_task_prepare_values_from_template(project, template,
|
||||
parent):
|
||||
""" Copies the values from a project.task.template over to the set of values used to create a project.task.
|
||||
|
|
@ -162,7 +158,7 @@ class SaleOrderLine(models.Model):
|
|||
:param parent: project.task to set as the parent to this task.
|
||||
"""
|
||||
vals = self._timesheet_create_task_prepare_values(project)
|
||||
vals['name'] = _generate_task_name(template) if not parent else template.name
|
||||
vals['name'] = template.name
|
||||
vals['description'] = template.description or vals['description']
|
||||
vals['parent_id'] = parent and parent.id
|
||||
vals['user_ids'] = template.assignees.ids
|
||||
|
|
@ -186,7 +182,6 @@ class SaleOrderLine(models.Model):
|
|||
if not task.equipment_ids and self.equipment_ids:
|
||||
task.equipment_ids = self.equipment_ids.ids
|
||||
task.planned_hours = self.task_duration
|
||||
task.name = _generate_task_name(tmpl)
|
||||
return task
|
||||
|
||||
def _timesheet_service_generation(self):
|
||||
|
|
@ -202,12 +197,13 @@ class SaleOrderLine(models.Model):
|
|||
project_id = task_ids[0].project_id
|
||||
line.visit_id.task_id = line._generate_task_for_visit_line(project_id)
|
||||
task_ids.write({'parent_id': line.visit_id.task_id.id})
|
||||
self.mapped('task_id').synchronize_name_fsm()
|
||||
|
||||
def _generate_task_for_visit_line(self, project):
|
||||
self.ensure_one()
|
||||
|
||||
task = self.env['project.task'].create({
|
||||
'name': self.order_id.name + ": " + self.name,
|
||||
'name': 'Temp Name',
|
||||
'description': f"Parent task for {self.order_id.name}, visit {self.name}",
|
||||
'project_id': project.id,
|
||||
'equipment_ids': self.get_section_line_ids().mapped('equipment_ids').ids,
|
||||
|
|
|
|||
|
|
@ -151,3 +151,28 @@ class Task(models.Model):
|
|||
for visit in visits:
|
||||
stage = closed_stage_by_project[visit.project_id]
|
||||
visits.write({'stage_id': stage.id, 'fsm_done': True})
|
||||
|
||||
def synchronize_name_fsm(self):
|
||||
""" Applies naming to the entire task tree for tasks that are part of this
|
||||
recordset. Root tasks are named:
|
||||
|
||||
SOXXXXX: Partner Shipping Name - Sale Line Name (Template Name)
|
||||
|
||||
Child tasks with sale_line_id are named by their template if set, sale line name
|
||||
if not.
|
||||
|
||||
Child tasks not linked to sale lines are left with their original names."""
|
||||
|
||||
all_tasks = self | self._get_all_subtasks()
|
||||
for rec in all_tasks:
|
||||
assert rec.is_fsm, "This method should only be called on FSM tasks."
|
||||
|
||||
template = rec.sale_line_id and rec.sale_line_id.product_id.task_template_id
|
||||
if not rec.parent_id:
|
||||
rec.name = f"{rec.sale_order_id.name}: " \
|
||||
f"{rec.sale_order_id.partner_shipping_id.name} - " \
|
||||
f"{rec.sale_line_id.name}"
|
||||
if template:
|
||||
rec.name += f" ({template.name})"
|
||||
else:
|
||||
rec.name = f"{template.name or rec.sale_line_id.name or rec.name}"
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ class FSMVisitTest(BemadeFSMBaseTest):
|
|||
self.assertEqual(sol2.qty_to_deliver, 0)
|
||||
self.assertTrue(visit.is_completed)
|
||||
|
||||
def test_marking_visit_done_does_not_create_sale_order_line(self):
|
||||
def test_marking_visit_task_done_does_not_create_sale_order_line(self):
|
||||
so, visit, sol1, sol2 = self._generate_so_with_one_visit_two_lines()
|
||||
so.action_confirm()
|
||||
|
||||
|
|
|
|||
|
|
@ -21,28 +21,30 @@ class TestSalesOrder(BemadeFSMBaseTest):
|
|||
self.assertTrue(task_template.name in task.name)
|
||||
self.assertTrue(task_template.planned_hours == task.planned_hours)
|
||||
|
||||
def test_order_confirmation_tree_template(self):
|
||||
def test_task_template_tree_order_confirmation(self):
|
||||
partner = self._generate_partner()
|
||||
so = self._generate_sale_order(partner=partner)
|
||||
parent_task = self._generate_task_template(structure=[2, 1],
|
||||
parent_template = self._generate_task_template(structure=[2, 1],
|
||||
names=['Parent Template',
|
||||
'Child Template',
|
||||
'Grandchild Template'])
|
||||
child_task_1 = parent_task.subtasks[0]
|
||||
child_task_2 = parent_task.subtasks[1]
|
||||
grandchild_task = parent_task.subtasks[0].subtasks[0]
|
||||
product = self._generate_product(task_template=parent_task)
|
||||
child_template_1= parent_template.subtasks[0]
|
||||
child_template_2 = parent_template.subtasks[1]
|
||||
grandchild_template = parent_template.subtasks[0].subtasks[0]
|
||||
product = self._generate_product(task_template=parent_template)
|
||||
sol = self._generate_sale_order_line(so, product=product)
|
||||
|
||||
so.action_confirm()
|
||||
|
||||
self.assertTrue(sol.task_id.child_ids and len(sol.task_id.child_ids) == 2)
|
||||
self.assertTrue(parent_task.name in sol.task_id.name)
|
||||
self.assertTrue(child_task_1.name in sol.task_id.child_ids[0].name)
|
||||
self.assertTrue(child_task_2.name in sol.task_id.child_ids[1].name)
|
||||
self.assertTrue(sol.task_id.child_ids[0].child_ids and len(
|
||||
sol.task_id.child_ids[0].child_ids) == 1)
|
||||
self.assertTrue(grandchild_task.name in sol.task_id.child_ids.child_ids[0].name)
|
||||
parent = sol.task_id
|
||||
c1, c2 = parent.child_ids
|
||||
gc = c1.child_ids[:1]
|
||||
self.assertTrue(parent.child_ids and len(parent.child_ids) == 2)
|
||||
self.assertTrue(parent_template.name in parent.name)
|
||||
self.assertEqual(child_template_1.name, c1.name)
|
||||
self.assertEqual(child_template_2.name, c2.name)
|
||||
self.assertTrue(c1.child_ids and len(c1.child_ids) == 1)
|
||||
self.assertEqual(grandchild_template.name, gc.name)
|
||||
|
||||
def test_order_confirmation_single_equipment(self):
|
||||
""" The equipment selected on the SO should transfer to the task."""
|
||||
|
|
|
|||
|
|
@ -65,6 +65,19 @@ class TestTaskTemplate(BemadeFSMBaseTest):
|
|||
|
||||
self.assertEqual(sol.task_duration, 24)
|
||||
|
||||
def test_child_task_names_are_short_version(self):
|
||||
so, visit, sol1, sol2 = self._generate_so_with_one_visit_two_lines()
|
||||
template = self._generate_task_template(names=['Task'])
|
||||
product = self._generate_product(task_template=template)
|
||||
sol1.name = "Short Name 1"
|
||||
sol2.name = "Short Name 2"
|
||||
sol3 = self._generate_sale_order_line(sale_order=so, product=product)
|
||||
|
||||
so.action_confirm()
|
||||
|
||||
self.assertEqual(sol1.task_id.name, "Short Name 1")
|
||||
self.assertEqual(sol2.task_id.name, "Short Name 2")
|
||||
self.assertEqual(sol3.task_id.name, "Task")
|
||||
|
||||
|
||||
@tagged('-at_install', 'post_install', 'slow')
|
||||
|
|
|
|||
Loading…
Reference in a new issue