[IMP] remove many2many display and clean ups

bzr revid: mat@openerp.com-20130422133355-ffhglxrkdia2hz4j
This commit is contained in:
Martin Trigaux 2013-04-22 15:33:55 +02:00
parent 38f205ef32
commit 8b400f7e88
10 changed files with 40 additions and 174 deletions

View File

@ -57,7 +57,6 @@ Both goals and badges are flexibles and can be adapted to a large range of modul
'js': [
'static/src/js/gamification.js',
'static/src/js/justgage.js',
'static/src/js/jquery.sparkline.2.1.1.min.js',
],
'qweb': ['static/src/xml/gamification.xml'],
}

View File

@ -138,11 +138,17 @@ class gamification_goal(osv.Model):
"""Return the percentage of completeness of the goal, between 0 and 100"""
res = {}
for goal in self.browse(cr, uid, ids, context):
if goal.current > 0:
res[goal.id] = min(100, round(100.0 * goal.current / goal.target_goal, 2))
else:
res[goal.id] = 0.0
# if goal.computation_mode == 'higher':
if goal.current > 0:
res[goal.id] = min(100, round(100.0 * goal.current / goal.target_goal, 2))
else:
res[goal.id] = 0.0
# else:
# # a goal 'lower than' has only two values possible: 0 or 100%
# if goal.current < goal.target_goal:
# res[goal.id] = 100.0
# else:
# res[goal.id] = 0.0
return res
def on_change_type_id(self, cr, uid, ids, type_id=False, context=None):

View File

@ -59,7 +59,7 @@
<!-- plans -->
<record model="gamification.goal.plan" id="plan_base_discover">
<field name="name">Discover OpenERP</field>
<field name="name">Set up your Profile</field>
<field name="period">once</field>
<field name="visibility_mode">progressbar</field>
<field name="report_message_frequency">never</field>

View File

@ -106,46 +106,6 @@ class gamification_goal_plan(osv.Model):
res[plan.id] = len(plan.planline_ids)
return res
def _reward_id_many(self, cr, uid, ids, field_name, arg, context=None):
"""Return the field reward_id as a many2many field"""
res = dict.fromkeys(ids, 0)
for plan in self.browse(cr, uid, ids, context):
if plan.reward_id:
res[plan.id] = [plan.reward_id.id]
else:
res[plan.id] = []
return res
def _reward_first_id_many(self, cr, uid, ids, field_name, arg, context=None):
"""Return the field reward_first_id as a many2many field"""
res = dict.fromkeys(ids, 0)
for plan in self.browse(cr, uid, ids, context):
if plan.reward_first_id:
res[plan.id] = [plan.reward_first_id.id]
else:
res[plan.id] = []
return res
def _reward_second_id_many(self, cr, uid, ids, field_name, arg, context=None):
"""Return the field reward_second_id as a many2many field"""
res = dict.fromkeys(ids, 0)
for plan in self.browse(cr, uid, ids, context):
if plan.reward_second_id:
res[plan.id] = [plan.reward_second_id.id]
else:
res[plan.id] = []
return res
def _reward_third_id_many(self, cr, uid, ids, field_name, arg, context=None):
"""Return the field reward_third_id as a many2many field"""
res = dict.fromkeys(ids, 0)
for plan in self.browse(cr, uid, ids, context):
if plan.reward_third_id:
res[plan.id] = [plan.reward_third_id.id]
else:
res[plan.id] = []
return res
_columns = {
'name': fields.char('Challenge Name', required=True, translate=True),
'description': fields.text('Description', translate=True),
@ -195,11 +155,6 @@ class gamification_goal_plan(osv.Model):
'reward_second_id': fields.many2one('gamification.badge', string="For 2nd user"),
'reward_third_id': fields.many2one('gamification.badge', string="For 3rd user"),
'reward_failure': fields.boolean('Reward Bests if not Succeeded?'),
# same fields but as many2many to be able to display as kanban
'reward_id_many': fields.function(_reward_id_many, type="many2many", relation="gamification.badge", string="For Every Succeding User"),
'reward_first_id_many': fields.function(_reward_first_id_many, type="many2many", relation="gamification.badge", string="For 1st user"),
'reward_second_id_many': fields.function(_reward_second_id_many, type="many2many", relation="gamification.badge", string="For 2nd user"),
'reward_third_id_many': fields.function(_reward_third_id_many, type="many2many", relation="gamification.badge", string="For 3rd user"),
'visibility_mode': fields.selection([
('progressbar', 'Individual Goals'),
@ -261,12 +216,6 @@ class gamification_goal_plan(osv.Model):
if new_group:
self.plan_subscribe_users(cr, uid, ids, [user.id for user in new_group.users], context=context)
if 'proposed_user_ids' in vals:
for plan in self.browse(cr, uid, ids, context=context):
puser_ids = [puser.id for puser in plan.proposed_user_ids]
if len([user for user in plan.user_ids if user.id in puser_ids]) > 0:
raise osv.except_osv(_('Error!'), _('Can not propose a challenge to an user already assigned to it'))
return write_res
##### Update #####

View File

@ -233,19 +233,17 @@
<field name="model">gamification.goal.plan</field>
<field name="arch" type="xml">
<form string="Challenge" version="7.0">
<field name="reward_id" invisible="1"/>
<field name="reward_first_id" invisible="1"/>
<field name="reward_second_id" invisible="1"/>
<field name="reward_third_id" invisible="1"/>
<field name="reward_failure" invisible="1"/>
<div class="oe_title">
<h1><field name="name" nolabel="1" readonly="1"/></h1>
</div>
<field name="description" nolabel="1" readonly="1" />
<div attrs="{'invisible': ['|',('start_date','!=', False),('end_date','!=', False)]}" class="oe_grey">
This challenge has no starting and end date specified, it will be closed
</div>
The challenge is running from <field name="start_date" class="oe_inline" readonly="1" /> to <field name="end_date" class="oe_inline" readonly="1" />
<group>
<field name="start_date" readonly="1" />
<field name="end_date" readonly="1" />
<field name="user_ids" string="Participating" readonly="1" widget="many2many_tags" />
<field name="proposed_user_ids" string="Invited" readonly="1" widget="many2many_tags" />
</group>
<group string="Goals">
<field name="planline_ids" nolabel="1" readonly="1" colspan="4">
<tree string="Planline List" version="7.0" editable="bottom" >
@ -262,64 +260,19 @@
There is no reward upon completion of this challenge.
</div>
<group attrs="{'invisible': [('reward_id','=',False),('reward_first_id','=',False)]}">
<field name="reward_id_many" readonly="1" attrs="{'invisible': [('reward_first_id','=', False)]}" widget="many2many_kanban">
<kanban>
<field name="image"/>
<templates>
<t t-name="kanban-box"><div class="oe_kanban_record">
<div class="oe_kanban_badge_avatars"><img t-att-src="kanban_image('gamification.badge', 'image', record.image.raw_value)" t-att-title="record.name.value" width="32" height="32" /></div>
<field name="name"/>
</div></t>
</templates>
</kanban>
</field>
<field name="reward_first_id_many" readonly="1" attrs="{'invisible': [('reward_first_id','=', False)]}" widget="many2many_kanban">
<kanban>
<field name="image"/>
<templates>
<t t-name="kanban-box"><div class="oe_kanban_record">
<div class="oe_kanban_badge_avatars"><img t-att-src="kanban_image('gamification.badge', 'image', record.image.raw_value)" t-att-title="record.name.value" width="32" height="32" /></div>
<field name="name"/>
</div></t>
</templates>
</kanban>
</field>
<field name="reward_second_id_many" readonly="1" attrs="{'invisible': [('reward_second_id','=', False)]}" widget="many2many_kanban">
<kanban>
<field name="image"/>
<templates>
<t t-name="kanban-box"><div class="oe_kanban_record">
<div class="oe_kanban_badge_avatars"><img t-att-src="kanban_image('gamification.badge', 'image', record.image.raw_value)" t-att-title="record.name.value" width="32" height="32" /></div>
<field name="name"/>
</div></t>
</templates>
</kanban>
</field>
<field name="reward_third_id_many" readonly="1" attrs="{'invisible': [('reward_third_id','=', False)]}" widget="many2many_kanban">
<kanban>
<field name="image"/>
<templates>
<t t-name="kanban-box"><div class="oe_kanban_record">
<div class="oe_kanban_badge_avatars"><img t-att-src="kanban_image('gamification.badge', 'image', record.image.raw_value)" t-att-title="record.name.value" width="32" height="32" /></div>
<field name="name"/>
</div></t>
</templates>
</kanban>
</field>
<field name="reward_id" readonly="1" attrs="{'invisible': [('reward_first_id','=', False)]}" />
<field name="reward_first_id" readonly="1" attrs="{'invisible': [('reward_first_id','=', False)]}" />
<field name="reward_second_id" readonly="1" attrs="{'invisible': [('reward_second_id','=', False)]}" />
<field name="reward_third_id" readonly="1" attrs="{'invisible': [('reward_third_id','=', False)]}" />
</group>
<div class="oe_grey" attrs="{'invisible': [('reward_failure','=',False)]}">
Even if the challenge is failed, best challengers will be rewarded
</div>
</group>
<group string="Challengers">
<div class="oe_grey" colspan="4">Who will you be competiting with ?<br/><br/></div>
<field name="user_ids" string="Participating" readonly="1" widget="many2many_tags" />
<field name="proposed_user_ids" string="Invited" readonly="1" widget="many2many_tags" />
</group>
<footer>
<center>
<button string="Accept" type="object" name="accept_challenge" class="oe_highlight" />
<button string="Discard" type="object" name="discard_challenge"/> or
<button string="Reject" type="object" name="discard_challenge"/> or
<button string="reply later" special="cancel" class="oe_link"/>
</center>
</footer>

View File

@ -80,11 +80,8 @@
}
/* mark goal as completed */
.openerp .oe_mail_wall_aside .oe_gamification_goal .oe_goal_reached {
/*text-decoration: line-through;*/
color: rgb(17, 95, 17);
}
.openerp .oe_mail_wall_aside .oe_gamification_goal .oe_goal_failed {
color: rgb(95, 17, 17);
text-decoration: line-through;
color: rgb(138, 137, 137);
}
.openerp .oe_mail_wall_aside .oe_goals_list {
@ -94,7 +91,7 @@
width: 200px;
}
.openerp .oe_mail_wall .oe_mail_wall_aside .oe_goal_outer_box {
background: rgb(173, 219, 178);
background: rgb(213, 213, 213);
min-height: 32px;
}
.openerp .oe_mail_wall_aside .oe_goals_list .oe_goal_inner_box {
@ -110,8 +107,12 @@
.openerp .oe_mail_wall_aside .oe_goals_list .oe_goal_inner_box strong {
padding-left: 5px;
}
.openerp .oe_mail_wall .oe_mail_wall_aside table {
.openerp .oe_mail_wall .oe_mail_wall_aside table.oe_goals_list {
margin: 10px 0;
border: solid 1px white;
}
.openerp .oe_mail_wall .oe_mail_wall_aside .oe_goals_list thead {
font-weight: normal;
}
.oe_mail_wall_aside .oe_goals_list tbody tr:nth-child(even) {
background-color: #fff;
@ -122,6 +123,7 @@
border: none;
}
.openerp .oe_mail_wall_aside .oe_goals_list thead th {
font-weight: normal;
padding: 5px;
}
.openerp .oe_mail_wall_aside .oe_goals_list tbody tr {

View File

@ -79,8 +79,6 @@ openerp.gamification = function(instance) {
if(self.goals_info.info.length > 0){
self.render_template_replace(self.$el.filter(".oe_gamification_goal"),'gamification.goal_list_to_do');
self.render_money_fields(self.goals_info.info[0].currency);
// self.render_progress_bars();
self.render_piechars();
self.render_user_avatars();
} else {
self.$el.filter(".oe_gamification_goal").hide();
@ -117,29 +115,6 @@ openerp.gamification = function(instance) {
money_field.replace($(this));
});
},
render_progress_bars: function() {
var self = this;
dfm = new instance.web.form.DefaultFieldManager(self);
// Generate a FieldMonetary for each .oe_goal_field_monetary
self.$(".oe_goal_progress").each(function() {
progress_field = new instance.web.form.FieldProgressBar(dfm, {
attrs: {
modifiers: '{"readonly": true}'
}
});
progress_field.set('value', $(this).attr('value'));
progress_field.replace($(this));
});
},
render_piechars: function() {
var self = this;
self.$(".oe_goal_sparkline_piechart").each(function() {
var completeness = parseInt( $(this).attr('data-completeness'), 10);
var values = [completeness, 100-completeness];
$(this).sparkline(values, {type: 'pie', offset: 180, sliceColors: ['#0B610B','#F78181']});
});
},
render_user_avatars: function() {
var self = this;
self.$(".oe_user_avatar").each(function() {

View File

@ -11,13 +11,12 @@
<t t-if="plan.visibility_mode == 'progressbar'">
<div class="oe_goals_list">
<div class="oe_goal_outer_box" t-foreach="plan.goals" t-as="goal" t-attf-style="width: #{goal.completeness}%;">
<div t-attf-class="#{goal.type_display == 'progress' ? 'oe_goal_outer_box' : ''}" t-foreach="plan.goals" t-as="goal" t-attf-style="#{goal.type_display == 'progress' ? 'width: '+goal.completeness+'%;' : ''}">
<div class="oe_goal_inner_box">
<!-- <span class="oe_goal_sparkline_piechart" t-att-data-completeness="goal.completeness"></span> -->
<strong t-attf-class="#{goal.state == 'reached' ? 'oe_goal_reached' : goal.state == 'failed' ? 'oe_goal_failed' : ''}" t-att-title="goal.type_description"><t t-esc="goal.type_name" /></strong>
<strong t-attf-class="#{goal.state == 'reached' ? 'oe_goal_reached' : ''}" t-att-title="goal.type_description"><t t-esc="goal.type_name" /></strong>
<t t-if="goal.computation_mode == 'manually' or goal.type_action">
<a class="oe_goal_action oe_e" t-att-id="goal.id">&amp;</a>
</t>
</t><br/>
<t t-if="goal.type_display == 'progress'">
<t t-if="goal.type_condition == 'higher'">
@ -38,11 +37,11 @@
</div>
</t>
<t t-if="plan.visibility_mode == 'board'">
<table width="100%" border="1" t-foreach="plan.planlines" t-as="planline" class="oe_goals_list">
<table t-foreach="plan.planlines" t-as="planline" class="oe_goals_list">
<thead>
<tr>
<th colspan="4" t-attf-title="#{planline.type_description ? planline.type_description : ''}">
<t t-esc="planline.type_name"/>
<strong><t t-esc="planline.type_name"/></strong><br/>
(Goal: max <span t-attf-class="#{planline.type_monetary ? 'oe_goal_field_monetary' : ''}"><t t-esc="planline.target_goal" /></span><t t-if="planline.type_unit"> <t t-esc="planline.type_unit"/></t>)
<t t-if="planline.type_computation_mode == 'manually' or planline.type_action">
<a class="oe_goal_action oe_e" t-att-id="planline.own_goal_id">&amp;</a>
@ -55,11 +54,10 @@
<div style="background: #fff;">
<th class="col0"><t t-esc="goal.rank" /></th>
<td><img class="oe_user_avatar" t-attf-alt="#{goal.user_name}" t-attf-data-id="#{goal.user_id}"/></td>
<td class="col1" style="width:200px;">
<td class="col1" style="width:180px;">
<div class="oe_goal_outer_box" t-attf-style="width: #{goal.completeness}%;">
<div class="oe_goal_inner_box">
<!-- <span class="oe_goal_sparkline_piechart" t-att-data-completeness="goal.completeness"></span> -->
<t t-esc="goal.user_name"/>
<t t-esc="goal.user_name"/><br/>
<span t-attf-class="#{planline.type_monetary ? 'oe_goal_field_monetary' : ''}"><t t-esc="goal.current" /></span><t t-if="planline.type_unit"> <t t-esc="planline.type_unit"/></t>
</div>
</div>
@ -77,7 +75,7 @@
<em>You have been invited to the following challenges:</em>
<ul t-foreach="widget.challenge_suggestions.info" t-as="challenge" class="oe_challenge">
<li>
<strong><t t-esc="challenge.name"/></strong> <a class="oe_challenge_reply" t-attf-title="#{challenge.description.value ? challenge.description.value : ''}" t-attf-id="{challenge.id}">accept?</a>
<strong><a class="oe_challenge_reply" t-attf-title="#{challenge.description.value ? challenge.description.value : ''}" t-attf-id="{challenge.id}" title="more details..."><t t-esc="challenge.name"/></a></strong>
</li>
</ul>
</t>

View File

@ -124,7 +124,6 @@
<!-- plans -->
<record model="gamification.goal.plan" id="plan_crm_sale">
<field name="name">Monthly Sales Targets</field>
@ -150,11 +149,6 @@
<field name="target_goal">20000</field>
<field name="plan_id" eval="ref('plan_crm_sale')" />
</record>
<record model="gamification.goal.planline" id="planline_crm_sale5">
<field name="type_id" eval="ref('type_crm_nbr_customer_refunds')" />
<field name="target_goal">4</field>
<field name="plan_id" eval="ref('plan_crm_sale')" />
</record>
<record model="gamification.goal.planline" id="planline_crm_marketing1">

View File

@ -18,16 +18,6 @@
<field name="target_goal">2000</field>
<field name="state">inprogress</field>
</record>
<record model="gamification.goal" id="goal_crm_sale5">
<field name="type_id" eval="ref('type_crm_nbr_customer_refunds')" />
<field name="user_id" eval="ref('base.user_demo')" />
<field name="planline_id" eval="ref('planline_crm_sale5')" />
<field name="start_date" eval="time.strftime('2013-03-01')" />
<field name="end_date" eval="time.strftime('2013-03-31')" />
<field name="target_goal">4</field>
<field name="state">inprogress</field>
</record>
</data>
</openerp>