2013-03-12 15:27:12 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
2013-12-17 10:48:13 +00:00
|
|
|
# Copyright (C) 2013 OpenERP SA (<http://www.openerp.com>)
|
2013-03-12 15:27:12 +00:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
from openerp.osv import fields, osv
|
2013-04-12 08:54:52 +00:00
|
|
|
from openerp import SUPERUSER_ID
|
2013-03-12 15:27:12 +00:00
|
|
|
|
|
|
|
|
2013-03-12 16:15:56 +00:00
|
|
|
class hr_gamification_badge_user(osv.Model):
|
2013-03-12 15:27:12 +00:00
|
|
|
"""User having received a badge"""
|
|
|
|
|
|
|
|
_name = 'gamification.badge.user'
|
|
|
|
_inherit = ['gamification.badge.user']
|
|
|
|
|
|
|
|
_columns = {
|
|
|
|
'employee_id': fields.many2one("hr.employee", string='Employee'),
|
|
|
|
}
|
|
|
|
|
|
|
|
def _check_employee_related_user(self, cr, uid, ids, context=None):
|
|
|
|
for badge_user in self.browse(cr, uid, ids, context=context):
|
|
|
|
if badge_user.user_id and badge_user.employee_id:
|
|
|
|
if badge_user.employee_id not in badge_user.user_id.employee_ids:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
_constraints = [
|
|
|
|
(_check_employee_related_user, "The selected employee does not correspond to the selected user.", ['employee_id']),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2013-04-11 13:24:38 +00:00
|
|
|
class gamification_badge(osv.Model):
|
2013-03-12 16:15:56 +00:00
|
|
|
_name = 'gamification.badge'
|
2013-04-11 13:24:38 +00:00
|
|
|
_inherit = ['gamification.badge']
|
2013-03-12 16:15:56 +00:00
|
|
|
|
2013-04-12 13:36:06 +00:00
|
|
|
def get_granted_employees(self, cr, uid, badge_ids, context=None):
|
|
|
|
if context is None:
|
|
|
|
context = {}
|
|
|
|
|
|
|
|
employee_ids = []
|
|
|
|
badge_user_ids = self.pool.get('gamification.badge.user').search(cr, uid, [('badge_id', 'in', badge_ids), ('employee_id', '!=', False)], context=context)
|
|
|
|
for badge_user in self.pool.get('gamification.badge.user').browse(cr, uid, badge_user_ids, context):
|
|
|
|
employee_ids.append(badge_user.employee_id.id)
|
|
|
|
# remove duplicates
|
|
|
|
employee_ids = list(set(employee_ids))
|
|
|
|
return {
|
|
|
|
'type': 'ir.actions.act_window',
|
|
|
|
'name': 'Granted Employees',
|
|
|
|
'view_mode': 'kanban,tree,form',
|
|
|
|
'view_type': 'form',
|
|
|
|
'res_model': 'hr.employee',
|
|
|
|
'domain': [('id', 'in', employee_ids)]
|
|
|
|
}
|
2013-03-12 16:15:56 +00:00
|
|
|
|
2013-03-13 15:11:30 +00:00
|
|
|
|
|
|
|
class hr_employee(osv.osv):
|
|
|
|
_name = "hr.employee"
|
|
|
|
_inherit = "hr.employee"
|
|
|
|
|
2013-04-16 12:45:58 +00:00
|
|
|
def _get_employee_goals(self, cr, uid, ids, field_name, arg, context=None):
|
|
|
|
"""Return the list of goals assigned to the employee"""
|
|
|
|
res = {}
|
|
|
|
for employee in self.browse(cr, uid, ids, context=context):
|
2013-12-17 16:15:41 +00:00
|
|
|
res[employee.id] = self.pool.get('gamification.goal').search(cr,uid,[('user_id', '=', employee.user_id.id), ('challenge_id.category', '=', 'hr')], context=context)
|
2013-04-16 12:45:58 +00:00
|
|
|
return res
|
|
|
|
|
2013-03-13 15:11:30 +00:00
|
|
|
def _get_employee_badges(self, cr, uid, ids, field_name, arg, context=None):
|
2013-03-18 12:48:14 +00:00
|
|
|
"""Return the list of badge_users assigned to the employee"""
|
2013-03-13 15:11:30 +00:00
|
|
|
res = {}
|
|
|
|
for employee in self.browse(cr, uid, ids, context=context):
|
2013-04-19 15:48:17 +00:00
|
|
|
res[employee.id] = self.pool.get('gamification.badge.user').search(cr, uid, [
|
|
|
|
'|',
|
|
|
|
('employee_id', '=', employee.id),
|
|
|
|
'&',
|
|
|
|
('employee_id', '=', False),
|
|
|
|
('user_id', '=', employee.user_id.id)
|
|
|
|
], context=context)
|
2013-03-13 15:11:30 +00:00
|
|
|
return res
|
|
|
|
|
2013-04-10 11:50:23 +00:00
|
|
|
def _has_badges(self, cr, uid, ids, field_name, arg, context=None):
|
|
|
|
"""Return the list of badge_users assigned to the employee"""
|
|
|
|
res = {}
|
|
|
|
for employee in self.browse(cr, uid, ids, context=context):
|
2013-04-19 15:05:23 +00:00
|
|
|
employee_badge_ids = self.pool.get('gamification.badge.user').search(cr, uid, [
|
|
|
|
'|',
|
|
|
|
('employee_id', '=', employee.id),
|
|
|
|
'&',
|
|
|
|
('employee_id', '=', False),
|
|
|
|
('user_id', '=', employee.user_id.id)
|
|
|
|
], context=context)
|
|
|
|
res[employee.id] = len(employee_badge_ids) > 0
|
2013-04-10 11:50:23 +00:00
|
|
|
return res
|
|
|
|
|
2013-03-13 15:11:30 +00:00
|
|
|
_columns = {
|
2013-04-16 12:45:58 +00:00
|
|
|
'goal_ids': fields.function(_get_employee_goals, type="one2many", obj='gamification.goal', string="Employee HR Goals"),
|
2013-12-18 14:03:33 +00:00
|
|
|
'badge_ids': fields.function(_get_employee_badges, type="one2many", obj='gamification.badge.user', string="Employee Badges"),
|
2013-04-10 11:50:23 +00:00
|
|
|
'has_badges': fields.function(_has_badges, type="boolean", string="Has Badges"),
|
2013-03-13 15:11:30 +00:00
|
|
|
}
|