| 1 |
|
| 2 |
from random import randint |
| 3 |
|
| 4 |
from odoo import fields, models |
| 5 |
|
| 6 |
|
| 7 |
class HrTalentPool(models.Model): |
| 8 |
_name = "hr.talent.pool" |
| 9 |
_description = "Talent Pool" |
| 10 |
_inherit = ["mail.thread"] |
| 11 |
|
| 12 |
def _get_default_color(self): |
| 13 |
return randint(1, 11) |
| 14 |
|
| 15 |
active = fields.Boolean(default=True) |
| 16 |
name = fields.Char(string="Title", required=True, translate=True) |
| 17 |
company_id = fields.Many2one( |
| 18 |
"res.company", |
| 19 |
string="Company", |
| 20 |
default=lambda self: self.env.company, |
| 21 |
tracking=True, |
| 22 |
) |
| 23 |
pool_manager = fields.Many2one( |
| 24 |
"res.users", |
| 25 |
"Pool Manager", |
| 26 |
default=lambda self: self.env.user, |
| 27 |
domain="[('share', '=', False), ('company_ids', 'in', company_id)]", |
| 28 |
tracking=True, |
| 29 |
store=True, |
| 30 |
readonly=False, |
| 31 |
) |
| 32 |
talent_ids = fields.Many2many(comodel_name="hr.applicant", string="Talent", groups="base.group_user") |
| 33 |
no_of_talents = fields.Integer( |
| 34 |
compute="_compute_talent_count", |
| 35 |
string="# Talents", |
| 36 |
help="The number of talents in this talent pool.", |
| 37 |
) |
| 38 |
description = fields.Html(string="Talent Pool Description") |
| 39 |
color = fields.Integer(string="Color", default=_get_default_color) |
| 40 |
categ_ids = fields.Many2many( |
| 41 |
comodel_name="hr.applicant.category", |
| 42 |
string="Tags", |
| 43 |
store=True, |
| 44 |
readonly=False, |
| 45 |
) |
| 46 |
|
| 47 |
def _compute_talent_count(self): |
| 48 |
talents = self.env["hr.applicant"]._read_group( |
| 49 |
domain=[("talent_pool_ids", "in", self.ids)], groupby=["talent_pool_ids"], aggregates=["__count"] |
| 50 |
) |
| 51 |
talent_data = {talent_pool.id: count for talent_pool, count in talents} |
| 52 |
for pool in self: |
| 53 |
pool.no_of_talents = talent_data.get(pool.id, 0) |
| 54 |
|
| 55 |
def action_talent_pool_add_talents(self): |
| 56 |
self.ensure_one() |
| 57 |
return { |
| 58 |
"name": self.env._("Create Talent"), |
| 59 |
"type": "ir.actions.act_window", |
| 60 |
"res_model": "hr.applicant", |
| 61 |
"views": [[False, "form"]], |
| 62 |
"context": { |
| 63 |
"default_talent_pool_ids": [self.id], |
| 64 |
}, |
| 65 |
} |