bemade_fsm: Propagation of task assignee to subtasks (optional).

This commit is contained in:
Marc Durepos 2023-12-05 14:56:06 -05:00
parent 41ef2c1484
commit 74ec46382a
6 changed files with 63 additions and 2 deletions

View file

@ -20,7 +20,7 @@
######################################################################################## ########################################################################################
{ {
'name': 'Improved Field Service Management', 'name': 'Improved Field Service Management',
'version': '15.0.1.0.4', 'version': '15.0.1.0.5',
'summary': 'Adds functionality necessary for managing field service operations at Durpro.', 'summary': 'Adds functionality necessary for managing field service operations at Durpro.',
'description': 'Adds functionality necessary for managing field service operations at Durpro.', 'description': 'Adds functionality necessary for managing field service operations at Durpro.',
'category': 'Services/Field Service', 'category': 'Services/Field Service',

View file

@ -76,6 +76,12 @@ class Task(models.Model):
work_order_number = fields.Char(readonly=True) work_order_number = fields.Char(readonly=True)
propagate_assignment = fields.Boolean(
string='Propagate Assignment',
help='Propagate assignment of this task to all subtasks.',
default=True,
)
@api.model_create_multi @api.model_create_multi
def create(self, vals): def create(self, vals):
res = super().create(vals) res = super().create(vals)
@ -92,6 +98,16 @@ class Task(models.Model):
+ f"-{seq}" + f"-{seq}"
return res return res
def write(self, vals):
super().write(vals)
if not self: # End recursion on empty RecordSet
return
if 'user_ids' in vals:
to_propagate = self.filtered(lambda task: task.propagate_assignment)
# Here we use child_ids instead of _get_all_subtasks() so as to allow for setting propagate_assignment
# to false on a child task.
to_propagate.child_ids.write({'user_ids': vals['user_ids']})
@api.depends('sale_order_id') @api.depends('sale_order_id')
def _compute_relevant_order_lines(self): def _compute_relevant_order_lines(self):
for rec in self: for rec in self:
@ -199,6 +215,7 @@ class Task(models.Model):
if self.child_ids: if self.child_ids:
return self | self.child_ids._get_full_hierarchy() return self | self.child_ids._get_full_hierarchy()
return self return self
def synchronize_name_fsm(self): def synchronize_name_fsm(self):
""" Applies naming to the entire task tree for tasks that are part of this """ Applies naming to the entire task tree for tasks that are part of this
recordset. Root tasks are named: recordset. Root tasks are named:

View file

@ -4,3 +4,4 @@ from . import test_sale_order
from . import test_equipment from . import test_equipment
from . import test_fsm_contact_setting from . import test_fsm_contact_setting
from . import test_fsm_visit from . import test_fsm_visit
from . import test_task

View file

@ -0,0 +1,40 @@
from .test_bemade_fsm_common import BemadeFSMBaseTest
from odoo.tests.common import tagged
from odoo import Command
@tagged('post_install', '-at_install')
class TaskTest(BemadeFSMBaseTest):
def test_reassigning_assignment_propagating_task_changes_subtasks(self):
# This creation step is a bit lazy - we use defaults to make tasks with a hierachy and settings we want
so = self._generate_sale_order()
template = self._generate_task_template(names=['Parent', 'Child'], structure=[2])
product = self._generate_product(task_template=template)
sol = self._generate_sale_order_line(sale_order=so, product=product)
user = self._generate_project_manager_user('Bob', 'Bob')
so.action_confirm()
task = sol.task_id
task.write({
'user_ids': [Command.set([user.id])]
})
self.assertTrue(all([t.user_ids == user for t in task | task._get_all_subtasks()]))
def test_reassigning_assignment_non_propagating_task_doesnt_change_subtasks(self):
so = self._generate_sale_order()
template = self._generate_task_template(names=['Parent', 'Child', 'Grandchild'], structure=[2, 1])
product = self._generate_product(task_template=template)
sol = self._generate_sale_order_line(sale_order=so, product=product)
user = self._generate_project_manager_user('Bob', 'Bob')
so.action_confirm()
task = sol.task_id
task.child_ids.write({'propagate_assignment': False}) # Stop propagation after the first level
task.write({
'user_ids': [Command.set([user.id])]
})
self.assertTrue(all([t.user_ids == user for t in task | task.child_ids]))
self.assertFalse(any([t.user_ids for t in task.child_ids.child_ids]))

View file

@ -46,6 +46,9 @@
<xpath expr="//field[@name='child_ids']/tree//field[@name='name']" position="after"> <xpath expr="//field[@name='child_ids']/tree//field[@name='name']" position="after">
<field name="description" string="Description/Comments"/> <field name="description" string="Description/Comments"/>
</xpath> </xpath>
<field name="user_ids" position="after">
<field name="propagate_assignment"/>
</field>
</field> </field>
</record> </record>
<!-- Add parent_id = false to domain for My Tasks, All Tasks: To Schedule, All Tasks and To Invoice--> <!-- Add parent_id = false to domain for My Tasks, All Tasks: To Schedule, All Tasks and To Invoice-->