diff options
| author | Martin Trigaux <mat@openerp.com> | 2013-04-24 14:23:34 +0200 |
|---|---|---|
| committer | Martin Trigaux <mat@openerp.com> | 2013-04-24 14:23:34 +0200 |
| commit | cc8d4ae4d49cb3102fd6ef069d8d82a02fad9403 (patch) | |
| tree | ef84860b0425554cfad31987c163c7a656ba7436 /addons | |
| parent | cd23075ff694dfe4c50f5af2b9c9545b920d560e (diff) | |
[ADD] goal type example
bzr revid: mat@openerp.com-20130424122334-9wyfq4ns2d1c4c50
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/gamification/__init__.py | 1 | ||||
| -rw-r--r-- | addons/gamification/goal.py | 2 | ||||
| -rw-r--r-- | addons/gamification/goal_base_data.xml | 7 | ||||
| -rw-r--r-- | addons/gamification/goal_type_data.py | 18 | ||||
| -rw-r--r-- | addons/gamification/goal_view.xml | 2 | ||||
| -rw-r--r-- | addons/gamification/templates/group_progress.mako | 6 | ||||
| -rw-r--r-- | addons/gamification/templates/personal_progress.mako | 12 |
7 files changed, 38 insertions, 10 deletions
diff --git a/addons/gamification/__init__.py b/addons/gamification/__init__.py index b7f7efeac07..3c4211df081 100644 --- a/addons/gamification/__init__.py +++ b/addons/gamification/__init__.py @@ -1,4 +1,5 @@ import goal +import goal_type_data import plan import res_users import badge diff --git a/addons/gamification/goal.py b/addons/gamification/goal.py index d836bcc82c1..ce830e93f06 100644 --- a/addons/gamification/goal.py +++ b/addons/gamification/goal.py @@ -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: diff --git a/addons/gamification/goal_base_data.xml b/addons/gamification/goal_base_data.xml index 99603f917b7..76408c92e85 100644 --- a/addons/gamification/goal_base_data.xml +++ b/addons/gamification/goal_base_data.xml @@ -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 --> diff --git a/addons/gamification/goal_type_data.py b/addons/gamification/goal_type_data.py index 37976a45742..40df5f6a88c 100644 --- a/addons/gamification/goal_type_data.py +++ b/addons/gamification/goal_type_data.py @@ -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 diff --git a/addons/gamification/goal_view.xml b/addons/gamification/goal_view.xml index 9a913863455..6982ba0731a 100644 --- a/addons/gamification/goal_view.xml +++ b/addons/gamification/goal_view.xml @@ -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"> diff --git a/addons/gamification/templates/group_progress.mako b/addons/gamification/templates/group_progress.mako index 6f4b7d5d747..00751f98134 100644 --- a/addons/gamification/templates/group_progress.mako +++ b/addons/gamification/templates/group_progress.mako @@ -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 diff --git a/addons/gamification/templates/personal_progress.mako b/addons/gamification/templates/personal_progress.mako index e5cfbc3137c..bd744bb63a5 100644 --- a/addons/gamification/templates/personal_progress.mako +++ b/addons/gamification/templates/personal_progress.mako @@ -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 |
