[FIX] bemade_fsm: update partner when SO shipping location changes

This commit is contained in:
Marc Durepos 2024-09-25 10:19:09 -04:00
parent 31c3695c3e
commit 96e5b2d2fe
4 changed files with 27 additions and 12 deletions

View file

@ -154,3 +154,10 @@ class SaleOrder(models.Model):
def action_confirm(self): def action_confirm(self):
self._create_or_organize_visits_if_needed() self._create_or_organize_visits_if_needed()
return super().action_confirm() return super().action_confirm()
def write(self, values):
res = super().write(values)
if "partner_shipping_id" in values:
for rec in self:
rec.tasks_ids.write({"partner_id": rec.partner_shipping_id.id})
return res

View file

@ -111,7 +111,7 @@ class SaleOrderLine(models.Model):
for t in template.subtasks: for t in template.subtasks:
subtask = _create_task_from_template(project, t, task) subtask = _create_task_from_template(project, t, 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])]})
# We don't want to see the sub-tasks on the SO # We don't want to see the sub-tasks on the SO
task.child_ids.write( task.child_ids.write(
{ {
@ -142,7 +142,7 @@ class SaleOrderLine(models.Model):
vals["tag_ids"] = template.tags.ids vals["tag_ids"] = template.tags.ids
vals["allocated_hours"] = template.planned_hours vals["allocated_hours"] = template.planned_hours
vals["sequence"] = template.sequence vals["sequence"] = template.sequence
# vals["partner_id"] = parent and parent.partner_id and parent.partner_id.id vals["partner_id"] = self.order_id.partner_id.id
if template.equipment_ids: if template.equipment_ids:
vals["equipment_ids"] = template.equipment_ids.ids vals["equipment_ids"] = template.equipment_ids.ids
return vals return vals

View file

@ -53,6 +53,7 @@ class Task(models.Model):
root_ancestor = fields.Many2one( root_ancestor = fields.Many2one(
comodel_name="project.task", comodel_name="project.task",
compute="_compute_root_ancestor", compute="_compute_root_ancestor",
recursive=True,
) )
def _compute_is_closed(self): def _compute_is_closed(self):
@ -109,14 +110,20 @@ class Task(models.Model):
# Here we use child_ids instead of _get_all_subtasks() so as to allow for setting 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 false on a child task.
to_propagate.child_ids.write({"user_ids": vals["user_ids"]}) to_propagate.child_ids.write({"user_ids": vals["user_ids"]})
if "site_contacts" in vals and self.child_ids: for rec in self:
self._get_all_subtasks().write( if rec.child_ids:
{"site_contacts": [Command.set(self.site_contacts.ids)]} child_vals = {}
) if "site_contacts" in vals:
if "work_order_contacts" in vals and self.child_ids: child_vals.update(
self._get_all_subtasks().write( site_contacts=[Command.set(rec.site_contacts.ids)]
{"work_order_contacts": [Command.set(self.work_order_contacts.ids)]} )
) if "work_order_contacts" in vals:
child_vals.update(
work_order_contacts=[Command.set(rec.work_order_contacts.ids)]
)
if "partner_id" in vals:
child_vals.update(partner_id=vals["partner_id"])
rec.child_ids.write(child_vals)
return res return res
@api.depends("sale_order_id") @api.depends("sale_order_id")

View file

@ -348,15 +348,16 @@ class TestSalesOrder(BemadeFSMBaseTest):
so.write( so.write(
{ {
"partner_shipping_id": self.env["res.partner"].create( "partner_shipping_id": self.env["res.partner"]
.create(
{ {
"name": "New shipping address", "name": "New shipping address",
"parent_id": so.partner_id.id, "parent_id": so.partner_id.id,
"type": "delivery", "type": "delivery",
} }
) )
.id
} }
) )
for task in parent_task._get_all_subtasks() | parent_task: for task in parent_task._get_all_subtasks() | parent_task:
self.assertEqual(so.partner_shipping_id, task.partner_id) self.assertEqual(so.partner_shipping_id, task.partner_id)