2013-02-14 08:20:38 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2013 Tiny SPRL (<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/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
from openerp.osv import fields, osv
|
|
|
|
|
|
|
|
from datetime import date
|
|
|
|
|
2013-02-15 14:16:51 +00:00
|
|
|
GAMIFICATION_GOAL_STATE = [
|
2013-02-14 17:07:36 +00:00
|
|
|
('inprogress','In progress'),
|
|
|
|
('reached','Reached'),
|
|
|
|
('failed','Failed'),
|
|
|
|
]
|
|
|
|
|
2013-02-15 14:16:51 +00:00
|
|
|
GAMIFICATION_PLAN_STATE = [
|
2013-02-15 11:03:58 +00:00
|
|
|
('draft','Draft'),
|
|
|
|
('inprogress','In progress'),
|
|
|
|
('done','Done'),
|
|
|
|
]
|
2013-02-14 17:07:36 +00:00
|
|
|
|
2013-02-15 14:16:51 +00:00
|
|
|
GAMIFICATION_PERIOD_STATE = [
|
2013-02-14 17:07:36 +00:00
|
|
|
('once','No automatic assigment'),
|
|
|
|
('daily','Daily'),
|
|
|
|
('weekly','Weekly'),
|
|
|
|
('monthly','Monthly'),
|
|
|
|
('yearly', 'Yearly')
|
|
|
|
]
|
|
|
|
|
2013-02-15 09:16:38 +00:00
|
|
|
GAMIFICATION_COMPUTATION_MODE = [
|
|
|
|
('sum','Sum'),
|
|
|
|
('count','Count'),
|
|
|
|
('manually','Manually')
|
|
|
|
]
|
|
|
|
|
|
|
|
GAMIFICATION_VALIDATION_CONDITION = [
|
|
|
|
('minus','<='),
|
|
|
|
('plus','>=')
|
|
|
|
]
|
|
|
|
|
2013-02-15 13:32:34 +00:00
|
|
|
GAMIFICATION_REPORT_MODE = [
|
|
|
|
('board','Leader board'),
|
|
|
|
('progressbar','Personal progressbar')
|
|
|
|
]
|
|
|
|
|
|
|
|
GAMIFICATION_REPORT_FREQ = [
|
|
|
|
('onchange','On change'),
|
|
|
|
('daily','Daily'),
|
|
|
|
('weekly','Weekly'),
|
|
|
|
('monthly','Monthly'),
|
|
|
|
('yearly', 'Yearly')
|
|
|
|
]
|
|
|
|
|
2013-02-15 09:16:38 +00:00
|
|
|
|
2013-02-14 17:07:36 +00:00
|
|
|
class gamification_goal_type(osv.Model):
|
|
|
|
"""Goal type definition
|
|
|
|
|
|
|
|
A goal type defining a way to set an objective and evaluate it
|
|
|
|
Each module wanting to be able to set goals to the users needs to create
|
|
|
|
a new gamification_goal_type
|
|
|
|
"""
|
|
|
|
_name = 'gamification.goal.type'
|
|
|
|
_description = 'Gamification goal type'
|
|
|
|
|
|
|
|
_columns = {
|
|
|
|
'name': fields.char('Name', required=True),
|
2013-02-15 09:16:38 +00:00
|
|
|
'description': fields.text('Description'),
|
|
|
|
'computation_mode': fields.selection(GAMIFICATION_COMPUTATION_MODE,
|
2013-02-14 17:07:36 +00:00
|
|
|
string="Mode of computation",
|
2013-02-15 09:16:38 +00:00
|
|
|
help="""How is computed the goal value :\n
|
|
|
|
- 'Sum' for the total of the values if the 'Evaluated field'\n
|
|
|
|
- 'Count' for the number of entries\n
|
2013-02-14 17:07:36 +00:00
|
|
|
- 'Manually' for user defined values""",
|
|
|
|
required=True),
|
|
|
|
'object': fields.many2one('ir.model',
|
|
|
|
string='Object',
|
2013-02-15 09:16:38 +00:00
|
|
|
help='The object type for the field to evaluate' ),
|
2013-02-14 17:07:36 +00:00
|
|
|
'field': fields.many2one('ir.model.fields',
|
|
|
|
string='Evaluated field',
|
2013-02-15 09:16:38 +00:00
|
|
|
help='The field containing the value to evaluate' ),
|
2013-02-14 17:07:36 +00:00
|
|
|
'field_date': fields.many2one('ir.model.fields',
|
|
|
|
string='Evaluated date field',
|
2013-02-15 09:16:38 +00:00
|
|
|
help='The date to use for the time period evaluated'),
|
2013-02-14 17:07:36 +00:00
|
|
|
'domain': fields.char("Domain"), # how to apply it ?
|
2013-02-15 09:16:38 +00:00
|
|
|
'condition' : fields.selection(GAMIFICATION_VALIDATION_CONDITION,
|
2013-02-14 17:07:36 +00:00
|
|
|
string='Validation condition',
|
2013-02-15 09:16:38 +00:00
|
|
|
help='A goal is considered as completed when the current value is compared to the value to reach',
|
|
|
|
required=True),
|
2013-02-14 17:07:36 +00:00
|
|
|
'sequence' : fields.integer('Sequence',
|
2013-02-15 09:16:38 +00:00
|
|
|
help='Sequence number for ordering',
|
2013-02-14 17:07:36 +00:00
|
|
|
required=True),
|
2013-02-14 08:20:38 +00:00
|
|
|
}
|
2013-02-14 17:07:36 +00:00
|
|
|
|
2013-02-15 14:54:15 +00:00
|
|
|
_order = 'sequence'
|
2013-02-14 17:07:36 +00:00
|
|
|
_defaults = {
|
|
|
|
'sequence': 0,
|
|
|
|
'condition': 'plus',
|
2013-02-15 09:16:38 +00:00
|
|
|
'computation_mode':'manually',
|
2013-02-14 08:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-14 17:07:36 +00:00
|
|
|
class gamification_goal(osv.Model):
|
|
|
|
"""Goal instance for a user
|
|
|
|
|
|
|
|
An individual goal for a user on a specified time period
|
|
|
|
"""
|
|
|
|
|
|
|
|
_name = 'gamification.goal'
|
|
|
|
_description = 'Gamification goal instance'
|
|
|
|
_inherit = 'mail.thread'
|
|
|
|
|
2013-02-15 14:54:15 +00:00
|
|
|
def _get_completeness(self, cr, uid, ids, field_name, arg, context=None):
|
|
|
|
res = {}
|
|
|
|
for goal in self.browse(cr, uid, ids, context):
|
|
|
|
# more 100% ?
|
|
|
|
if goal.target_goal > 0:
|
|
|
|
res[goal.id] = 100.0 * goal.current / goal.target_goal
|
|
|
|
else:
|
|
|
|
res[goal.id] = 0.0
|
|
|
|
return res
|
|
|
|
|
2013-02-14 17:07:36 +00:00
|
|
|
_columns = {
|
|
|
|
'type_id' : fields.many2one('gamification.goal.type',
|
|
|
|
string='Goal type',
|
|
|
|
required=True),
|
|
|
|
'user_id' : fields.many2one('res.users', string='User', required=True),
|
|
|
|
'plan_id' : fields.many2one('gamification.goal.plan',
|
|
|
|
string='Goal plan'),
|
|
|
|
'start_date' : fields.date('Start date'),
|
|
|
|
'end_date' : fields.date('End date'), # no start and end = always active
|
|
|
|
'target_goal' : fields.float('To reach',
|
|
|
|
required=True,
|
|
|
|
track_visibility = 'always'), # no goal = global index
|
|
|
|
'current' : fields.float('Current',
|
|
|
|
required=True,
|
|
|
|
track_visibility = 'always'),
|
2013-02-15 14:54:15 +00:00
|
|
|
'completeness': fields.function(_get_completeness,
|
|
|
|
type='float',
|
|
|
|
string='Occupation'),
|
2013-02-15 14:16:51 +00:00
|
|
|
'state': fields.selection(GAMIFICATION_GOAL_STATE,
|
|
|
|
string='State',
|
2013-02-14 17:07:36 +00:00
|
|
|
required=True,
|
|
|
|
track_visibility = 'always'),
|
|
|
|
}
|
2013-02-14 08:20:38 +00:00
|
|
|
|
2013-02-14 17:07:36 +00:00
|
|
|
_defaults = {
|
|
|
|
'current': 0,
|
2013-02-15 14:16:51 +00:00
|
|
|
'state': 'inprogress',
|
2013-02-14 17:07:36 +00:00
|
|
|
}
|
2013-02-14 08:20:38 +00:00
|
|
|
|
|
|
|
|
2013-02-14 17:07:36 +00:00
|
|
|
class gamification_goal_plan(osv.Model):
|
|
|
|
"""Ga;ification goal plan
|
|
|
|
|
|
|
|
Set of predifined goals to be able to automate goal settings or
|
|
|
|
quickly apply several goals manually to a group of users
|
|
|
|
|
|
|
|
If 'user_ids' is defined and 'period' is different than 'one', the set will
|
|
|
|
be assigned to the users for each period (eg: every 1st of each month if
|
|
|
|
'monthly' is selected)
|
|
|
|
"""
|
|
|
|
|
|
|
|
_name = 'gamification.goal.plan'
|
|
|
|
_description = 'Gamification goal plan'
|
|
|
|
|
|
|
|
_columns = {
|
|
|
|
'name' : fields.char('Plan name', required=True),
|
|
|
|
'user_ids' : fields.many2many('res.users',
|
2013-02-15 13:09:21 +00:00
|
|
|
string='Users',
|
2013-02-15 09:16:38 +00:00
|
|
|
help="list of users to which the goal will be set"),
|
2013-02-15 13:09:21 +00:00
|
|
|
'planline_ids' : fields.one2many('gamification.goal.planline',
|
|
|
|
'plan_id',
|
|
|
|
string='Planline',
|
|
|
|
help="list of goals that will be set"),
|
2013-02-15 13:32:34 +00:00
|
|
|
'autojoin_group_id' : fields.many2one('res.groups',
|
|
|
|
string='Group',
|
|
|
|
help='Group of users whose members will automatically be added to the users'),
|
2013-02-15 14:16:51 +00:00
|
|
|
'period' : fields.selection(GAMIFICATION_PERIOD_STATE,
|
2013-02-14 17:07:36 +00:00
|
|
|
string='Period',
|
2013-02-15 09:16:38 +00:00
|
|
|
help='Period of automatic goal assigment, will be done manually if none is selected',
|
2013-02-14 17:07:36 +00:00
|
|
|
required=True),
|
2013-02-15 14:16:51 +00:00
|
|
|
'state': fields.selection(GAMIFICATION_PLAN_STATE,
|
|
|
|
string='State',
|
2013-02-14 17:07:36 +00:00
|
|
|
required=True),
|
2013-02-15 13:32:34 +00:00
|
|
|
'report_mode':fields.selection(GAMIFICATION_REPORT_MODE,
|
|
|
|
string="Mode",
|
|
|
|
help='How is displayed the results, shared or in a signle progressbar',
|
|
|
|
required=True),
|
|
|
|
'report_message_frequency':fields.selection(GAMIFICATION_REPORT_FREQ,
|
|
|
|
string="Frequency",
|
|
|
|
required=True),
|
|
|
|
'report_message_group_id' : fields.many2one('mail.group',
|
|
|
|
string='Group',
|
|
|
|
help='Group that will receive the report in addition to the user'),
|
|
|
|
'report_header' : fields.text('Report header'),
|
2013-02-14 17:07:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_defaults = {
|
|
|
|
'period': 'once',
|
2013-02-15 14:16:51 +00:00
|
|
|
'state': 'inprogress',
|
2013-02-15 13:32:34 +00:00
|
|
|
'report_mode' : 'progressbar',
|
|
|
|
'report_message_frequency' : 'onchange',
|
2013-02-14 17:07:36 +00:00
|
|
|
}
|
2013-02-14 08:20:38 +00:00
|
|
|
|
|
|
|
|
2013-02-14 17:07:36 +00:00
|
|
|
class gamification_goal_planline(osv.Model):
|
|
|
|
"""Gamification goal planline
|
2013-02-14 08:20:38 +00:00
|
|
|
|
2013-02-14 17:07:36 +00:00
|
|
|
Predifined goal for 'gamification_goal_plan'
|
|
|
|
These are generic list of goals with only the target goal defined
|
|
|
|
Should only be created for the gamification_goal_plan object
|
|
|
|
"""
|
2013-02-14 08:20:38 +00:00
|
|
|
|
2013-02-14 17:07:36 +00:00
|
|
|
_name = 'gamification.goal.planline'
|
|
|
|
_description = 'Gamification generic goal for plan'
|
2013-02-14 08:20:38 +00:00
|
|
|
|
2013-02-14 17:07:36 +00:00
|
|
|
_columns = {
|
|
|
|
'plan_id' : fields.many2one('gamification.goal.plan',
|
|
|
|
string='Plan'),
|
|
|
|
'type_id' : fields.many2one('gamification.goal.type',
|
|
|
|
string='Goal type'),
|
|
|
|
'target_goal' : fields.float('Target value to reach'),
|
2013-02-14 09:21:51 +00:00
|
|
|
}
|