[IMP] use board view for sidebar
bzr revid: mat@openerp.com-20130325153953-zch12sfx62s5i6xc
This commit is contained in:
parent
0ef116ce06
commit
364612d0be
|
@ -316,12 +316,12 @@ class gamification_goal(osv.Model):
|
|||
'name': "Update %s" % goal.type_id.name,
|
||||
'id': goal_id,
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
if goal.computation_mode == 'manually':
|
||||
action['context'] = {'default_goal_id': goal_id, 'default_current': goal.current}
|
||||
action['res_model'] = 'gamification.goal.wizard'
|
||||
action['views'] = [[False, 'form']]
|
||||
action['target'] = 'new'
|
||||
else:
|
||||
action['res_model'] = goal.type_id.model_id.model
|
||||
action['views'] = [[False, 'tree']]
|
||||
|
|
|
@ -404,6 +404,88 @@ class gamification_goal_plan(osv.Model):
|
|||
self.write(cr, uid, ids, {'user_ids': [(4, user) for user in unified_subscription]}, context=context)
|
||||
return True
|
||||
|
||||
def get_board_goal_info(self, cr, uid, plan, subset_goal_ids=False, context=None):
|
||||
"""Get the list of latest goals for a plan, sorted by user ranking for each planline"""
|
||||
|
||||
goal_obj = self.pool.get('gamification.goal')
|
||||
planlines_boards = []
|
||||
(start_date, end_date) = start_end_date_for_period(plan.period)
|
||||
|
||||
for planline in plan.planline_ids:
|
||||
|
||||
domain = [
|
||||
('planline_id', '=', planline.id),
|
||||
('state', 'in', ('inprogress', 'inprogress_update',
|
||||
'reached', 'failed')),
|
||||
]
|
||||
|
||||
if subset_goal_ids:
|
||||
goal_ids = goal_obj.search(cr, uid, domain, context=context)
|
||||
common_goal_ids = [goal for goal in goal_ids if goal in subset_goal_ids]
|
||||
else:
|
||||
# if no subset goals, use the dates for restriction
|
||||
if start_date:
|
||||
domain.append(('start_date', '=', start_date.isoformat()))
|
||||
if end_date:
|
||||
domain.append(('end_date', '=', end_date.isoformat()))
|
||||
common_goal_ids = goal_obj.search(cr, uid, domain, context=context)
|
||||
|
||||
board_goals = [goal for goal in goal_obj.browse(cr, uid, common_goal_ids, context=context)]
|
||||
|
||||
# most complete first, current if same percentage (eg: if several 100%)
|
||||
sorted_board = enumerate(sorted(board_goals, key=lambda k: (k.completeness, k.current), reverse=True))
|
||||
planlines_boards.append({'goal_type': planline.type_id, 'board_goals': sorted_board})
|
||||
return planlines_boards
|
||||
|
||||
def get_indivual_goal_info(self, cr, uid, user_id, plan, subset_goal_ids=False, context=None):
|
||||
"""Get the list of latest goals of a user for a plan"""
|
||||
domain = [
|
||||
('plan_id', '=', plan.id),
|
||||
('user_id', '=', user_id),
|
||||
('state', 'in', ('inprogress', 'inprogress_update',
|
||||
'reached', 'failed')),
|
||||
]
|
||||
goal_obj = self.pool.get('gamification.goal')
|
||||
(start_date, end_date) = start_end_date_for_period(plan.period)
|
||||
|
||||
if subset_goal_ids:
|
||||
# use the domain for safety, don't want irrelevant report if wrong argument
|
||||
goal_ids = goal_obj.search(cr, uid, domain, context=context)
|
||||
related_goal_ids = [goal for goal in goal_ids if goal in subset_goal_ids]
|
||||
else:
|
||||
# if no subset goals, use the dates for restriction
|
||||
if start_date:
|
||||
domain.append(('start_date', '=', start_date.isoformat()))
|
||||
if end_date:
|
||||
domain.append(('end_date', '=', end_date.isoformat()))
|
||||
related_goal_ids = goal_obj.search(cr, uid, domain, context=context)
|
||||
|
||||
if len(related_goal_ids) == 0:
|
||||
print("no related_goal_ids")
|
||||
return False
|
||||
|
||||
values = {'goals': []}
|
||||
all_done = True
|
||||
for goal in goal_obj.browse(cr, uid, related_goal_ids, context=context):
|
||||
if goal.end_date:
|
||||
if goal.end_date < fields.date.today():
|
||||
# do not include goals of previous plan run
|
||||
continue
|
||||
else:
|
||||
all_done = False
|
||||
else:
|
||||
if goal.state == 'inprogress' or goal.state == 'inprogress_update':
|
||||
all_done = False
|
||||
|
||||
values['goals'].append(goal)
|
||||
|
||||
if all_done:
|
||||
# skip plans where all goal are done or failed
|
||||
print("all_done")
|
||||
return False
|
||||
else:
|
||||
return values
|
||||
|
||||
def report_progress(self, cr, uid, plan, context=None, users=False, subset_goal_ids=False):
|
||||
"""Post report about the progress of the goals
|
||||
|
||||
|
@ -423,43 +505,8 @@ class gamification_goal_plan(osv.Model):
|
|||
goal_obj = self.pool.get('gamification.goal')
|
||||
template_env = TemplateHelper()
|
||||
|
||||
(start_date, end_date) = start_end_date_for_period(plan.period)
|
||||
|
||||
if plan.visibility_mode == 'board':
|
||||
# generate a shared report
|
||||
planlines_boards = []
|
||||
|
||||
for planline in plan.planline_ids:
|
||||
|
||||
domain = [
|
||||
('planline_id', '=', planline.id),
|
||||
('state', 'in', ('inprogress', 'inprogress_update',
|
||||
'reached', 'failed')),
|
||||
]
|
||||
|
||||
if subset_goal_ids:
|
||||
goal_ids = goal_obj.search(cr, uid, domain, context=context)
|
||||
common_goal_ids = [goal for goal in goal_ids if goal in subset_goal_ids]
|
||||
else:
|
||||
# if no subset goals, use the dates for restriction
|
||||
if start_date:
|
||||
domain.append(('start_date', '=', start_date.isoformat()))
|
||||
if end_date:
|
||||
domain.append(('end_date', '=', end_date.isoformat()))
|
||||
common_goal_ids = goal_obj.search(cr, uid, domain, context=context)
|
||||
|
||||
board_goals = []
|
||||
for goal in goal_obj.browse(cr, uid, common_goal_ids, context=context):
|
||||
board_goals.append({
|
||||
'user': goal.user_id,
|
||||
'current':goal.current,
|
||||
'target_goal':goal.target_goal,
|
||||
'completeness':goal.completeness,
|
||||
})
|
||||
|
||||
# most complete first, current if same percentage (eg: if several 100%)
|
||||
sorted_board = enumerate(sorted(board_goals, key=lambda k: (k['completeness'], k['current']), reverse=True))
|
||||
planlines_boards.append({'goal_type': planline.type_id.name, 'board_goals': sorted_board})
|
||||
planlines_boards = self.get_board_goal_info(cr, uid, plan, subset_goal_ids, context)
|
||||
|
||||
body_html = template_env.get_template('group_progress.mako').render({'object': plan, 'planlines_boards': planlines_boards})
|
||||
|
||||
|
@ -477,33 +524,14 @@ class gamification_goal_plan(osv.Model):
|
|||
else:
|
||||
# generate individual reports
|
||||
for user in users or plan.user_ids:
|
||||
domain = [
|
||||
('plan_id', '=', plan.id),
|
||||
('user_id', '=', user.id),
|
||||
('state', 'in', ('inprogress', 'inprogress_update',
|
||||
'reached', 'failed')),
|
||||
]
|
||||
if subset_goal_ids:
|
||||
# use the domain for safety, don't want irrelevant report if wrong argument
|
||||
goal_ids = goal_obj.search(cr, uid, domain, context=context)
|
||||
related_goal_ids = [goal for goal in goal_ids if goal in subset_goal_ids]
|
||||
else:
|
||||
# if no subset goals, use the dates for restriction
|
||||
if start_date:
|
||||
domain.append(('start_date', '=', start_date.isoformat()))
|
||||
if end_date:
|
||||
domain.append(('end_date', '=', end_date.isoformat()))
|
||||
related_goal_ids = goal_obj.search(cr, uid, domain, context=context)
|
||||
|
||||
if len(related_goal_ids) == 0:
|
||||
values = self.get_indivual_goal_info(cr, uid, user.id, plan, subset_goal_ids, context=context)
|
||||
if not values:
|
||||
continue
|
||||
|
||||
variables = {
|
||||
'object': plan,
|
||||
'user': user,
|
||||
'goals': goal_obj.browse(cr, uid, related_goal_ids, context=context)
|
||||
}
|
||||
body_html = template_env.get_template('personal_progress.mako').render(variables)
|
||||
values['object'] = plan
|
||||
values['user'] = user,
|
||||
|
||||
body_html = template_env.get_template('personal_progress.mako').render(values)
|
||||
|
||||
self.message_post(cr, uid, plan.id,
|
||||
body=body_html,
|
||||
|
|
|
@ -24,38 +24,69 @@ class res_users_gamification_group(osv.Model):
|
|||
|
||||
def get_goals_todo_info(self, cr, uid, context=None):
|
||||
"""Return the list of goals assigned to the user, grouped by plan"""
|
||||
goals_info = []
|
||||
goal_obj = self.pool.get('gamification.goal')
|
||||
all_goals_info = []
|
||||
plan_obj = self.pool.get('gamification.goal.plan')
|
||||
|
||||
plan_ids = plan_obj.search(cr, uid, [('user_ids', 'in', uid)], context=context)
|
||||
for plan in plan_obj.browse(cr, uid, plan_ids, context=context):
|
||||
vals = {'name': plan.name, 'goals': []}
|
||||
# serialize goals info to be able to use it in javascript
|
||||
serialized_goals_info = {
|
||||
'name': plan.name,
|
||||
'visibility_mode': plan.visibility_mode
|
||||
}
|
||||
|
||||
goal_ids = goal_obj.search(cr, uid, [('user_id', '=', uid), ('plan_id', '=', plan.id)], context=context)
|
||||
all_done = True
|
||||
for goal in goal_obj.browse(cr, uid, goal_ids, context=context):
|
||||
if goal.last_update and goal.end_date and goal.last_update > goal.end_date:
|
||||
# do not include goals of previous plan run
|
||||
if plan.visibility_mode == 'board':
|
||||
# board report should be grouped by planline for all users
|
||||
print("board plan")
|
||||
goals_info = plan_obj.get_board_goal_info(cr, uid, plan, subset_goal_ids=False, context=context)
|
||||
|
||||
if not goals_info:
|
||||
print("skipping")
|
||||
continue
|
||||
|
||||
if goal.state == 'inprogress' or goal.state == 'inprogress_update':
|
||||
all_done = False
|
||||
serialized_goals_info['planlines'] = []
|
||||
for planline_board in goals_info:
|
||||
vals = {'type_name': planline_board['goal_type'].name,
|
||||
'type_description': planline_board['goal_type'].description,
|
||||
'type_condition': planline_board['goal_type'].condition,
|
||||
'goals': []}
|
||||
for goal in planline_board['board_goals']:
|
||||
vals['goals'].append({
|
||||
'rank': goal[0]+1,
|
||||
'id': goal[1].id,
|
||||
'user_name': goal[1].user_id.name,
|
||||
'state': goal[1].state,
|
||||
'completeness': goal[1].completeness,
|
||||
'current': goal[1].current,
|
||||
'target_goal': goal[1].target_goal,
|
||||
})
|
||||
serialized_goals_info['planlines'].append(vals)
|
||||
|
||||
vals['goals'].append({
|
||||
'id': goal.id,
|
||||
'type_name': goal.type_id.name,
|
||||
'type_condition': goal.type_id.condition,
|
||||
'type_description': goal.type_description,
|
||||
'state': goal.state,
|
||||
'completeness': goal.completeness,
|
||||
'computation_mode': goal.computation_mode,
|
||||
'current': goal.current,
|
||||
'target_goal': goal.target_goal,
|
||||
})
|
||||
# skip plans where all goal are done or failed
|
||||
if not all_done:
|
||||
goals_info.append(vals)
|
||||
return goals_info
|
||||
else:
|
||||
# individual report are simply a list of goal
|
||||
print("individual plan")
|
||||
goals_info = plan_obj.get_indivual_goal_info(cr, uid, uid, plan, subset_goal_ids=False, context=context)
|
||||
|
||||
if not goals_info:
|
||||
print("skipping")
|
||||
continue
|
||||
|
||||
serialized_goals_info['goals'] = []
|
||||
for goal in goals_info['goals']:
|
||||
serialized_goals_info['goals'].append({
|
||||
'id': goal.id,
|
||||
'type_name': goal.type_id.name,
|
||||
'type_condition': goal.type_id.condition,
|
||||
'type_description': goal.type_description,
|
||||
'state': goal.state,
|
||||
'completeness': goal.completeness,
|
||||
'computation_mode': goal.computation_mode,
|
||||
'current': goal.current,
|
||||
'target_goal': goal.target_goal,
|
||||
})
|
||||
|
||||
all_goals_info.append(serialized_goals_info)
|
||||
return all_goals_info
|
||||
|
||||
|
||||
class res_groups_gamification_group(osv.Model):
|
||||
|
|
|
@ -58,6 +58,13 @@
|
|||
.openerp .oe_mail_wall .oe_mail_wall_aside li {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.openerp .oe_mail_wall .oe_mail_wall_aside table {
|
||||
margin: 10px 0;
|
||||
}
|
||||
.openerp .oe_mail_wall .oe_mail_wall_aside table progress {
|
||||
width: 100%;
|
||||
display: inline-block;
|
||||
}
|
||||
.openerp .oe_mail_wall .oe_mail_wall_aside li progress {
|
||||
width: 80%;
|
||||
display: inline-block;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
openerp.gamification = function(instance) {
|
||||
console.log("Debug statement: file loaded");
|
||||
var QWeb = instance.web.qweb;
|
||||
|
||||
instance.gamification.Sidebar = instance.web.Widget.extend({
|
||||
|
@ -31,7 +30,6 @@ openerp.gamification = function(instance) {
|
|||
goal_action['action'] = res;
|
||||
});
|
||||
$.when(goal_action).done(function() {
|
||||
console.log(goal_action);
|
||||
var action_manager = new instance.web.ActionManager(this);
|
||||
action_manager.do_action(goal_action.action);
|
||||
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
<t t-name="gamification.goal_list_to_do">
|
||||
<div t-foreach="widget.goals_info.info" t-as="plan">
|
||||
<h3><t t-esc="plan.name"/></h3>
|
||||
<ul class="oe_goals_list">
|
||||
<t t-if="plan.visibility_mode == 'progressbar'">
|
||||
<ul class="oe_goals_list">
|
||||
<li t-foreach="plan.goals" t-as="goal">
|
||||
<a class="oe_goal_action" t-att-id="goal.id">
|
||||
<strong t-attf-class="#{goal.state == 'reached' ? 'oe_goal_reached' : goal.state == 'failed' ? 'oe_goal_failed' : ''}"><t t-esc="goal.type_name" /></strong>
|
||||
|
@ -26,7 +27,27 @@
|
|||
</a>
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
</ul>
|
||||
</t>
|
||||
<t t-if="plan.visibility_mode == 'board'">
|
||||
<table width="100%" border="1" t-foreach="plan.planlines" t-as="planline">
|
||||
<tr>
|
||||
<th colspan="4"><t t-esc="planline.goal_type"/></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Pers.</th>
|
||||
<th>compl.</th>
|
||||
<th>Current</th>
|
||||
</tr>
|
||||
<tr t-foreach="planline.goals" t-as="goal" t-attf-class="#{goal.completness >= 100 ? 'oe_bold' : ''}">
|
||||
<td><t t-esc="goal.rank" /></td>
|
||||
<td><t t-esc="goal.user_name" /></td>
|
||||
<td><progress t-att-value="goal.completeness" max="100" /></td>
|
||||
<td><t t-esc="goal.current" />/<t t-esc="goal.target_goal" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
</t>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>User</th>
|
||||
<th>Person</th>
|
||||
<th>Completeness</th>
|
||||
<th>Current</th>
|
||||
</tr>
|
||||
|
|
Loading…
Reference in New Issue