bemade_fsm: correct partner_id on task to use partner_shipping_id from sale order
This commit is contained in:
parent
ab60babd7d
commit
b19da588cd
2 changed files with 25 additions and 7 deletions
|
|
@ -111,7 +111,6 @@ 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])]})
|
|
||||||
# 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 +141,11 @@ 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"] = self.order_id.partner_id.id
|
# Use shipping address for FSM tasks for consistency
|
||||||
|
if project and project.is_fsm:
|
||||||
|
vals["partner_id"] = self.order_id.partner_shipping_id.id
|
||||||
|
else:
|
||||||
|
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
|
||||||
|
|
@ -150,6 +153,9 @@ class SaleOrderLine(models.Model):
|
||||||
tmpl = self.product_id.task_template_id
|
tmpl = self.product_id.task_template_id
|
||||||
if not tmpl:
|
if not tmpl:
|
||||||
task = super()._timesheet_create_task(project)
|
task = super()._timesheet_create_task(project)
|
||||||
|
# For FSM tasks without a template, update partner_id to use shipping address
|
||||||
|
if project.is_fsm and task:
|
||||||
|
task.partner_id = self.order_id.partner_shipping_id.id
|
||||||
else:
|
else:
|
||||||
task = _create_task_from_template(project, tmpl, None)
|
task = _create_task_from_template(project, tmpl, None)
|
||||||
self.write({"task_id": task.id})
|
self.write({"task_id": task.id})
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,16 @@ class Task(models.Model):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
|
# Check if we're adding new child tasks
|
||||||
|
adding_children = False
|
||||||
|
if 'child_ids' in vals:
|
||||||
|
for command in vals['child_ids']:
|
||||||
|
# Command format is [command_code, id, values]
|
||||||
|
# Command code 0 is CREATE, 1 is UPDATE, 4 is LINK
|
||||||
|
if command[0] in [0, 1, 4]:
|
||||||
|
adding_children = True
|
||||||
|
break
|
||||||
|
|
||||||
res = super().write(vals)
|
res = super().write(vals)
|
||||||
if not self: # End recursion on empty RecordSet
|
if not self: # End recursion on empty RecordSet
|
||||||
return res
|
return res
|
||||||
|
|
@ -113,17 +123,19 @@ class Task(models.Model):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
if rec.child_ids:
|
if rec.child_ids:
|
||||||
child_vals = {}
|
child_vals = {}
|
||||||
if "site_contacts" in vals:
|
# If we're adding new children or these fields are being updated, propagate them
|
||||||
|
if "site_contacts" in vals or adding_children:
|
||||||
child_vals.update(
|
child_vals.update(
|
||||||
site_contacts=[Command.set(rec.site_contacts.ids)]
|
site_contacts=[Command.set(rec.site_contacts.ids)]
|
||||||
)
|
)
|
||||||
if "work_order_contacts" in vals:
|
if "work_order_contacts" in vals or adding_children:
|
||||||
child_vals.update(
|
child_vals.update(
|
||||||
work_order_contacts=[Command.set(rec.work_order_contacts.ids)]
|
work_order_contacts=[Command.set(rec.work_order_contacts.ids)]
|
||||||
)
|
)
|
||||||
if "partner_id" in vals:
|
if "partner_id" in vals or adding_children:
|
||||||
child_vals.update(partner_id=vals["partner_id"])
|
child_vals.update(partner_id=rec.partner_id.id)
|
||||||
rec.child_ids.write(child_vals)
|
if child_vals:
|
||||||
|
rec.child_ids.write(child_vals)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@api.depends("sale_order_id")
|
@api.depends("sale_order_id")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue