[ADD] monetary field

bzr revid: mat@openerp.com-20130326154553-t8cacle6s1oll4r9
This commit is contained in:
Martin Trigaux 2013-03-26 16:45:53 +01:00
parent 47eb0d6b25
commit 635df4028a
6 changed files with 57 additions and 15 deletions

View File

@ -40,6 +40,7 @@ class gamification_goal_type(osv.Model):
_columns = {
'name': fields.char('Type Name', required=True, translate=True),
'description': fields.text('Description'),
'monetary': fields.boolean('Use Currency', help="The target and current value used is monetary"),
'unit': fields.char('Unit',
help="The unit of the target and current values", translate=True),
'computation_mode': fields.selection([
@ -76,13 +77,14 @@ class gamification_goal_type(osv.Model):
help='Sequence number for ordering',
required=True),
}
_order = 'sequence'
_defaults = {
'sequence': 1,
'condition': 'higher',
'computation_mode':'manually',
'domain':"[]",
'computation_mode': 'manually',
'domain': "[]",
'monetary': False,
}

View File

@ -214,6 +214,8 @@
<group string="General">
<field name="description"/>
<field name="condition"/>
<field name="monetary" />
<field name="unit" attrs="{'invisible': [('monetary', '=', True)]}"/>
</group>
<group string="Computation">
<field name="computation_mode"/>

View File

@ -32,8 +32,10 @@ class res_users_gamification_group(osv.Model):
# serialize goals info to be able to use it in javascript
serialized_goals_info = {
'name': plan.name,
'visibility_mode': plan.visibility_mode
'visibility_mode': plan.visibility_mode,
}
user = self.browse(cr, uid, uid, context=context)
serialized_goals_info['currency'] = user.company_id.currency_id.id
if plan.visibility_mode == 'board':
# board report should be grouped by planline for all users
@ -49,6 +51,9 @@ class res_users_gamification_group(osv.Model):
vals = {'type_name': planline_board['goal_type'].name,
'type_description': planline_board['goal_type'].description,
'type_condition': planline_board['goal_type'].condition,
'type_computation_mode': planline_board['goal_type'].computation_mode,
'type_monetary': planline_board['goal_type'].monetary,
'type_unit': planline_board['goal_type'].unit,
'goals': []}
for goal in planline_board['board_goals']:
vals['goals'].append({
@ -76,8 +81,10 @@ class res_users_gamification_group(osv.Model):
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,
'type_condition': goal.type_id.condition,
'type_monetary': goal.type_id.monetary,
'type_unit': goal.type_id.unit,
'state': goal.state,
'completeness': goal.completeness,
'computation_mode': goal.computation_mode,

View File

@ -64,13 +64,31 @@ openerp.gamification = function(instance) {
self.goals_info['info'] = res
});
$.when(goals_info).done(function() {
console.log(self.goals_info.info);
if(self.goals_info.info.length > 0){
self.render_template_replace(self.$el.filter(".oe_gamification_goal"),'gamification.goal_list_to_do');
self.$el.find('.oe_type_description').hide();
self.render_money_fields(self.goals_info.info[0].currency);
}
});
},
render_money_fields: function(currency_id) {
var self = this;
self.dfm = new instance.web.form.DefaultFieldManager(self);
self.$el.find(".oe_goal_field_monetary").each(function() {
money_field = new instance.web.form.FieldMonetary(self.dfm, {
attrs: {
modifiers: '{"readonly": true}'
}
});
money_field.set('currency', currency_id);
money_field.get_currency_info();
money_field.set('value', parseInt($(this).text()));
console.log(money_field.get('value'));
money_field.replace($(this));
console.log(money_field.$el.html());
});
}
});
instance.mail.Widget.include({

View File

@ -9,19 +9,25 @@
<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" t-att-title="goal.type_description">
<strong t-attf-class="#{goal.state == 'reached' ? 'oe_goal_reached' : goal.state == 'failed' ? 'oe_goal_failed' : ''}"><t t-esc="goal.type_name" /></strong>
</a>
<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>
<t t-if="goal.computation_mode == 'manually'">
<a class="oe_goal_action" t-att-id="goal.id">modify</a>
</t>
<!-- <t t-if="goal.type_description">
<a class="oe_show_description" t-att-id="goal.id">?</a>
<p t-att-class="'oe_type_description oe_type_description_' + goal.id"><t t-esc="goal.type_description" /></p>
</t> -->
<p>
<t t-if="goal.type_condition == 'higher'">
<t t-esc="goal.current" />/<span t-attf-class="#{goal.type_monetary ? 'oe_goal_field_monetary' : ''}"><t t-esc="goal.target_goal"/></span>
<t t-if="goal.type_unit"><t t-esc="goal.type_unit"/></t>
<progress t-att-value="goal.completeness" max="100"/>
</t>
<t t-if="goal.type_condition == 'lower'">
<t t-esc="goal.current" /> (less than <t t-esc="goal.target_goal"/>)
<t t-esc="goal.current" /> (less than
<span t-attf-class="#{goal.type_monetary ? 'oe_goal_field_monetary' : ''}"><t t-esc="goal.target_goal"/></span>
<t t-if="goal.type_unit"><t t-esc="goal.type_unit"/></t>
)
</t>
<!-- <a class="oe_update_goal" rol="button" t-attf-id="{goal.id}">
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QMWCRMG1/sI6gAAAR1JREFUKM910T9L1nEUBfCPP39S4pAuba0FDoEhbc6CLkEUvQMb7hKFDU29gCYPNFUoiH9WRwedhBB8CS1Bg7WEKKH12PJ94GnoTJfDOece7h3TkGQCk+hxVVVnjZ/Gz6q6TqJLMvTcxRG+4l0T38MXPE0yVlW6qhoa5jCLG/jQuEXM4BOWk+hb0n2sYQVdVX1uhvc4xRbe4rBPMo4n+I7NqroYqXmFXTzEC9zpcbOt3m8CIzVhkGSvGR50GMdtDPwfZzjHoGvCUyygH9YZqQW3MIXjHr9wgFU8axdRVZJMocNjHONbV1W/sYMf+Ig3SSZb8kts4xFeV9VF19JO8GpEdNnmFSxhv6oO8M+n1zGP51X1J8lsS1/FRpIe/gIpymSOkJCtuQAAAABJRU5ErkJggg==" alt="update" />
@ -33,7 +39,11 @@
<t t-if="plan.visibility_mode == 'board'">
<table width="100%" border="1" t-foreach="plan.planlines" t-as="planline">
<tr>
<th colspan="4" t-attf-title="#{planline.type_description ? planline.type_description : ''}"><t t-esc="planline.type_name"/>
<th colspan="4" t-attf-title="#{planline.type_description ? planline.type_description : ''}">
<t t-esc="planline.type_name"/>
<t t-if="planline.type_computation_mode == 'manually'">
<a class="oe_goal_action" t-att-id="goal.id">modify</a>
</t>
</th>
</tr>
<tr>
@ -46,7 +56,10 @@
<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>
<td>
<t t-esc="goal.current" />/<span t-attf-class="#{planline.type_monetary ? 'oe_goal_field_monetary' : ''}"><t t-esc="goal.target_goal"/></span>
<t t-if="planline.type_unit"><t t-esc="planline.type_unit"/></t>
</td>
</tr>
</table>
</t>

View File

@ -7,7 +7,7 @@
<field name="name">Total Invoiced</field>
<field name="description"></field>
<field name="computation_mode">sum</field>
<field name="unit"></field>
<field name="monetary">True</field>
<field name="model_id" eval="ref('account.model_account_invoice_report')" />
<field name="field_id" eval="ref('account.field_account_invoice_report_price_total')" />
<field name="field_date_id" eval="ref('account.field_account_invoice_report_day')" />
@ -92,7 +92,7 @@
<field name="name">Total Paid Sales Orders</field>
<field name="description">Based on the invoice date</field>
<field name="computation_mode">count</field>
<field name="unit"></field>
<field name="monetary">True</field>
<field name="model_id" eval="ref('account.model_account_invoice_report')" />
<field name="field_id" eval="ref('account.field_account_invoice_report_price_total')" />
<field name="field_date_id" eval="ref('account.field_account_invoice_report_day')" />
@ -115,7 +115,7 @@
<field name="description">The total refunded value is a negative value. Validated when higher (min refunded).</field>
<field name="computation_mode">sum</field>
<field name="condition">higher</field>
<field name="unit"></field>
<field name="monetary">True</field>
<field name="model_id" eval="ref('account.model_account_invoice_report')" />
<field name="field_id" eval="ref('account.field_account_invoice_report_price_total')" />
<field name="field_date_id" eval="ref('account.field_account_invoice_report_day')" />