[IMP] gamification: better consistency for plan

bzr revid: mat@openerp.com-20130227084608-79t5fyjzweq5zq1j
This commit is contained in:
Martin Trigaux
2013-02-27 09:46:08 +01:00
parent 6cc39b566a
commit ce777dde1c
2 changed files with 47 additions and 11 deletions
+15 -5
View File
@@ -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
+32 -6
View File
@@ -70,12 +70,38 @@
<group colspan="4">
<field name="period" attrs="{'readonly':[('state','!=','draft')]}"/>
<field name="remind_update_delay"/>
<field name="visibility_mode"/>
</group>
<group string="Report">
<field name="report_message_group_id" />
<field name="report_message_frequency" attrs="{'invisible':[('report_message_group_id','=', False)], 'required':[('report_message_group_id','=', False)]}"/>
<field name="report_header" attrs="{'invisible':[('report_message_group_id','=', False)]}"/>
<group string="Notify" colspan="4">
<label for="visibility_mode"/>
<div>
<field name="visibility_mode" colspan="2" />
<group name="visibility_mode_help" class="oe_grey oe_edit_only" colspan="1">
<p attrs="{'invisible': [('visibility_mode','!=','board')]}">
In Leaderboard mode, the reports will contain the progress of users of this plan.
</p>
<p attrs="{'invisible': [('visibility_mode','!=','progressbar')]}">
In Personal Progressbar mode, the progress of each user can only be seen by himself and the followers of this plan.
</p>
</group>
</div>
<field name="report_message_frequency" />
<field name="report_header" />
<label for="report_message_group_id"/>
<div>
<field name="report_message_group_id" />
<group name="report_help" class="oe_grey oe_edit_only" col="2" colspan="2">
<p attrs="{'invisible': [('report_message_group_id','!=',False)]}">
Select a group that will receive a copy of the reports.
</p>
<p attrs="{'invisible': [('report_message_group_id','=',False)]}">
A copy of the report that user recieve will be sent to this group.
</p>
</group>
</div>
</group>
</group>
@@ -90,7 +116,7 @@
<group string="Subscription">
<group colspan="4">
<field name="autojoin_group_id" string="Group" />
<field name="autojoin_group_id" />
</group>
<group colspan="4">
<field name="user_ids" widget="many2many_kanban">