Skip to content

Commit

Permalink
[IMP] fieldservice_skill: Filter order workers
Browse files Browse the repository at this point in the history
  • Loading branch information
brian10048 committed Oct 30, 2020
1 parent 0a2a080 commit 8a65e8c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
30 changes: 30 additions & 0 deletions fieldservice_skill/models/fsm_order.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# Copyright (C) 2018, Open Source Integrators
# Copyright (C) 2020, Brian McMaster
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging

from odoo import api, fields, models

_logger = logging.getLogger(__name__)


class FSMOrder(models.Model):
_inherit = "fsm.order"

skill_ids = fields.Many2many("hr.skill", string="Required Skills")
skill_worker_ids = fields.Many2many(
"fsm.person",
"fsm_order_skill_workers_rel",
compute="_compute_skill_workers",
help="Available workers based on skill requirements",
)

@api.onchange("category_ids")
def _onchange_category_ids(self):
Expand All @@ -22,3 +32,23 @@ def _onchange_template_id(self):
if self.template_id:
super(FSMOrder, self)._onchange_template_id()
self.skill_ids = self.template_id.skill_ids

@api.depends("skill_ids")
@api.onchange("skill_ids")
def _compute_skill_workers(self):
worker_ids = []
req_skills = self.skill_ids.ids
if not self.skill_ids:
worker_ids = self.env["fsm.person"].search([]).ids
else:
FPS = self.env["fsm.person.skill"]
potential_workers = FPS.search(
[("skill_id", "in", self.skill_ids.ids)]
).mapped("person_id")
for w in potential_workers:
worker_skills = FPS.search([("person_id", "=", w.id)]).mapped(
"skill_id"
)
if set(worker_skills.ids) >= set(req_skills):
worker_ids.append(w.id)
self.skill_worker_ids = [(6, 0, worker_ids)]
6 changes: 6 additions & 0 deletions fieldservice_skill/views/fsm_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
widget="many2many_tags"
options="{'color_field': 'color'}"
/>
<field name="skill_worker_ids" invisible="1" />
</field>
<field name="person_id" position="attributes">
<attribute name="domain">
[("id", "in", skill_worker_ids)]
</attribute>
</field>
</field>
</record>
Expand Down

0 comments on commit 8a65e8c

Please sign in to comment.