[ADD] goal type example
bzr revid: mat@openerp.com-20130424122334-9wyfq4ns2d1c4c50
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import goal
|
||||
import goal_type_data
|
||||
import plan
|
||||
import res_users
|
||||
import badge
|
||||
|
||||
@@ -258,7 +258,7 @@ class gamification_goal(osv.Model):
|
||||
subtype='mail.mt_comment')
|
||||
|
||||
elif goal.type_id.computation_mode == 'python':
|
||||
values = {'cr': cr, 'uid': uid, 'context': context, 'self': self.pool.get('gamification.goal.type')}
|
||||
values = {'cr': cr, 'uid': goal.user_id.id, 'context': context, 'self': self.pool.get('gamification.goal.type')}
|
||||
result = safe_eval(goal.type_id.compute_code, values, {})
|
||||
|
||||
if type(result) == float or type(result) == int:
|
||||
|
||||
@@ -68,6 +68,13 @@
|
||||
<field name="action_id" eval="ref('action_new_simplified_res_users')" />
|
||||
</record>
|
||||
|
||||
<record model="gamification.goal.type" id="type_nbr_following">
|
||||
<field name="name"># Mail Group Following</field>
|
||||
<field name="description">Follow mail groups to receive news</field>
|
||||
<field name="computation_mode">python</field>
|
||||
<field name="compute_code">self.number_following(cr, uid, 'mail.group')</field>
|
||||
<field name="action_id" eval="ref('mail.action_view_groups')" />
|
||||
</record>
|
||||
|
||||
|
||||
<!-- plans -->
|
||||
|
||||
@@ -50,10 +50,18 @@ class gamification_goal_type_data(osv.Model):
|
||||
delta = relativedelta(years=user.create_date.year - today.year, months=user.create_date.month - today.month)
|
||||
return delta.years*12 + delta.months
|
||||
|
||||
def number_mail_groups(self, cr, uid, context=None):
|
||||
"""Return the number of mail group the user has joined
|
||||
For example purpose, similar goal could be done with a 'count' goal.
|
||||
def number_following(self, cr, uid, xml_id="mail.thread", context=None):
|
||||
"""Return the number of 'xml_id' objects the user is following
|
||||
|
||||
'message_is_follower' is a non-stored field so could not be in a search
|
||||
domain with a 'count' goal type
|
||||
The object must inherit from mail.thread
|
||||
"""
|
||||
if context is None: context = {}
|
||||
mail_group_ids = self.pool.get('mail.group').search(cr, uid, [('message_is_follower', '=', True)], context=context)
|
||||
return len(mail_group_ids)
|
||||
ref_obj = self.pool.get(xml_id)
|
||||
obj_ids = ref_obj.search(cr, uid, [], context=context)
|
||||
following_count = 0
|
||||
for obj in ref_obj.browse(cr, uid, obj_ids, context=context):
|
||||
if obj.message_is_follower:
|
||||
following_count += 1
|
||||
return following_count
|
||||
|
||||
@@ -244,7 +244,7 @@
|
||||
<field name="field_id" attrs="{'invisible':[('computation_mode','!=','sum')], 'required':[('computation_mode','=','sum')]}" domain="[('model_id','=',model_id)]" class="oe_inline"/>
|
||||
<field name="field_date_id" attrs="{'invisible':[('computation_mode','not in',('sum', 'count'))]}" domain="[('ttype', 'in', ('date', 'datetime')), ('model_id','=',model_id)]" class="oe_inline"/>
|
||||
<field name="domain" attrs="{'invisible':[('computation_mode','not in',('sum', 'count'))], 'required':[('computation_mode','in',('sum', 'count'))]}" class="oe_inline"/>
|
||||
<field name="compute_code" attrs="{'invisible':[('computation_mode','!=','python')], 'required':[('computation_mode','=','python')]}"/>
|
||||
<field name="compute_code" attrs="{'invisible':[('computation_mode','!=','python')], 'required':[('computation_mode','=','python')]}" placeholder="e.g. self.my_method(cr, uid)"/>
|
||||
<field name="condition" widget="radio"/>
|
||||
</group>
|
||||
<group string="Formating Options">
|
||||
|
||||
@@ -22,7 +22,11 @@
|
||||
<td>${idx+1}</td>
|
||||
<td>${goal.user_id.name}</td>
|
||||
<td>${goal.completeness}%</td>
|
||||
<td>${goal.current}/${goal.target_goal} ${goal.type_suffix}</td>
|
||||
<td>${goal.current}/${goal.target_goal}
|
||||
% if goal.type_suffix:
|
||||
${goal.type_suffix}
|
||||
% endif
|
||||
</td>
|
||||
</tr>
|
||||
% endif
|
||||
% endfor
|
||||
|
||||
@@ -14,8 +14,16 @@
|
||||
% endif
|
||||
>
|
||||
<td>${goal.type_id.name}</td>
|
||||
<td>${goal.target_goal} ${goal.type_suffix}</td>
|
||||
<td>${goal.current} ${goal.type_suffix}</td>
|
||||
<td>${goal.target_goal}
|
||||
% if goal.type_suffix:
|
||||
${goal.type_suffix}
|
||||
% endif
|
||||
</td>
|
||||
<td>${goal.current}
|
||||
% if goal.type_suffix:
|
||||
${goal.type_suffix}
|
||||
% endif
|
||||
</td>
|
||||
<td>${goal.completeness} %</td>
|
||||
</tr>
|
||||
% endfor
|
||||
|
||||
Reference in New Issue
Block a user