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 @@ + + # Mail Group Following + Follow mail groups to receive news + python + self.number_following(cr, uid, 'mail.group') + + 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 @@ - + 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 @@ ${idx+1} ${goal.user_id.name} ${goal.completeness}% - ${goal.current}/${goal.target_goal} ${goal.type_suffix} + ${goal.current}/${goal.target_goal} + % if goal.type_suffix: + ${goal.type_suffix} + % endif + % 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 > ${goal.type_id.name} - ${goal.target_goal} ${goal.type_suffix} - ${goal.current} ${goal.type_suffix} + ${goal.target_goal} + % if goal.type_suffix: + ${goal.type_suffix} + % endif + + ${goal.current} + % if goal.type_suffix: + ${goal.type_suffix} + % endif + ${goal.completeness} % % endfor