diff options
| author | Thibault Delavallée <tde@openerp.com> | 2014-01-06 14:57:00 +0100 |
|---|---|---|
| committer | Thibault Delavallée <tde@openerp.com> | 2014-01-06 14:57:00 +0100 |
| commit | 49c0b7a82003a889edc19cb189d0d6d0ebda2c5f (patch) | |
| tree | d24c9d3fe3baad3ba06f11d4bf334e2504fb6092 /addons/hr_gamification | |
| parent | c4c268c902a134efdf0f097053c9b28d6b14417c (diff) | |
| parent | ced63415b7319e12fb9d31a3e370850278f697c1 (diff) | |
[MERGE] Sync with trunk
bzr revid: tde@openerp.com-20140106135700-rt0g44w5xmpbtxiu
Diffstat (limited to 'addons/hr_gamification')
| -rw-r--r-- | addons/hr_gamification/__init__.py | 23 | ||||
| -rw-r--r-- | addons/hr_gamification/__openerp__.py | 40 | ||||
| -rw-r--r-- | addons/hr_gamification/models/__init__.py | 22 | ||||
| -rw-r--r-- | addons/hr_gamification/models/gamification.py | 113 | ||||
| -rw-r--r-- | addons/hr_gamification/security/gamification_security.xml | 17 | ||||
| -rw-r--r-- | addons/hr_gamification/security/ir.model.access.csv | 5 | ||||
| -rw-r--r-- | addons/hr_gamification/static/src/js/gamification.js | 19 | ||||
| -rw-r--r-- | addons/hr_gamification/views/gamification.xml | 104 | ||||
| -rw-r--r-- | addons/hr_gamification/wizard/__init__.py | 22 | ||||
| -rw-r--r-- | addons/hr_gamification/wizard/grant_badge.py | 60 | ||||
| -rw-r--r-- | addons/hr_gamification/wizard/grant_badge.xml | 46 |
11 files changed, 471 insertions, 0 deletions
diff --git a/addons/hr_gamification/__init__.py b/addons/hr_gamification/__init__.py new file mode 100644 index 00000000000..1896704c7fc --- /dev/null +++ b/addons/hr_gamification/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013 OpenERP SA (<http://openerp.com>). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +import models +import wizard
\ No newline at end of file diff --git a/addons/hr_gamification/__openerp__.py b/addons/hr_gamification/__openerp__.py new file mode 100644 index 00000000000..c75a4454437 --- /dev/null +++ b/addons/hr_gamification/__openerp__.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013 OpenERP SA (<http://openerp.com>). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## +{ + 'name': 'HR Gamification', + 'version': '1.0', + 'author': 'OpenERP SA', + 'category': 'hidden', + 'depends': ['gamification', 'hr'], + 'description': """Use the HR ressources for the gamification process. + +The HR officer can now manage challenges and badges. +This allow the user to send badges to employees instead of simple users. +Badge received are displayed on the user profile. +""", + 'data': [ + 'security/ir.model.access.csv', + 'security/gamification_security.xml', + 'wizard/grant_badge.xml', + 'views/gamification.xml', + ], + 'js': ['static/src/js/gamification.js'], +} diff --git a/addons/hr_gamification/models/__init__.py b/addons/hr_gamification/models/__init__.py new file mode 100644 index 00000000000..51cf01dfa09 --- /dev/null +++ b/addons/hr_gamification/models/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013 OpenERP SA (<http://openerp.com>). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +import gamification diff --git a/addons/hr_gamification/models/gamification.py b/addons/hr_gamification/models/gamification.py new file mode 100644 index 00000000000..b2aa9039cb1 --- /dev/null +++ b/addons/hr_gamification/models/gamification.py @@ -0,0 +1,113 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013 OpenERP SA (<http://www.openerp.com>) +# +# 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 + + +class hr_gamification_badge_user(osv.Model): + """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']), + ] + + +class gamification_badge(osv.Model): + _name = 'gamification.badge' + _inherit = ['gamification.badge'] + + 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)] + } + + +class hr_employee(osv.osv): + _name = "hr.employee" + _inherit = "hr.employee" + + 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): + res[employee.id] = self.pool.get('gamification.goal').search(cr,uid,[('user_id', '=', employee.user_id.id), ('challenge_id.category', '=', 'hr')], context=context) + return res + + def _get_employee_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): + 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) + return res + + 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): + 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 + return res + + _columns = { + 'goal_ids': fields.function(_get_employee_goals, type="one2many", obj='gamification.goal', string="Employee HR Goals"), + 'badge_ids': fields.function(_get_employee_badges, type="one2many", obj='gamification.badge.user', string="Employee Badges"), + 'has_badges': fields.function(_has_badges, type="boolean", string="Has Badges"), + } diff --git a/addons/hr_gamification/security/gamification_security.xml b/addons/hr_gamification/security/gamification_security.xml new file mode 100644 index 00000000000..e0f9a6cf918 --- /dev/null +++ b/addons/hr_gamification/security/gamification_security.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" ?> +<openerp> + <data noupdate="1"> + + <record id="goal_officer_visibility" model="ir.rule"> + <field name="name">HR Officer can see any goal</field> + <field name="model_id" ref="gamification.model_gamification_goal"/> + <field name="groups" eval="[(4, ref('base.group_hr_user'))]"/> + <field name="perm_read" eval="True"/> + <field name="perm_write" eval="True"/> + <field name="perm_create" eval="False"/> + <field name="perm_unlink" eval="False"/> + <field name="domain_force">[(1, '=', 1)]</field> + </record> + + </data> +</openerp> diff --git a/addons/hr_gamification/security/ir.model.access.csv b/addons/hr_gamification/security/ir.model.access.csv new file mode 100644 index 00000000000..b89db7cd104 --- /dev/null +++ b/addons/hr_gamification/security/ir.model.access.csv @@ -0,0 +1,5 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +challenge_officer,"Challenge Officer",gamification.model_gamification_challenge,base.group_hr_user,1,1,1,1 +challenge_line_officer,"Challenge Line Officer",gamification.model_gamification_challenge_line,base.group_hr_user,1,1,1,1 +badge_officer,"Badge Officer",gamification.model_gamification_badge,base.group_hr_user,1,1,1,1 +badge_user_officer,"Badge-user Officer",gamification.model_gamification_badge_user,base.group_hr_user,1,1,1,1
\ No newline at end of file diff --git a/addons/hr_gamification/static/src/js/gamification.js b/addons/hr_gamification/static/src/js/gamification.js new file mode 100644 index 00000000000..a9126464a10 --- /dev/null +++ b/addons/hr_gamification/static/src/js/gamification.js @@ -0,0 +1,19 @@ +openerp.hr_gamification = function(instance) { + instance.web_kanban.KanbanRecord.include({ + on_card_clicked: function() { + if (this.view.dataset.model === 'gamification.badge.user') { + var action = { + type: 'ir.actions.act_window', + res_model: 'gamification.badge', + view_mode: 'form', + view_type: 'form,kanban,tree', + views: [[false, 'form']], + res_id: this.record.badge_id.raw_value[0] + }; + this.do_action(action); + } else { + this._super.apply(this, arguments); + } + } + }); +}; diff --git a/addons/hr_gamification/views/gamification.xml b/addons/hr_gamification/views/gamification.xml new file mode 100644 index 00000000000..e2d45948b95 --- /dev/null +++ b/addons/hr_gamification/views/gamification.xml @@ -0,0 +1,104 @@ +<?xml version="1.0" encoding="UTF-8"?> +<openerp> + <data> + + <record id="hr_badge_form_view" model="ir.ui.view"> + <field name="name">Badge Form</field> + <field name="model">gamification.badge</field> + <field name="inherit_id" ref="gamification.badge_form_view"/> + <field name="arch" type="xml"> + <xpath expr="//div[@class='oe_right oe_button_box']" position="inside"> + <button string="Granted Employees" type="object" name="get_granted_employees" attrs="{'invisible': [('stat_count','=',0)]}" /> + </xpath> + </field> + </record> + + <!-- HR Employee --> + + <record id="hr_hr_employee_view_form" model="ir.ui.view"> + <field name="name">hr.hr.employee.view.form</field> + <field name="model">hr.employee</field> + <field name="inherit_id" ref="hr.view_employee_form"/> + <field name="arch" type="xml"> + + <xpath expr="//page[@string='Public Information']" position="before"> + <page string="Received Badges" attrs="{'invisible': [('user_id', '=', False)]}"> + <field name="has_badges" invisible="1"/> + <button string="Grant a Badge" type="action" name="%(action_reward_wizard)d"/> to reward this employee for a good action + <div class="oe_view_nocontent" attrs="{'invisible': [('has_badges', '=', True)]}"> + <p class="oe_view_nocontent_create"> + Click to grant this employee his first badge + </p><p class="oe_grey"> + Badges are rewards of good work. Give them to people you believe deserve it. + </p> + </div> + <field name="badge_ids" widget="many2many_kanban" /> + </page> + </xpath> + <xpath expr="//page[@string='Public Information']" position="after"> + <page string="Goals"> + <field name="goal_ids" widget="many2many_kanban" /> + </page> + </xpath> + + </field> + </record> + + + <record id="goals_menu_groupby_action2" model="ir.actions.act_window"> + <field name="res_model">gamification.goal</field> + <field name="view_type">form</field> + <field name="name">Goals History</field> + <field name="view_mode">tree,kanban</field> + <field name="context">{'search_default_group_by_user': True, 'search_default_group_by_type': True}</field> + <field name="domain">[('challenge_id.category', '=', 'hr')]</field> + <field name="help" type="html"> + <p class="oe_view_nocontent_create"> + Click to create a goal. + </p> + <p> + A goal is defined by a user and a goal type. + Goals can be created automatically by using challenges. + </p> + </field> + </record> + + + <record id="challenge_list_action2" model="ir.actions.act_window"> + <field name="name">Challenges</field> + <field name="res_model">gamification.challenge</field> + <field name="view_mode">kanban,tree,form</field> + <field name="domain">[('category', '=', 'hr')]</field> + <field name="context">{'search_default_inprogress':True, 'default_inprogress':True}</field> + <field name="help" type="html"> + <p class="oe_view_nocontent_create"> + Click to create a challenge. + </p> + <p> + Assign a list of goals to chosen users to evaluate them. + The challenge can use a period (weekly, monthly...) for automatic creation of goals. + The goals are created for the specified users or member of the group. + </p> + </field> + </record> + <record id="challenge_list_action2_view1" model="ir.actions.act_window.view"> + <field eval="1" name="sequence"/> + <field name="view_mode">kanban</field> + <field name="act_window_id" ref="challenge_list_action2"/> + <field name="view_id" ref="gamification.view_challenge_kanban"/> + </record> + <record id="challenge_list_action2_view2" model="ir.actions.act_window.view"> + <field eval="10" name="sequence"/> + <field name="view_mode">form</field> + <field name="act_window_id" ref="challenge_list_action2"/> + <field name="view_id" ref="gamification.challenge_form_view"/> + </record> + + <menuitem id="menu_hr_gamification" parent="hr.menu_hr_root" name="Engagement" sequence="40"/> + + <menuitem id="gamification_badge_menu_hr" parent="menu_hr_gamification" action="gamification.badge_list_action" /> + <menuitem id="gamification_challenge_menu_hr" parent="menu_hr_gamification" action="challenge_list_action2" groups="base.group_hr_user"/> + <menuitem id="gamification_goal_menu_hr" parent="menu_hr_gamification" action="goals_menu_groupby_action2" groups="base.group_hr_user"/> + + </data> +</openerp> diff --git a/addons/hr_gamification/wizard/__init__.py b/addons/hr_gamification/wizard/__init__.py new file mode 100644 index 00000000000..bb521f011bb --- /dev/null +++ b/addons/hr_gamification/wizard/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013 OpenERP SA (<http://openerp.com>). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +import grant_badge
\ No newline at end of file diff --git a/addons/hr_gamification/wizard/grant_badge.py b/addons/hr_gamification/wizard/grant_badge.py new file mode 100644 index 00000000000..b8a51044d4c --- /dev/null +++ b/addons/hr_gamification/wizard/grant_badge.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013 OpenERP SA (<http://www.openerp.com>) +# +# 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 +from openerp.tools.translate import _ + +class hr_grant_badge_wizard(osv.TransientModel): + _name = 'gamification.badge.user.wizard' + _inherit = ['gamification.badge.user.wizard'] + + _columns = { + 'employee_id': fields.many2one("hr.employee", string='Employee', required=True), + 'user_id': fields.related("employee_id", "user_id", + type="many2one", relation="res.users", + store=True, string='User') + } + + def action_grant_badge(self, cr, uid, ids, context=None): + """Wizard action for sending a badge to a chosen employee""" + if context is None: + context = {} + + badge_user_obj = self.pool.get('gamification.badge.user') + + for wiz in self.browse(cr, uid, ids, context=context): + if not wiz.user_id: + raise osv.except_osv(_('Warning!'), _('You can send badges only to employees linked to a user.')) + + if uid == wiz.user_id.id: + raise osv.except_osv(_('Warning!'), _('You can not send a badge to yourself')) + + values = { + 'user_id': wiz.user_id.id, + 'sender_id': uid, + 'badge_id': wiz.badge_id.id, + 'employee_id': wiz.employee_id.id, + 'comment': wiz.comment, + } + + badge_user = badge_user_obj.create(cr, uid, values, context=context) + result = badge_user_obj._send_badge(cr, uid, [badge_user], context=context) + return result
\ No newline at end of file diff --git a/addons/hr_gamification/wizard/grant_badge.xml b/addons/hr_gamification/wizard/grant_badge.xml new file mode 100644 index 00000000000..6dcf2d2e7c4 --- /dev/null +++ b/addons/hr_gamification/wizard/grant_badge.xml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8"?> +<openerp> + <data> + + <record id="view_badge_wizard_grant_employee" model="ir.ui.view"> + <field name="name">Grant Badge Employee Form</field> + <field name="model">gamification.badge.user.wizard</field> + <field name="inherit_id" ref="gamification.view_badge_wizard_grant" /> + <field name="arch" type="xml"> + <data> + <xpath expr="//field[@name='user_id']" position="replace"> + <field name="employee_id" nolabel="1" domain="[('user_id', '!=', False),('user_id', '!=', uid)]" /> + </xpath> + </data> + </field> + </record> + + <record id="view_badge_wizard_reward" model="ir.ui.view"> + <field name="name">Reward Employee Badge Form</field> + <field name="model">gamification.badge.user.wizard</field> + <field name="arch" type="xml"> + <form string="Reward Employee with" version="7.0"> + What are you thank for? + <group> + <field name="employee_id" invisible="1" /> + <field name="badge_id" nolabel="1" colspan="4" /> + <field name="comment" nolabel="1" placeholder="Describe what they did and why it matters (will be public)" /> + </group> + <footer> + <button string="Reward Employee" type="object" name="action_grant_badge" class="oe_highlight" /> or + <button string="Cancel" special="cancel" class="oe_link"/> + </footer> + </form> + </field> + </record> + + <act_window domain="[]" id="action_reward_wizard" + name="Reward Employee" + target="new" + res_model="gamification.badge.user.wizard" + context="{'default_employee_id': active_id, 'employee_id': active_id}" + view_type="form" view_mode="form" + view_id="view_badge_wizard_reward"/> + + </data> +</openerp> |
