Skip to content

Commit

Permalink
Make employees easily searchable
Browse files Browse the repository at this point in the history
  • Loading branch information
fcayre committed Oct 14, 2024
1 parent 82977b5 commit fc76481
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
16 changes: 16 additions & 0 deletions customer_team_manager/models/employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ class Employee(models.Model):
firstname = fields.Char(
string="First name",
required=True,
index=True,
)

lastname = fields.Char(
string="Last name",
required=True,
index=True,
)

name = fields.Char(
compute="_compute_name",
store=True,
)

email = fields.Char(
Expand All @@ -41,6 +48,7 @@ class Employee(models.Model):
"customer_team_manager.team",
index=True,
ondelete="restrict",
domain="[('company', '=', company)]",
)

active = fields.Boolean(default=True)
Expand Down Expand Up @@ -73,6 +81,14 @@ class Employee(models.Model):
required=True,
)

@api.depends("firstname", "lastname")
def _compute_name(self):
for record in self:
record.name = self.env["res.partner"]._get_computed_name(
record.lastname,
record.firstname,
)

def _compute_default_image(self):
img_path = get_module_resource("base", "static/img", "avatar.png")
with open(img_path, "rb") as f:
Expand Down
21 changes: 21 additions & 0 deletions customer_team_manager/views/customer_team_manager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,27 @@
</field>
</record>

<record id="view_employee_search" model="ir.ui.view">
<field name="name">customer_team_manager.employee.search</field>
<field name="model">customer_team_manager.employee</field>
<field name="arch" type="xml">
<search string="Employees">
<field
name="name"
filter_domain="['|', '|', ('name', 'ilike', self), ('email', 'ilike', self)]"/>
<field name="team"/>
<field name="company"/>
<field name="roles"/>
<group expand="0" string="Group By">
<filter string="Company" name="company"
context="{'group_by': 'company'}"/>
<filter string="Team" name="team"
context="{'group_by': 'team'}"/>
</group>
</search>
</field>
</record>

<record id="view_team_form" model="ir.ui.view">
<field name="name">customer_team_manager.team.form</field>
<field name="model">customer_team_manager.team</field>
Expand Down

0 comments on commit fc76481

Please sign in to comment.