[REF] gamification: minor changes for better consistency

bzr revid: mat@openerp.com-20130220123328-n13psgprp4ci14vn
This commit is contained in:
Martin Trigaux 2013-02-20 13:33:28 +01:00
parent 3eaa452f1d
commit 55541a3d3b
4 changed files with 98 additions and 89 deletions

View File

@ -20,52 +20,7 @@
##############################################################################
from openerp.osv import fields, osv
GAMIFICATION_GOAL_STATE = [
('inprogress', 'In progress'),
('inprogress_update', 'In progress (to update)'),
('reached', 'Reached'),
('failed', 'Failed'),
]
GAMIFICATION_PLAN_STATE = [
('draft', 'Draft'),
('inprogress', 'In progress'),
('done', 'Done'),
]
GAMIFICATION_PERIOD_STATE = [
('once', 'Manual'),
('daily', 'Daily'),
('weekly', 'Weekly'),
('monthly', 'Monthly'),
('yearly', 'Yearly')
]
GAMIFICATION_COMPUTATION_MODE = [
('sum','Sum'),
('count','Count'),
('manually','Manually')
]
GAMIFICATION_VALIDATION_CONDITION = [
('minus','<='),
('plus','>=')
]
GAMIFICATION_REPORT_MODE = [
('board','Leader board'),
('progressbar','Personal progressbar')
]
GAMIFICATION_REPORT_FREQ = [
('never','Never'),
('onchange','On change'),
('daily','Daily'),
('weekly','Weekly'),
('monthly','Monthly'),
('yearly', 'Yearly')
]
from openerp.tools.safe_eval import safe_eval
class gamification_goal_type(osv.Model):
@ -82,7 +37,11 @@ class gamification_goal_type(osv.Model):
_columns = {
'name': fields.char('Type Name', required=True),
'description': fields.text('Description'),
'computation_mode': fields.selection(GAMIFICATION_COMPUTATION_MODE,
'computation_mode': fields.selection([
('sum','Sum'),
('count','Count'),
('manually','Manually')
],
string="Mode of Computation",
help="""How is computed the goal value :\n
- 'Sum' for the total of the values if the 'Evaluated field'\n
@ -101,7 +60,10 @@ class gamification_goal_type(osv.Model):
'domain': fields.char("Domain",
help="Technical filters rules to apply",
required=True), # how to apply it ?
'condition' : fields.selection(GAMIFICATION_VALIDATION_CONDITION,
'condition' : fields.selection([
('minus','<='),
('plus','>=')
],
string='Validation Condition',
help='A goal is considered as completed when the current value is compared to the value to reach',
required=True),
@ -118,6 +80,15 @@ class gamification_goal_type(osv.Model):
'domain':"[]",
}
def compute_goal_completeness(current, target_goal):
# more than 100% case is handled by the widget
if target_goal > 0:
return 100.0 * current / target_goal
else:
return 0.0
class gamification_goal(osv.Model):
"""Goal instance for a user
@ -131,11 +102,7 @@ class gamification_goal(osv.Model):
def _get_completeness(self, cr, uid, ids, field_name, arg, context=None):
res = {}
for goal in self.browse(cr, uid, ids, context):
# more than 100% case is handled by the widget
if goal.target_goal > 0:
res[goal.id] = 100.0 * goal.current / goal.target_goal
else:
res[goal.id] = 0.0
res[goal.id] = compute_goal_completeness(goal.current, goal.target_goal)
return res
_columns = {
@ -144,7 +111,7 @@ class gamification_goal(osv.Model):
required=True,
ondelete="cascade"),
'user_id' : fields.many2one('res.users', string='User', required=True),
'plan_id' : fields.many2one('gamification.goal.plan',
'planline_id' : fields.many2one('gamification.goal.planline',
string='Goal Plan',
ondelete="cascade"),
'start_date' : fields.date('Start Date'),
@ -157,8 +124,14 @@ class gamification_goal(osv.Model):
track_visibility = 'always'),
'completeness': fields.function(_get_completeness,
type='float',
string='Occupation'),
'state': fields.selection(GAMIFICATION_GOAL_STATE,
string='Completeness'),
'state': fields.selection([
('inprogress', 'In progress'),
('inprogress_update', 'In progress (to update)'),
('reached', 'Reached'),
('failed', 'Failed'),
('canceled', 'Canceled'),
],
string='State',
required=True,
track_visibility = 'always'),
@ -210,18 +183,38 @@ class gamification_goal_plan(osv.Model):
'autojoin_group_id' : fields.many2one('res.groups',
string='Group',
help='Group of users whose members will automatically be added to the users'),
'period' : fields.selection(GAMIFICATION_PERIOD_STATE,
string='Period',
'period' : fields.selection([
('once', 'Manual'),
('daily', 'Daily'),
('weekly', 'Weekly'),
('monthly', 'Monthly'),
('yearly', 'Yearly')
],
string='Periodicity',
help='Period of automatic goal assigment, will be done manually if none is selected',
required=True),
'state': fields.selection(GAMIFICATION_PLAN_STATE,
'state': fields.selection([
('draft', 'Draft'),
('inprogress', 'In progress'),
('done', 'Done'),
],
string='State',
required=True),
'report_mode':fields.selection(GAMIFICATION_REPORT_MODE,
string="Mode",
help='How is displayed the results, shared or in a signle progressbar',
'visibility_mode':fields.selection([
('board','Leader board'),
('progressbar','Personal progressbar')
],
string="Visibility",
help='How are displayed the results, shared or in a single progressbar',
required=True),
'report_message_frequency':fields.selection(GAMIFICATION_REPORT_FREQ,
'report_message_frequency':fields.selection([
('never','Never'),
('onchange','On change'),
('daily','Daily'),
('weekly','Weekly'),
('monthly','Monthly'),
('yearly', 'Yearly')
],
string="Frequency",
required=True),
'report_message_group_id' : fields.many2one('mail.group',
@ -235,7 +228,7 @@ class gamification_goal_plan(osv.Model):
_defaults = {
'period': 'once',
'state': 'draft',
'report_mode' : 'progressbar',
'visibility_mode' : 'progressbar',
'report_message_frequency' : 'onchange',
}
@ -287,6 +280,24 @@ class gamification_goal_plan(osv.Model):
return self.write(cr, uid, ids, {'state': 'inprogress'}, context=context)
def generate_goals_from_plan(self, cr, uid, ids, context=None):
"""Generate the lsit of goals fron a plan"""
for plan in self.browse(cr, uid, ids, context):
for planline in plan.planline_ids:
for user in plan.user_ids:
goal_obj = self.pool.get('gamification.goal')
current = compute_current_value(planline.type_id, user_id)
goal_id = goal_obj.create(cr, uid, {
'type_id': planline.type_id,
'user_id': user.id,
'start_date':0,
'end_date':0,
'target_goal':planline.target_goal,
'state':'inprogress',
'last_update':fields.date.today,
}, context=context)
class gamification_goal_planline(osv.Model):
"""Gamification goal planline

View File

@ -5,7 +5,6 @@
<field name="name">Goals</field>
<field name="res_model">gamification.goal</field>
<field name="view_mode">tree,form,calendar</field>
<field name="context">{'search_default_my_in_progress': 1}</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create a goal.
@ -30,7 +29,7 @@
<field name="end_date"/>
<field name="completeness" widget="progressbar"/>
<field name="state" invisible="1"/>
<field name="plan_id" invisible="1"/>
<field name="planline_id" invisible="1"/>
</tree>
</field>
</record>
@ -41,7 +40,8 @@
<field name="arch" type="xml">
<form string="Goal" version="7.0">
<header>
<button string="Goal Reached" type="object" name="action_reach" states="inprogress,inprogress_update" class="oe_highlight"/>
<button string="Refresh state" type="object" name="action_refresh" states="inprogress,inprogress_update" class="oe_highlight"/>
<button string="Goal Reached" type="object" name="action_reach" states="inprogress,inprogress_update" />
<button string="Goal Failed" type="object" name="action_fail" states="inprogress,inprogress_update"/>
<button string="Reset Completion" type="object" name="action_cancel" states="failed,reached"/>
<field name="state" widget="statusbar" statusbar_visible="inprogress,inprogress_update" />
@ -51,7 +51,7 @@
<group string="Reference">
<field name="type_id"/>
<field name="user_id"/>
<field name="plan_id"/>
<field name="planline_id"/>
</group>
<group string="Schedule">
<field name="start_date"/>
@ -89,9 +89,9 @@
<field name="model">gamification.goal</field>
<field name="arch" type="xml">
<search string="Search Goals">
<filter name="my_in_progress" string="My Goals in Progress"
<filter name="my_inprogress" string="My Goals in Progress"
domain="[('user_id', '=', uid),('state', 'in', ('inprogress', 'inprogress_update'))]"/>
<field name="plan_id"/>
<field name="planline_id"/>
<field name="user_id"/>
<field name="type_id"/>
<group expand="0" string="Group By...">
@ -99,7 +99,6 @@
<filter string="Goal Type" domain="[]" context="{'group_by':'type_id'}"/>
<filter string="State" domain="[]" context="{'group_by':'state'}"/>
<filter string="End Date" domain="[]" context="{'group_by':'end_date'}"/>
<filter string="Plan" domain="[]" context="{'group_by':'plan_id'}"/>
</group>
</search>
</field>

View File

@ -6,7 +6,6 @@
<field name="name">Goal Plans</field>
<field name="res_model">gamification.goal.plan</field>
<field name="view_mode">tree,form</field>
<field name="context">{'search_default_draft_active': 1}</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create a goal plan.
@ -57,7 +56,7 @@
<div class="oe_edit_only">
<label for="name"/>
</div>
<field name="name"/>
<field name="name" attrs="{'readonly':[('state','!=','draft')]}"/>
</h1>
<!-- action buttons -->
@ -67,24 +66,24 @@
<group>
<group colspan="4">
<field name="period"/>
<field name="period" attrs="{'readonly':[('state','!=','draft')]}"/>
<field name="remind_update_delays"/>
<field name="visibility_mode"/>
</group>
<group string="Report">
<field name="report_mode"/>
<field name="report_message_frequency"/>
<field name="report_message_group_id"/>
<field name="report_header"/>
<field name="remind_update_delays"/>
<field name="report_message_group_id" />
<field name="report_message_frequency" attrs="{'invisible':[('report_message_group_id','!=', False)], 'required':[('report_message_group_id','!=', False)]}"/>
<field name="report_header" attrs="{'invisible':[('report_message_group_id','!=', False)]}"/>
</group>
</group>
<group string="Planlines">
<field name="planline_ids" nolabel="1" attrs="{'readonly':[('state','!=','draft')]}">
<tree string="Planline List" version="7.0" editable="bottom" >
<field name="type_id"/>
<field name="target_goal"/>
</tree>
</field>
<field name="planline_ids" nolabel="1">
<tree string="Planline List" version="7.0" editable="bottom" >
<field name="type_id"/>
<field name="target_goal"/>
</tree>
</field>
</group>
<group string="Subscription">
@ -135,7 +134,7 @@
<field name="model">gamification.goal.plan</field>
<field name="arch" type="xml">
<search string="Search Goal Plans">
<filter name="draft_active" string="Draft or Active Plans"
<filter name="draft_inprogress" string="Non-closed Plans"
domain="[('state', 'in', ('inprogress', 'draft'))]"/>
<field name="name"/>
<group expand="0" string="Group By...">

View File

@ -50,10 +50,10 @@
<group string="Computation">
<field name="computation_mode"/>
<!-- Hide the fields beloz if manually -->
<!-- Hide the fields below if manually -->
<field name="model_id" attrs="{'invisible':[('computation_mode','=','manually')], 'required':[('computation_mode','!=','manually')]}"/>
<field name="field_id" attrs="{'invisible':[('computation_mode','=','manually')], 'required':[('computation_mode','!=','manually')]}" domain="[('model_id','=',model_id)]" />
<field name="field_date_id" attrs="{'invisible':[('computation_mode','=','manually')], 'required':[('computation_mode','!=','manually')]}" domain="[('ttype', 'in', ('date', 'datetime')), ('model_id','=',model_id)]"/>
<field name="field_id" attrs="{'invisible':[('computation_mode','!=','sum')], 'required':[('computation_mode','=','sum')]}" domain="[('model_id','=',model_id)]" />
<field name="field_date_id" attrs="{'invisible':[('computation_mode','=','manually')]}" domain="[('ttype', 'in', ('date', 'datetime')), ('model_id','=',model_id)]"/>
<field name="domain" attrs="{'invisible':[('computation_mode','=','manually')], 'required':[('computation_mode','!=','manually')]}"/>
</group>
</group>