mirror of
https://github.com/bringout/oca-ocb-hr.git
synced 2026-04-25 19:12:05 +02:00
Initial commit: Hr packages
This commit is contained in:
commit
62531cd146
2820 changed files with 1432848 additions and 0 deletions
|
|
@ -0,0 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import gamification
|
||||
from . import hr_employee
|
||||
from . import res_users
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class GamificationBadgeUser(models.Model):
|
||||
"""User having received a badge"""
|
||||
_inherit = 'gamification.badge.user'
|
||||
|
||||
employee_id = fields.Many2one('hr.employee', string='Employee', index=True)
|
||||
|
||||
@api.constrains('employee_id')
|
||||
def _check_employee_related_user(self):
|
||||
for badge_user in self:
|
||||
if badge_user.employee_id not in badge_user.user_id.\
|
||||
with_context(allowed_company_ids=self.env.user.company_ids.ids).employee_ids:
|
||||
raise ValidationError(_('The selected employee does not correspond to the selected user.'))
|
||||
|
||||
def action_open_badge(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'gamification.badge',
|
||||
'view_mode': 'form',
|
||||
'res_id': self.badge_id.id,
|
||||
}
|
||||
|
||||
class GamificationBadge(models.Model):
|
||||
_inherit = 'gamification.badge'
|
||||
|
||||
granted_employees_count = fields.Integer(compute="_compute_granted_employees_count")
|
||||
|
||||
@api.depends('owner_ids.employee_id')
|
||||
def _compute_granted_employees_count(self):
|
||||
for badge in self:
|
||||
badge.granted_employees_count = self.env['gamification.badge.user'].search_count([
|
||||
('badge_id', '=', badge.id),
|
||||
('employee_id', '!=', False)
|
||||
])
|
||||
|
||||
def get_granted_employees(self):
|
||||
employee_ids = self.mapped('owner_ids.employee_id').ids
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': 'Granted Employees',
|
||||
'view_mode': 'kanban,tree,form',
|
||||
'res_model': 'hr.employee.public',
|
||||
'domain': [('id', 'in', employee_ids)]
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class HrEmployeeBase(models.AbstractModel):
|
||||
_inherit = "hr.employee.base"
|
||||
|
||||
goal_ids = fields.One2many('gamification.goal', string='Employee HR Goals', compute='_compute_employee_goals')
|
||||
badge_ids = fields.One2many(
|
||||
'gamification.badge.user', string='Employee Badges', compute='_compute_employee_badges',
|
||||
help="All employee badges, linked to the employee either directly or through the user"
|
||||
)
|
||||
has_badges = fields.Boolean(compute='_compute_employee_badges')
|
||||
# necessary for correct dependencies of badge_ids and has_badges
|
||||
direct_badge_ids = fields.One2many(
|
||||
'gamification.badge.user', 'employee_id',
|
||||
help="Badges directly linked to the employee")
|
||||
|
||||
@api.depends('user_id.goal_ids.challenge_id.challenge_category')
|
||||
def _compute_employee_goals(self):
|
||||
for employee in self:
|
||||
employee.goal_ids = self.env['gamification.goal'].search([
|
||||
('user_id', '=', employee.user_id.id),
|
||||
('challenge_id.challenge_category', '=', 'hr'),
|
||||
])
|
||||
|
||||
@api.depends('direct_badge_ids', 'user_id.badge_ids.employee_id')
|
||||
def _compute_employee_badges(self):
|
||||
for employee in self:
|
||||
badge_ids = self.env['gamification.badge.user'].search([
|
||||
'|', ('employee_id', '=', employee.id),
|
||||
'&', ('employee_id', '=', False),
|
||||
('user_id', '=', employee.user_id.id)
|
||||
])
|
||||
employee.has_badges = bool(badge_ids)
|
||||
employee.badge_ids = badge_ids
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResUsers(models.Model):
|
||||
_inherit = 'res.users'
|
||||
|
||||
goal_ids = fields.One2many('gamification.goal', 'user_id')
|
||||
badge_ids = fields.One2many('gamification.badge.user', 'user_id')
|
||||
Loading…
Add table
Add a link
Reference in a new issue