From ce777dde1cdea831edfc6dee7e3ff212b973353a Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Wed, 27 Feb 2013 09:46:08 +0100 Subject: [PATCH] [IMP] gamification: better consistency for plan bzr revid: mat@openerp.com-20130227084608-79t5fyjzweq5zq1j --- addons/gamification/goal.py | 20 ++++++++++++---- addons/gamification/view/plan.xml | 38 ++++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/addons/gamification/goal.py b/addons/gamification/goal.py index fedf4c7ea36..32186ff0a15 100644 --- a/addons/gamification/goal.py +++ b/addons/gamification/goal.py @@ -305,7 +305,7 @@ class gamification_goal_plan(osv.Model): help="list of goals that will be set", required=True), 'autojoin_group_id' : fields.many2one('res.groups', - string='Group', + string='Auto-join Group', help='Group of users whose members will automatically be added to the users'), 'period' : fields.selection([ ('once', 'No Periodicity'), @@ -342,8 +342,8 @@ class gamification_goal_plan(osv.Model): string="Frequency", required=True), 'report_message_group_id' : fields.many2one('mail.group', - string='Report to', - help='Group that will receive the report in addition to the user'), + string='Send a copy to', + help='Group that will receive a copy of the report in addition to the user'), 'report_header' : fields.text('Report Header'), 'remind_update_delay' : fields.integer('Remind delay', help="The number of days after which the user assigned to a manual goal will be reminded. Never reminded if no value is specified.") @@ -375,6 +375,16 @@ class gamification_goal_plan(osv.Model): (_check_nonzero_users, "At least one user is required to create a non-draft goal plan", ['user_ids']), ] + def write(self, cr, uid, ids, vals, context=None): + """Overwrite the write method to add the user of groups""" + write_res = super(gamification_goal_plan, self).write(cr, uid, ids, vals, context=context) + + # add users when change the group auto-subscription + if 'autojoin_group_id' in vals: + new_group = self.pool.get('res.groups').browse(cr, uid, vals['autojoin_group_id'], context=context) + self.plan_subscribe_users(cr, uid, ids, [user.id for user in new_group.users], context=context) + return write_res + def _update_all(self, cr, uid, ids=False, context=None): """Update every plan in progress""" if not ids: @@ -487,7 +497,7 @@ class gamification_goal_plan(osv.Model): return True - def plan_subscribe_users(self, cr, uid, ids, user_ids, context=None): + def plan_subscribe_users(self, cr, uid, ids, new_user_ids, context=None): """ Add the following users to plans :param ids: ids of plans to which the users will be added @@ -495,7 +505,7 @@ class gamification_goal_plan(osv.Model): for plan in self.browse(cr,uid, ids, context): subscription = [user.id for user in plan.user_ids] - subscription.extend(user_ids) + subscription.extend(new_user_ids) unified_subscription = list(set(subscription)) self.write(cr, uid, ids, {'user_ids': [(4, uid) for uid in unified_subscription]}, context=context) return True diff --git a/addons/gamification/view/plan.xml b/addons/gamification/view/plan.xml index f4b3313c76e..ce2e60c5d1e 100644 --- a/addons/gamification/view/plan.xml +++ b/addons/gamification/view/plan.xml @@ -70,12 +70,38 @@ - + - - - - + + @@ -90,7 +116,7 @@ - +