Skip to content

Commit

Permalink
[IMP] fieldservice_recurring: populate fsm.recurring.person_id from t…
Browse files Browse the repository at this point in the history
…he res.territory
  • Loading branch information
ivantodorovich committed Dec 3, 2024
1 parent 85c144b commit 4467947
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion fieldservice_recurring/models/fsm_recurring.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,28 @@ def _default_team_id(self):
tracking=True,
)
person_id = fields.Many2one(
"fsm.person", string="Assigned To", index=True, tracking=True
"fsm.person",
string="Assigned To",
compute="_compute_person_id",
precompute=True,
store=True,
readonly=False,
index=True,
tracking=True,
)
equipment_ids = fields.Many2many("fsm.equipment")

@api.depends("location_id")
def _compute_person_id(self):
"""Compute the person from the location's territory"""
for rec in self:
# If the person is one of the territory's workers, keep it.
if rec.person_id in rec.location_id.territory_id.person_ids:
continue

Check warning on line 98 in fieldservice_recurring/models/fsm_recurring.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_recurring/models/fsm_recurring.py#L98

Added line #L98 was not covered by tests
# If the territory has a primary assignment, use it.
if rec.location_id.territory_id.person_id:
rec.person_id = rec.location_id.territory_id.person_id

Check warning on line 101 in fieldservice_recurring/models/fsm_recurring.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_recurring/models/fsm_recurring.py#L101

Added line #L101 was not covered by tests

@api.depends("fsm_order_ids")
def _compute_order_count(self):
data = self.env["fsm.order"].read_group(
Expand Down

0 comments on commit 4467947

Please sign in to comment.