[ADD] gamification: add autosubscription from groups
bzr revid: mat@openerp.com-20130222114421-dueg3178wdtv2gk8
This commit is contained in:
parent
be75098490
commit
4c3ff4303a
|
@ -1 +1,2 @@
|
|||
import goal
|
||||
import goal
|
||||
import res_users
|
|
@ -24,6 +24,8 @@ from openerp.tools.safe_eval import safe_eval
|
|||
|
||||
from datetime import date, timedelta
|
||||
import calendar
|
||||
import itertools
|
||||
|
||||
|
||||
class gamification_goal_type(osv.Model):
|
||||
"""Goal type definition
|
||||
|
@ -112,7 +114,6 @@ class gamification_goal(osv.Model):
|
|||
return {'value':{'type_id': False}}
|
||||
goal_type = goal_type.browse(cr, uid, type_id, context=context)
|
||||
ret = {'value' : {'computation_mode' : goal_type.computation_mode}}
|
||||
print(ret)
|
||||
return ret
|
||||
|
||||
_columns = {
|
||||
|
@ -168,6 +169,7 @@ class gamification_goal(osv.Model):
|
|||
"""Update every goal in progress"""
|
||||
if not ids:
|
||||
ids = self.search(cr, uid, [('state', 'in', ('inprogress','inprogress_update', 'reached'))])
|
||||
|
||||
return self.update(cr, uid, ids, context=context)
|
||||
|
||||
def update(self, cr, uid, ids, context=None):
|
||||
|
@ -247,11 +249,10 @@ class gamification_goal(osv.Model):
|
|||
('user_id', '=', user_id),
|
||||
('start_date', '=', start_date.isoformat())]
|
||||
goal_ids = obj.search(cr, uid, domain, context=context)
|
||||
print(domain, goal_ids)
|
||||
if len(goal_ids) > 0:
|
||||
# already exist, skip
|
||||
return True
|
||||
print("creating goal for", planline_id, user_id, start_date)
|
||||
|
||||
planline = self.pool.get('gamification.goal.planline').browse(cr, uid, planline_id, context)
|
||||
values = {
|
||||
'type_id':planline.type_id.id,
|
||||
|
@ -399,7 +400,7 @@ class gamification_goal_plan(osv.Model):
|
|||
if not ids:
|
||||
ids = self.search(cr, uid, [('state', '=', 'inprogress'),
|
||||
('period', '!=', 'once')])
|
||||
print("_update_all plans", ids)
|
||||
|
||||
return self.generate_goals_from_plan(cr, uid, ids, context=context)
|
||||
|
||||
def action_start(self, cr, uid, ids, context=None):
|
||||
|
@ -478,6 +479,22 @@ class gamification_goal_plan(osv.Model):
|
|||
|
||||
return True
|
||||
|
||||
|
||||
def plan_subscribe_users(self, cr, uid, ids, user_ids, context=None):
|
||||
""" Add the following users to plans
|
||||
|
||||
:param ids: ids of plans to which the users will be added
|
||||
:param user_ids: ids of the users to add"""
|
||||
|
||||
print("subscibe users", ids, user_ids)
|
||||
for plan in self.browse(cr,uid, ids, context):
|
||||
subscription = [user.id for user in plan.user_ids]
|
||||
subscription.extend(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
|
||||
|
||||
|
||||
class gamification_goal_planline(osv.Model):
|
||||
"""Gamification goal planline
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
from openerp.osv import osv
|
||||
|
||||
class res_users_gamification_group(osv.Model):
|
||||
""" Update of res.users class
|
||||
- if adding groups to an user, check gamification.goal.plan linked to
|
||||
this group, and the user. This is done by overriding the write method.
|
||||
"""
|
||||
_name = 'res.users'
|
||||
_inherit = ['res.users']
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
print("Overwrite res_users_gamification_group", ids)
|
||||
write_res = super(res_users_gamification_group, self).write(cr, uid, ids, vals, context=context)
|
||||
if vals.get('groups_id'):
|
||||
# form: {'group_ids': [(3, 10), (3, 3), (4, 10), (4, 3)]} or {'group_ids': [(6, 0, [ids]}
|
||||
user_group_ids = [command[1] for command in vals['groups_id'] if command[0] == 4]
|
||||
user_group_ids += [id for command in vals['groups_id'] if command[0] == 6 for id in command[2]]
|
||||
|
||||
goal_plan_obj = self.pool.get('gamification.goal.plan')
|
||||
plan_ids = goal_plan_obj.search(cr, uid, [('autojoin_group_id', 'in', user_group_ids)], context=context)
|
||||
|
||||
goal_plan_obj.plan_subscribe_users(cr, uid, plan_ids, ids, context=context)
|
||||
return write_res
|
||||
|
||||
class res_groups_gamification_group(osv.Model):
|
||||
""" Update of res.groups class
|
||||
- if adding users from a group, check gamification.goal.plan linked to
|
||||
this group, and the user. This is done by overriding the write method.
|
||||
"""
|
||||
_name = 'res.groups'
|
||||
_inherit = 'res.groups'
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
print("Overwrite res_groups_gamification_group", ids)
|
||||
write_res = super(res_groups_gamification_group, self).write(cr, uid, ids, vals, context=context)
|
||||
if vals.get('users'):
|
||||
# form: {'group_ids': [(3, 10), (3, 3), (4, 10), (4, 3)]} or {'group_ids': [(6, 0, [ids]}
|
||||
user_ids = [command[1] for command in vals['users'] if command[0] == 4]
|
||||
user_ids += [id for command in vals['users'] if command[0] == 6 for id in command[2]]
|
||||
|
||||
goal_plan_obj = self.pool.get('gamification.goal.plan')
|
||||
plan_ids = goal_plan_obj.search(cr, uid, [('autojoin_group_id', 'in', ids)], context=context)
|
||||
|
||||
goal_plan_obj.plan_subscribe_users(cr, uid, plan_ids, user_ids, context=context)
|
||||
return write_res
|
|
@ -67,7 +67,7 @@
|
|||
</group>
|
||||
<group string="Data">
|
||||
<field name="target_goal"/>
|
||||
<field name="current"/>
|
||||
<field name="current" attrs="{'readonly':[('computation_mode','!=','manually')]}"/>
|
||||
</group>
|
||||
</group>
|
||||
</sheet>
|
||||
|
|
Loading…
Reference in New Issue