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 0410172 commit 2dda2db
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion fieldservice_recurring/models/fsm_recurring.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,29 @@ 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,
required=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
# 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

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

0 comments on commit 2dda2db

Please sign in to comment.