[REF] remove automatic code for badges
bzr revid: mat@openerp.com-20130418082402-3h89j54gdvwe3dwu
This commit is contained in:
parent
2dbfe49d73
commit
24f44d38c4
|
@ -261,99 +261,6 @@ class gamification_badge(osv.Model):
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _cron_check(self, cr, uid, context=None):
|
|
||||||
"""Run cron on all automatic goals"""
|
|
||||||
ids = self.search(cr, uid, [('rule_automatic', '!=', 'manual')], context=context)
|
|
||||||
self.check_automatic(cr, uid, ids, context=context)
|
|
||||||
|
|
||||||
def check_automatic(self, cr, uid, ids, context=None):
|
|
||||||
"""Check if the badges should be deserved to users
|
|
||||||
|
|
||||||
Only badges with an automatic rule specified are checked to be
|
|
||||||
granted, other type of badge will be skipped. Send alert messages to
|
|
||||||
the one validating the condition.
|
|
||||||
:param ids: the list of id of the badges to check
|
|
||||||
|
|
||||||
In case of python code to execute, the user should input the name of
|
|
||||||
the function that will be excuted through safe_eval. The globals
|
|
||||||
variables available are cr (database cursor), uid (current user id)
|
|
||||||
and context.
|
|
||||||
|
|
||||||
To create new functions in different modules, create a class extending
|
|
||||||
the 'gamification.badge.execute' class and implementing this method. The result
|
|
||||||
of the function should be a list of res.users ids (int). A badge_user
|
|
||||||
linked to this badge will be created for each of these users and a
|
|
||||||
notification will be send.
|
|
||||||
Beware that the case of user already having this badge is NOT checked
|
|
||||||
and is the responsability of the python code.
|
|
||||||
|
|
||||||
In case of list of goals to check, the case of a user already having
|
|
||||||
this badge is checked and the user will not receive badge at each run
|
|
||||||
of this method.
|
|
||||||
"""
|
|
||||||
|
|
||||||
context = context or {}
|
|
||||||
badge_user_obj = self.pool.get('gamification.badge.user')
|
|
||||||
|
|
||||||
for badge in self.browse(cr, uid, ids, context=context):
|
|
||||||
|
|
||||||
if badge.rule_automatic == 'python':
|
|
||||||
values = {'cr': cr, 'uid': uid, 'context': context, 'self': self.pool.get('gamification.badge.execute')}
|
|
||||||
result = safe_eval(badge.compute_code, values, {})
|
|
||||||
|
|
||||||
# code_obj = compile(badge.compute_code, '<string>', 'exec')
|
|
||||||
# code_globals = {}
|
|
||||||
# code_locals = {'cr': cr, 'uid': uid, 'context': context, 'result': []}
|
|
||||||
# exec code_obj in code_globals, code_locals
|
|
||||||
if type(result) == list:
|
|
||||||
user_badge_ids = [
|
|
||||||
badge_user_obj.create(cr, uid, {'user_id': user_id, 'badge_id': badge.id}, context=context)
|
|
||||||
for user_id in result
|
|
||||||
]
|
|
||||||
self.send_badge(cr, uid, badge.id, user_badge_ids, context=context)
|
|
||||||
else:
|
|
||||||
raise osv.except_osv(_('Error!'), _('Unvalid return content from the evaluation of %s' % str(badge.compute_code)))
|
|
||||||
|
|
||||||
elif badge.rule_automatic == 'goals':
|
|
||||||
common_users = None
|
|
||||||
for goal_type in badge.goal_type_ids:
|
|
||||||
res = self.pool.get('gamification.goal').read_group(cr, uid, [
|
|
||||||
('type_id', '=', goal_type.id),
|
|
||||||
('state', '=', 'reached'),
|
|
||||||
], ['user_id', 'state', 'type_id'], ['user_id'], context=context)
|
|
||||||
|
|
||||||
users = [goal['user_id'][0] for goal in res]
|
|
||||||
if common_users is None:
|
|
||||||
# first type, include all
|
|
||||||
common_users = users
|
|
||||||
else:
|
|
||||||
merged_list = [user_id for user_id in users if user_id in common_users]
|
|
||||||
common_users = merged_list
|
|
||||||
|
|
||||||
if common_users is None:
|
|
||||||
# nobody succeeded the goals
|
|
||||||
continue
|
|
||||||
|
|
||||||
# remove users having already this badge
|
|
||||||
badge_user_not_having = []
|
|
||||||
for user_id in common_users:
|
|
||||||
badge_user_having = badge_user_obj.search(cr, uid, [
|
|
||||||
('user_id', '=', user_id),
|
|
||||||
('badge_id', '=', badge.id)], context=context)
|
|
||||||
if len(badge_user_having) == 0:
|
|
||||||
badge_user_not_having.append(user_id)
|
|
||||||
|
|
||||||
# create badge users for users deserving the badge
|
|
||||||
user_badge_ids = [
|
|
||||||
badge_user_obj.create(cr, uid, {'user_id': user_id, 'badge_id': badge.id}, context=context)
|
|
||||||
for user_id in badge_user_not_having
|
|
||||||
]
|
|
||||||
self.send_badge(cr, uid, badge.id, user_badge_ids, context=context)
|
|
||||||
|
|
||||||
# else badge.rule_automatic == 'manual':
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def check_granting(self, cr, uid, user_from_id, badge_id, context=None):
|
def check_granting(self, cr, uid, user_from_id, badge_id, context=None):
|
||||||
"""Check the user can grant a badge and raise the appropriate exception
|
"""Check the user can grant a badge and raise the appropriate exception
|
||||||
if not"""
|
if not"""
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
<field name="name">Good Job</field>
|
<field name="name">Good Job</field>
|
||||||
<field name="description">You did great at your job.</field>
|
<field name="description">You did great at your job.</field>
|
||||||
<field name="rule_auth">everyone</field>
|
<field name="rule_auth">everyone</field>
|
||||||
<field name="rule_automatic">manual</field>
|
|
||||||
<field name="image">iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAABmJLR0QAxACcAA+BYKlhAAAACXBI
|
<field name="image">iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAABmJLR0QAxACcAA+BYKlhAAAACXBI
|
||||||
WXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QMdCSITq3pssgAAIABJREFUeNrtvXmcXVWZ7/191h7O
|
WXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QMdCSITq3pssgAAIABJREFUeNrtvXmcXVWZ7/191h7O
|
||||||
UPOUVOZKQmaSMAYIiDIIiIKCXqFRabyK2tfb9qA92Gq3b3uV621xbBC1VbRFEEUmgaDM8xCmEMhI
|
UPOUVOZKQmaSMAYIiDIIiIKCXqFRabyK2tfb9qA92Gq3b3uV621xbBC1VbRFEEUmgaDM8xCmEMhI
|
||||||
|
@ -223,7 +222,6 @@
|
||||||
<field name="name">Problem Solver</field>
|
<field name="name">Problem Solver</field>
|
||||||
<field name="description">No one can solve challenges like you do.</field>
|
<field name="description">No one can solve challenges like you do.</field>
|
||||||
<field name="rule_auth">everyone</field>
|
<field name="rule_auth">everyone</field>
|
||||||
<field name="rule_automatic">manual</field>
|
|
||||||
<field name="image">iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAABmJLR0QAVgB7ADQ3APIQAAAACXBI
|
<field name="image">iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAABmJLR0QAVgB7ADQ3APIQAAAACXBI
|
||||||
WXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QMdCQASe88aBAAAIABJREFUeNrsvXeYZld15vtbe59z
|
WXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QMdCQASe88aBAAAIABJREFUeNrsvXeYZld15vtbe59z
|
||||||
vlj1Va7OUa1Wq6UWykIJJBAKgEDkYMCAB2xsj8O1fa/TjO0Zj+1nDL4YX3DAeEyOJuNLECAJhFBA
|
vlj1Va7OUa1Wq6UWykIJJBAKgEDkYMCAB2xsj8O1fa/TjO0Zj+1nDL4YX3DAeEyOJuNLECAJhFBA
|
||||||
|
@ -622,7 +620,6 @@
|
||||||
<field name="name">Brilliant</field>
|
<field name="name">Brilliant</field>
|
||||||
<field name="description">With your brilliant ideas, you are an inspiration to others.</field>
|
<field name="description">With your brilliant ideas, you are an inspiration to others.</field>
|
||||||
<field name="rule_auth">everyone</field>
|
<field name="rule_auth">everyone</field>
|
||||||
<field name="rule_automatic">manual</field>
|
|
||||||
<field name="image">iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAABmJLR0QAvQBcABUZb0TlAAAACXBI
|
<field name="image">iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAABmJLR0QAvQBcABUZb0TlAAAACXBI
|
||||||
WXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QMdCTAQSodN2wAAIABJREFUeNrsvXmUbVd93/nZe5/x
|
WXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QMdCTAQSodN2wAAIABJREFUeNrsvXmUbVd93/nZe5/x
|
||||||
zlPN9eZRehqRkBACZGywmWwwNnjAcXDbTsftOEknbnevtnt5OXHshHjICrEhcRaJzdDGYIyZBEgI
|
zlPN9eZRehqRkBACZGywmWwwNnjAcXDbTsftOEknbnevtnt5OXHshHjICrEhcRaJzdDGYIyZBEgI
|
||||||
|
|
|
@ -103,13 +103,7 @@
|
||||||
<group string="Rewards for challenges">
|
<group string="Rewards for challenges">
|
||||||
<field name="plan_ids" widget="many2many_kanban" nolabel="1" />
|
<field name="plan_ids" widget="many2many_kanban" nolabel="1" />
|
||||||
</group>
|
</group>
|
||||||
<!--
|
<group string="Statistics">
|
||||||
<group string="Rules for Automatic Granting">
|
|
||||||
<field name="rule_automatic" widget="radio"/>
|
|
||||||
<field name="compute_code" attrs="{'invisible': [('rule_automatic','!=','python')]}"/>
|
|
||||||
<field name="goal_type_ids" attrs="{'invisible': [('rule_automatic','!=','goals')]}" widget="many2many_tags"/>
|
|
||||||
</group>
|
|
||||||
--> <group string="Statistics">
|
|
||||||
<group>
|
<group>
|
||||||
<field name="stat_count"/>
|
<field name="stat_count"/>
|
||||||
<field name="stat_this_month"/>
|
<field name="stat_this_month"/>
|
||||||
|
|
|
@ -12,16 +12,5 @@
|
||||||
<field name="function">_cron_update</field>
|
<field name="function">_cron_update</field>
|
||||||
<field name="args">()</field>
|
<field name="args">()</field>
|
||||||
</record>
|
</record>
|
||||||
<record forcecreate="True" id="ir_cron_check_badge"
|
|
||||||
model="ir.cron">
|
|
||||||
<field name="name">Run Bagde Checker</field>
|
|
||||||
<field name="interval_number">1</field>
|
|
||||||
<field name="interval_type">days</field>
|
|
||||||
<field name="numbercall">-1</field>
|
|
||||||
<field eval="False" name="doall" />
|
|
||||||
<field name="model">gamification.badge</field>
|
|
||||||
<field name="function">_cron_check</field>
|
|
||||||
<field name="args">()</field>
|
|
||||||
</record>
|
|
||||||
</data>
|
</data>
|
||||||
</openerp>
|
</openerp>
|
Loading…
Reference in New Issue