Skip to content

Commit

Permalink
[IMP] fieldservice_skill: Skill views
Browse files Browse the repository at this point in the history
Adapted FSM Person Skills to mimic Odoo v13 behavior of Employee Skills.
- Skill progress level instead of priority
- Updated views on FSM Person form
  • Loading branch information
brian10048 committed Oct 29, 2020
1 parent ab7c98e commit 5482402
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 46 deletions.
28 changes: 24 additions & 4 deletions fieldservice_skill/models/fsm_person_skill.py
Original file line number Diff line number Diff line change
@@ -1,21 +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).

from odoo import fields, models
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class FSMPersonSkill(models.Model):
_name = "fsm.person.skill"
_rec_name = "skill_id"
_description = "Field Service Worker Skill"

LEVEL = [("0", "Junior"), ("1", "Intermediate"), ("2", "Senior"), ("3", "Expert")]

person_id = fields.Many2one(
"fsm.person", string="Field Service Worker", required=True
)
skill_id = fields.Many2one("hr.skill", string="Skill", required=True)
level = fields.Selection(LEVEL, string="Level", default=LEVEL[0][0])
skill_level_id = fields.Many2one("hr.skill.level", required=True)
skill_type_id = fields.Many2one("hr.skill.type", required=True)
level_progress = fields.Integer(related="skill_level_id.level_progress")

_sql_constraints = [
(
Expand All @@ -24,3 +26,21 @@ class FSMPersonSkill(models.Model):
"This person already has that skill!",
),
]

@api.constrains("skill_id", "skill_type_id")
def _check_skill_type(self):
for record in self:
if record.skill_id not in record.skill_type_id.skill_ids:
raise ValidationError(
_("The skill %s and skill type %s doesn't match")
% (record.skill_id.name, record.skill_type_id.name)
)

@api.constrains("skill_type_id", "skill_level_id")
def _check_skill_level(self):
for record in self:
if record.skill_level_id not in record.skill_type_id.skill_level_ids:
raise ValidationError(
_("The skill level %s is not valid for skill type: %s ")
% (record.skill_level_id.name, record.skill_type_id.name)
)
26 changes: 20 additions & 6 deletions fieldservice_skill/views/fsm_person.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,26 @@
<field name="arch" type="xml">
<page name="contact" position="before">
<page string="Skills">
<field name="skill_ids" nolabel="1">
<tree editable="bottom">
<field name="skill_id" options="{'limit':1}" />
<field name="level" widget="priority" />
</tree>
</field>
<div class="row">
<div
class="o_hr_skills_group o_group_skills col-lg-5 d-flex flex-column"
>
<separator string="Skills" />
<field
mode="tree"
nolabel="1"
name="skill_ids"
widget="hr_skills"
>
<tree>
<field name="skill_type_id" invisible="1" />
<field name="skill_id" />
<field name="skill_level_id" />
<field name="level_progress" widget="progressbar" />
</tree>
</field>
</div>
</div>
</page>
</page>
</field>
Expand Down
52 changes: 16 additions & 36 deletions fieldservice_skill/views/fsm_person_skill.xml
Original file line number Diff line number Diff line change
@@ -1,53 +1,33 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<!-- Field Service Skill -->
<record id="fsm_person_skill_tree" model="ir.ui.view">
<field name="name">Skills</field>
<field name="model">fsm.person.skill</field>
<field name="arch" type="xml">
<tree string="Worker Skills">
<field name="person_id" />
<field name="skill_id" />
<field name="level" widget="priority" />
</tree>
</field>
</record>
<record id="fsm_person_skill_form" model="ir.ui.view">
<field name="name">fsm.person.skill.form</field>
<field name="model">fsm.person.skill</field>
<field name="arch" type="xml">
<form string="Worker Skill">
<form string="Worker Skills">
<sheet>
<group>
<group>
<field name="person_id" />
<field name="skill_id" />
<field name="level" widget="priority" />
<field name="skill_type_id" />
<field
name="skill_id"
domain="[('skill_type_id', '=', skill_type_id)]"
options="{'no_create_edit': True}"
/>
</group>
<group>
<field
name="skill_level_id"
domain="[('skill_type_id', '=', skill_type_id)]"
/>
<field name="level_progress" widget="progressbar" />
</group>
<group />
</group>
</sheet>
</form>
</field>
</record>
<record id="action_fsm_person_skill" model="ir.actions.act_window">
<field name="name">Worker Skills</field>
<field name="res_model">fsm.person.skill</field>
<field name="view_id" ref="fsm_person_skill_tree" />
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Create a worker skill.
</p>
</field>
</record>
<menuitem
id="menu_fsm_person_skill"
name="Worker Skills"
action="action_fsm_person_skill"
parent="fieldservice.data"
sequence="80"
/>
<!-- Reporting -->
<record id="view_fsm_person_skill_graph" model="ir.ui.view">
<field name="name">fsm.person.skill.graph</field>
Expand All @@ -56,7 +36,7 @@
<graph string="Worker Skills" type="bar">
<field name="person_id" type="row" />
<field name="skill_id" type="row" />
<field name="level" type="row" />
<field name="level_progress" type="row" />
</graph>
</field>
</record>
Expand All @@ -67,7 +47,7 @@
<pivot string="Worker Skills" display_quantity="true">
<field name="person_id" type="row" />
<field name="skill_id" type="row" />
<field name="level" type="row" />
<field name="level_progress" type="row" />
</pivot>
</field>
</record>
Expand Down

0 comments on commit 5482402

Please sign in to comment.