Skip to content

Commit 92a6187

Browse files
committed
[IMP] fieldservice: Set location parent to owner
Before this change, service location partners (created through inheritance) were typed "fsm_location" but did not always have a parent. When adding them within children of an existing partner, they of course did have a parent, but not the other way around: they had no parents when created, through inheritance, upon service location creation. After this change, service location partners are by default children of the service location owner partner. This is only done through defaults but not as related fields, which would break too much. Therefore, existing partners are not impacted by this change; only new ones created when creating a service location. See #1128.
1 parent 00b04db commit 92a6187

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

fieldservice/models/fsm_location.py

+3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ class FSMLocation(models.Model):
7272
@api.model_create_multi
7373
def create(self, vals_list):
7474
for vals in vals_list:
75+
# By default, create inherited partner as typed child of the location owner.
7576
vals.update({"fsm_location": True, "type": "fsm_location"})
77+
if not vals.get("partner_id"): # Don't change parent of existing partners.
78+
vals["parent_id"] = vals.get("owner_id")
7679
return super(FSMLocation, self.with_context(creating_fsm_location=True)).create(
7780
vals_list
7881
)

fieldservice/tests/test_fsm_location.py

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def test_fsm_location(self):
5454
self.assertTrue(location.fsm_location)
5555
self.assertFalse(location.fsm_person)
5656
self.assertFalse(location.is_company)
57+
self.assertEqual(location.parent_id, self.test_loc_partner)
58+
self.assertNotEqual(location.partner_id, self.test_loc_partner)
5759
self.assertEqual(location.type, "fsm_location")
5860

5961
# Test initial stage

fieldservice/wizard/fsm_wizard.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def action_convert(self):
2828
return {"type": "ir.actions.act_window_close"}
2929

3030
def _prepare_fsm_location(self, partner):
31-
return {"partner_id": partner.id, "owner_id": partner.id}
31+
return {"partner_id": partner.id, "owner_id": (partner.parent_id or partner).id}
3232

3333
def action_convert_location(self, partner):
3434
fl_model = self.env["fsm.location"]

0 commit comments

Comments
 (0)