[REF] gamification: mode to adequate folders
bzr revid: mat@openerp.com-20131218085907-6501sfdif2rk4a0b
This commit is contained in:
parent
4bc29b9ffa
commit
b63950e0dc
|
@ -46,6 +46,8 @@ Both goals and badges are flexibles and can be adapted to a large range of modul
|
||||||
'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
'data/goal_base.xml',
|
'data/goal_base.xml',
|
||||||
'data/badge.xml',
|
'data/badge.xml',
|
||||||
|
'wizard/update_goal.xml',
|
||||||
|
'wizard/grant_badge.xml',
|
||||||
],
|
],
|
||||||
'test': [
|
'test': [
|
||||||
'test/goal_demo.yml'
|
'test/goal_demo.yml'
|
||||||
|
|
|
@ -24,7 +24,6 @@ from openerp.osv import fields, osv
|
||||||
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT as DF
|
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT as DF
|
||||||
from openerp.tools.translate import _
|
from openerp.tools.translate import _
|
||||||
|
|
||||||
# from templates import TemplateHelper
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -111,7 +110,6 @@ class gamification_badge(osv.Model):
|
||||||
'name': fields.char('Badge', required=True, translate=True),
|
'name': fields.char('Badge', required=True, translate=True),
|
||||||
'description': fields.text('Description'),
|
'description': fields.text('Description'),
|
||||||
'image': fields.binary("Image", help="This field holds the image used for the badge, limited to 256x256"),
|
'image': fields.binary("Image", help="This field holds the image used for the badge, limited to 256x256"),
|
||||||
# image_select: selection with a on_change to fill image with predefined picts
|
|
||||||
'rule_auth': fields.selection([
|
'rule_auth': fields.selection([
|
||||||
('everyone', 'Everyone'),
|
('everyone', 'Everyone'),
|
||||||
('users', 'A selected list of users'),
|
('users', 'A selected list of users'),
|
||||||
|
@ -261,39 +259,3 @@ class gamification_badge(osv.Model):
|
||||||
|
|
||||||
# badge.rule_auth == 'everyone' -> no check
|
# badge.rule_auth == 'everyone' -> no check
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
class grant_badge_wizard(osv.TransientModel):
|
|
||||||
""" Wizard allowing to grant a badge to a user"""
|
|
||||||
|
|
||||||
_name = 'gamification.badge.user.wizard'
|
|
||||||
_columns = {
|
|
||||||
'user_id': fields.many2one("res.users", string='User', required=True),
|
|
||||||
'badge_id': fields.many2one("gamification.badge", string='Badge', required=True),
|
|
||||||
'comment': fields.text('Comment'),
|
|
||||||
}
|
|
||||||
|
|
||||||
def action_grant_badge(self, cr, uid, ids, context=None):
|
|
||||||
"""Wizard action for sending a badge to a chosen user"""
|
|
||||||
|
|
||||||
badge_obj = self.pool.get('gamification.badge')
|
|
||||||
badge_user_obj = self.pool.get('gamification.badge.user')
|
|
||||||
|
|
||||||
for wiz in self.browse(cr, uid, ids, context=context):
|
|
||||||
if uid == wiz.user_id.id:
|
|
||||||
raise osv.except_osv(_('Warning!'), _('You can not grant a badge to yourself'))
|
|
||||||
|
|
||||||
#check if the badge granting is legitimate
|
|
||||||
if badge_obj.check_granting(cr, uid, user_from_id=uid, badge_id=wiz.badge_id.id, context=context):
|
|
||||||
#create the badge
|
|
||||||
values = {
|
|
||||||
'user_id': wiz.user_id.id,
|
|
||||||
'badge_id': wiz.badge_id.id,
|
|
||||||
'comment': wiz.comment,
|
|
||||||
}
|
|
||||||
badge_user = badge_user_obj.create(cr, uid, values, context=context)
|
|
||||||
#notify the user
|
|
||||||
result = badge_obj.send_badge(cr, uid, wiz.badge_id.id, [badge_user], user_from=uid, context=context)
|
|
||||||
|
|
||||||
return result
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
||||||
|
|
|
@ -372,27 +372,3 @@ class gamification_goal(osv.Model):
|
||||||
return action
|
return action
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class goal_manual_wizard(osv.TransientModel):
|
|
||||||
"""Wizard to update a manual goal"""
|
|
||||||
_name = 'gamification.goal.wizard'
|
|
||||||
_columns = {
|
|
||||||
'goal_id': fields.many2one("gamification.goal", string='Goal', required=True),
|
|
||||||
'current': fields.float('Current'),
|
|
||||||
}
|
|
||||||
|
|
||||||
def action_update_current(self, cr, uid, ids, context=None):
|
|
||||||
"""Wizard action for updating the current value"""
|
|
||||||
|
|
||||||
goal_obj = self.pool.get('gamification.goal')
|
|
||||||
|
|
||||||
for wiz in self.browse(cr, uid, ids, context=context):
|
|
||||||
towrite = {
|
|
||||||
'current': wiz.current,
|
|
||||||
'goal_id': wiz.goal_id.id,
|
|
||||||
}
|
|
||||||
goal_obj.write(cr, uid, [wiz.goal_id.id], towrite, context=context)
|
|
||||||
goal_obj.update(cr, uid, [wiz.goal_id.id], context=context)
|
|
||||||
return {}
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
||||||
|
|
|
@ -61,6 +61,7 @@ class res_users_gamification_group(osv.Model):
|
||||||
all_goals_info = []
|
all_goals_info = []
|
||||||
challenge_obj = self.pool.get('gamification.challenge')
|
challenge_obj = self.pool.get('gamification.challenge')
|
||||||
|
|
||||||
|
user = self.browse(cr, uid, uid, context=context)
|
||||||
challenge_ids = challenge_obj.search(cr, uid, [('user_ids', 'in', uid), ('state', '=', 'inprogress')], context=context)
|
challenge_ids = challenge_obj.search(cr, uid, [('user_ids', 'in', uid), ('state', '=', 'inprogress')], context=context)
|
||||||
for challenge in challenge_obj.browse(cr, uid, challenge_ids, context=context):
|
for challenge in challenge_obj.browse(cr, uid, challenge_ids, context=context):
|
||||||
# serialize goals info to be able to use it in javascript
|
# serialize goals info to be able to use it in javascript
|
||||||
|
@ -68,9 +69,8 @@ class res_users_gamification_group(osv.Model):
|
||||||
'id': challenge.id,
|
'id': challenge.id,
|
||||||
'name': challenge.name,
|
'name': challenge.name,
|
||||||
'visibility_mode': challenge.visibility_mode,
|
'visibility_mode': challenge.visibility_mode,
|
||||||
|
'currency': user.company_id.currency_id.id
|
||||||
}
|
}
|
||||||
user = self.browse(cr, uid, uid, context=context)
|
|
||||||
serialized_goals_info['currency'] = user.company_id.currency_id.id
|
|
||||||
|
|
||||||
if challenge.visibility_mode == 'ranking':
|
if challenge.visibility_mode == 'ranking':
|
||||||
# board report should be grouped by line for all users
|
# board report should be grouped by line for all users
|
||||||
|
|
|
@ -19,34 +19,6 @@
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|
||||||
<record id="view_badge_wizard_grant" model="ir.ui.view">
|
|
||||||
<field name="name">Grant Badge User Form</field>
|
|
||||||
<field name="model">gamification.badge.user.wizard</field>
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<form string="Grant Badge To" version="7.0">
|
|
||||||
Who would you like to reward?
|
|
||||||
<group>
|
|
||||||
<field name="user_id" nolabel="1" />
|
|
||||||
<field name="badge_id" invisible="1"/>
|
|
||||||
<field name="comment" nolabel="1" placeholder="Describe what they did and why it matters (will be public)" class="oe_no_padding" />
|
|
||||||
</group>
|
|
||||||
<footer>
|
|
||||||
<button string="Grant Badge" 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_grant_wizard"
|
|
||||||
name="Grant Badge"
|
|
||||||
target="new"
|
|
||||||
res_model="gamification.badge.user.wizard"
|
|
||||||
context="{'default_badge_id': active_id, 'badge_id': active_id}"
|
|
||||||
view_type="form" view_mode="form"
|
|
||||||
view_id="gamification.view_badge_wizard_grant" />
|
|
||||||
|
|
||||||
<record id="badge_list_view" model="ir.ui.view">
|
<record id="badge_list_view" model="ir.ui.view">
|
||||||
<field name="name">Badge List</field>
|
<field name="name">Badge List</field>
|
||||||
<field name="model">gamification.badge</field>
|
<field name="model">gamification.badge</field>
|
||||||
|
|
|
@ -278,26 +278,6 @@
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|
||||||
<record id="view_goal_wizard_update_current" model="ir.ui.view">
|
|
||||||
<field name="name">Update the current value of the Goal</field>
|
|
||||||
<field name="model">gamification.goal.wizard</field>
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<form string="Grant Badge To" version="7.0">
|
|
||||||
Set the current value you have reached for this goal
|
|
||||||
<group>
|
|
||||||
<field name="goal_id" invisible="1"/>
|
|
||||||
<field name="current" />
|
|
||||||
</group>
|
|
||||||
<footer>
|
|
||||||
<button string="Update" type="object" name="action_update_current" class="oe_highlight" /> or
|
|
||||||
<button string="Cancel" special="cancel" class="oe_link"/>
|
|
||||||
</footer>
|
|
||||||
</form>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- menus in settings - technical feature required -->
|
<!-- menus in settings - technical feature required -->
|
||||||
<menuitem id="gamification_menu" name="Gamification Tools" parent="base.menu_administration" groups="base.group_no_one" />
|
<menuitem id="gamification_menu" name="Gamification Tools" parent="base.menu_administration" groups="base.group_no_one" />
|
||||||
<menuitem id="gamification_goal_menu" parent="gamification_menu" action="goal_list_action" sequence="0"/>
|
<menuitem id="gamification_goal_menu" parent="gamification_menu" action="goal_list_action" sequence="0"/>
|
||||||
|
|
|
@ -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 update_goal
|
||||||
|
import grant_badge
|
|
@ -0,0 +1,58 @@
|
||||||
|
# -*- 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 grant_badge_wizard(osv.TransientModel):
|
||||||
|
""" Wizard allowing to grant a badge to a user"""
|
||||||
|
|
||||||
|
_name = 'gamification.badge.user.wizard'
|
||||||
|
_columns = {
|
||||||
|
'user_id': fields.many2one("res.users", string='User', required=True),
|
||||||
|
'badge_id': fields.many2one("gamification.badge", string='Badge', required=True),
|
||||||
|
'comment': fields.text('Comment'),
|
||||||
|
}
|
||||||
|
|
||||||
|
def action_grant_badge(self, cr, uid, ids, context=None):
|
||||||
|
"""Wizard action for sending a badge to a chosen user"""
|
||||||
|
|
||||||
|
badge_obj = self.pool.get('gamification.badge')
|
||||||
|
badge_user_obj = self.pool.get('gamification.badge.user')
|
||||||
|
|
||||||
|
for wiz in self.browse(cr, uid, ids, context=context):
|
||||||
|
if uid == wiz.user_id.id:
|
||||||
|
raise osv.except_osv(_('Warning!'), _('You can not grant a badge to yourself'))
|
||||||
|
|
||||||
|
#check if the badge granting is legitimate
|
||||||
|
if badge_obj.check_granting(cr, uid, user_from_id=uid, badge_id=wiz.badge_id.id, context=context):
|
||||||
|
#create the badge
|
||||||
|
values = {
|
||||||
|
'user_id': wiz.user_id.id,
|
||||||
|
'badge_id': wiz.badge_id.id,
|
||||||
|
'comment': wiz.comment,
|
||||||
|
}
|
||||||
|
badge_user = badge_user_obj.create(cr, uid, values, context=context)
|
||||||
|
#notify the user
|
||||||
|
result = badge_obj.send_badge(cr, uid, wiz.badge_id.id, [badge_user], user_from=uid, context=context)
|
||||||
|
|
||||||
|
return result
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<openerp>
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<record id="view_badge_wizard_grant" model="ir.ui.view">
|
||||||
|
<field name="name">Grant Badge User Form</field>
|
||||||
|
<field name="model">gamification.badge.user.wizard</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form string="Grant Badge To" version="7.0">
|
||||||
|
Who would you like to reward?
|
||||||
|
<group>
|
||||||
|
<field name="user_id" nolabel="1" />
|
||||||
|
<field name="badge_id" invisible="1"/>
|
||||||
|
<field name="comment" nolabel="1" placeholder="Describe what they did and why it matters (will be public)" class="oe_no_padding" />
|
||||||
|
</group>
|
||||||
|
<footer>
|
||||||
|
<button string="Grant Badge" 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_grant_wizard"
|
||||||
|
name="Grant Badge"
|
||||||
|
target="new"
|
||||||
|
res_model="gamification.badge.user.wizard"
|
||||||
|
context="{'default_badge_id': active_id, 'badge_id': active_id}"
|
||||||
|
view_type="form" view_mode="form"
|
||||||
|
view_id="gamification.view_badge_wizard_grant" />
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</openerp>
|
|
@ -0,0 +1,44 @@
|
||||||
|
# -*- 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 goal_manual_wizard(osv.TransientModel):
|
||||||
|
"""Wizard to update a manual goal"""
|
||||||
|
_name = 'gamification.goal.wizard'
|
||||||
|
_columns = {
|
||||||
|
'goal_id': fields.many2one("gamification.goal", string='Goal', required=True),
|
||||||
|
'current': fields.float('Current'),
|
||||||
|
}
|
||||||
|
|
||||||
|
def action_update_current(self, cr, uid, ids, context=None):
|
||||||
|
"""Wizard action for updating the current value"""
|
||||||
|
|
||||||
|
goal_obj = self.pool.get('gamification.goal')
|
||||||
|
|
||||||
|
for wiz in self.browse(cr, uid, ids, context=context):
|
||||||
|
towrite = {
|
||||||
|
'current': wiz.current,
|
||||||
|
'goal_id': wiz.goal_id.id,
|
||||||
|
}
|
||||||
|
goal_obj.write(cr, uid, [wiz.goal_id.id], towrite, context=context)
|
||||||
|
goal_obj.update(cr, uid, [wiz.goal_id.id], context=context)
|
||||||
|
return {}
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<openerp>
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<record id="view_goal_wizard_update_current" model="ir.ui.view">
|
||||||
|
<field name="name">Update the current value of the Goal</field>
|
||||||
|
<field name="model">gamification.goal.wizard</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form string="Grant Badge To" version="7.0">
|
||||||
|
Set the current value you have reached for this goal
|
||||||
|
<group>
|
||||||
|
<field name="goal_id" invisible="1"/>
|
||||||
|
<field name="current" />
|
||||||
|
</group>
|
||||||
|
<footer>
|
||||||
|
<button string="Update" type="object" name="action_update_current" class="oe_highlight" /> or
|
||||||
|
<button string="Cancel" special="cancel" class="oe_link"/>
|
||||||
|
</footer>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</openerp>
|
|
@ -19,4 +19,5 @@
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
import gamification
|
import models
|
||||||
|
import wizard
|
|
@ -33,7 +33,8 @@ Badge received are displayed on the user profile.
|
||||||
'data': [
|
'data': [
|
||||||
'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
'security/gamification_security.xml',
|
'security/gamification_security.xml',
|
||||||
'gamification_view.xml',
|
'views/gamification.xml',
|
||||||
|
'wizard/grant_badge.xml',
|
||||||
],
|
],
|
||||||
'js': ['static/src/js/gamification.js'],
|
'js': ['static/src/js/gamification.js'],
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
|
@ -20,7 +20,6 @@
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
from openerp.osv import fields, osv
|
from openerp.osv import fields, osv
|
||||||
from openerp.tools.translate import _
|
|
||||||
from openerp import SUPERUSER_ID
|
from openerp import SUPERUSER_ID
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,7 +53,7 @@ class gamification_badge(osv.Model):
|
||||||
"""Overwrite the message_post method to send the badge to the employee"""
|
"""Overwrite the message_post method to send the badge to the employee"""
|
||||||
# badge_user included in the send_badge method and 'badge_id' in the wizard view
|
# badge_user included in the send_badge method and 'badge_id' in the wizard view
|
||||||
if 'badge_user' in context and 'badge_id' in context:
|
if 'badge_user' in context and 'badge_id' in context:
|
||||||
badge = self.browse(cr, uid, context['badge_id'], context=context)
|
# badge = self.browse(cr, uid, context['badge_id'], context=context)
|
||||||
badge_user = context['badge_user']
|
badge_user = context['badge_user']
|
||||||
if badge_user.employee_id:
|
if badge_user.employee_id:
|
||||||
return self.pool.get('hr.employee').message_post(cr, SUPERUSER_ID,
|
return self.pool.get('hr.employee').message_post(cr, SUPERUSER_ID,
|
||||||
|
@ -80,48 +79,6 @@ class gamification_badge(osv.Model):
|
||||||
'domain': [('id', 'in', employee_ids)]
|
'domain': [('id', 'in', employee_ids)]
|
||||||
}
|
}
|
||||||
|
|
||||||
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_obj = self.pool.get('gamification.badge')
|
|
||||||
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'))
|
|
||||||
|
|
||||||
if badge_obj.check_granting(cr, uid,
|
|
||||||
user_from_id=uid,
|
|
||||||
badge_id=wiz.badge_id.id,
|
|
||||||
context=context):
|
|
||||||
|
|
||||||
values = {
|
|
||||||
'user_id': wiz.user_id.id,
|
|
||||||
'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_obj.send_badge(cr, uid, wiz.badge_id.id, [badge_user], user_from=uid, context=context)
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
class hr_employee(osv.osv):
|
class hr_employee(osv.osv):
|
||||||
_name = "hr.employee"
|
_name = "hr.employee"
|
|
@ -2,48 +2,6 @@
|
||||||
<openerp>
|
<openerp>
|
||||||
<data>
|
<data>
|
||||||
|
|
||||||
<!-- Wizard -->
|
|
||||||
|
|
||||||
<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"/>
|
|
||||||
|
|
||||||
<record id="hr_badge_form_view" model="ir.ui.view">
|
<record id="hr_badge_form_view" model="ir.ui.view">
|
||||||
<field name="name">Badge Form</field>
|
<field name="name">Badge Form</field>
|
||||||
<field name="model">gamification.badge</field>
|
<field name="model">gamification.badge</field>
|
|
@ -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
|
|
@ -0,0 +1,65 @@
|
||||||
|
# -*- 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_obj = self.pool.get('gamification.badge')
|
||||||
|
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'))
|
||||||
|
|
||||||
|
if badge_obj.check_granting(cr, uid,
|
||||||
|
user_from_id=uid,
|
||||||
|
badge_id=wiz.badge_id.id,
|
||||||
|
context=context):
|
||||||
|
|
||||||
|
values = {
|
||||||
|
'user_id': wiz.user_id.id,
|
||||||
|
'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_obj.send_badge(cr, uid, wiz.badge_id.id, [badge_user], user_from=uid, context=context)
|
||||||
|
return result
|
|
@ -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>
|
Loading…
Reference in New Issue