Browse Source

[FIX] rounding

pull/1/head
Ivan Yelizariev 10 years ago
parent
commit
42819fe077
  1. 1
      models.py
  2. 1
      static/src/css/main.css
  3. 28
      static/src/js/main.js
  4. 8
      static/src/xml/main.xml
  5. 1
      views.xml

1
models.py

@ -76,6 +76,7 @@ Slice - use "domain" for total and "won_domain" for target
'type': self.type,
'model': self.model_id.model,
'domain': str(domain),
'precision': self.precision,
}
obj = self.env[self.model_id.model]
if self.type == 'list':

1
static/src/css/main.css

@ -17,6 +17,7 @@
.openerp .oe_mail_wall .oe_goal .oe_goals_list .oe_cell.oe_goal_current .oe_form_field_monetary{
font-weight: normal;
font-size: 70%;
white-space: nowrap;
}
.openerp .oe_mail_wall .oe_goal .oe_goals_list .oe_cell.oe_goal_current .oe_form_field_monetary .oe_form_char_content {
font-weight: bold;

28
static/src/js/main.js

@ -64,6 +64,7 @@ openerp.mail_wall_widgets = function(instance) {
_.each(result, function(item){
var $item = $(QWeb.render(self.widget_templates[item.model], {info: item}));
self.render_money_fields($item);
self.render_float_fields($item);
//self.render_user_avatars($item);
self.$el.find('.oe_mail_wall_widgets').append($item);
});
@ -76,17 +77,38 @@ openerp.mail_wall_widgets = function(instance) {
// Generate a FieldMonetary for each .oe_goal_field_monetary
item.find(".oe_goal_field_monetary").each(function() {
var currency_id = parseInt( $(this).attr('data-id'), 10);
money_field = new instance.web.form.FieldMonetary(self.dfm, {
var precision = parseFloat( $(this).attr('data-precision') , 10) || 1;
var digits = [69,0];
if (precision && precision<1)
digits[1] = ($(this).attr('data-precision') || '0.01').slice(2).indexOf('1')+1;
var money_field = new instance.web.form.FieldMonetary(self.dfm, {
attrs: {
modifiers: '{"readonly": true}'
'modifiers': '{"readonly": true}',
'digits': digits
}
});
money_field.set('currency', currency_id);
money_field.get_currency_info();
money_field.set('value', parseInt($(this).text(), 10));
money_field.set('value', parseInt(parseFloat($(this).text(), 10)/precision)*precision);
money_field.replace($(this));
});
},
render_float_fields: function(item) {
var self = this;
// Generate a FieldMonetary for each .oe_goal_field_monetary
item.find(".oe_goal_field_float").each(function() {
var value = $(this).text();
if (!value)
return;
var precision = parseFloat( $(this).attr('data-precision'), 10) || 1;
var digits = [69,0];
if (precision && precision<1)
digits[1] = ($(this).attr('data-precision') || '0.01').slice(2).indexOf('1')+1;
value = instance.web.format_value(parseFloat(value), {type: "float", digits: digits}, '')
$(this).text(value)
});
},
render_user_avatars: function(item) {
var self = this;
item.find(".oe_user_avatar").each(function() {

8
static/src/xml/main.xml

@ -17,7 +17,7 @@
<t t-if="line.display_mode == 'progress'">
<div class="oe_goal_progress_background"></div>
<div class="oe_goal_progress" t-attf-style="#{line.display_mode == 'progress' ? 'width: '+line.completeness+'%;' : 'width:0;'}"></div>
<div class="oe_cell oe_goal_current" ><span t-attf-class="#{line.monetary ? 'oe_goal_field_monetary' : ''}" t-attf-data-id="#{line.monetary ? info.currency : ''}"><t t-esc="line.current" /></span></div>
<div class="oe_cell oe_goal_current" ><span t-attf-class="#{line.monetary ? 'oe_goal_field_monetary' : 'oe_goal_field_float'}" t-attf-data-id="#{line.monetary ? info.currency : ''}" t-attf-data-precision="#{info.data.precision or ''}"><t t-esc="line.current" /></span></div>
</t>
<div class="oe_cell">
<span t-att-title="line.description"><t t-raw="line.name" /></span>
@ -37,10 +37,10 @@
<t t-if="line.display_mode == 'progress'">
<div class="oe_goal_progress_background"></div>
<div class="oe_goal_progress" t-attf-style="#{line.display_mode == 'progress' ? 'width: '+line.rel_value+'%;' : 'width:0;'}"></div>
<div class="oe_cell oe_goal_current"><t t-esc="line.rel_value" /><span class="small">%</span></div>
<div class="oe_cell oe_goal_current"><span class="oe_goal_field_float" t-attf-data-precision="#{info.data.precision or ''}"><t t-esc="line.rel_value" /></span><span class="small">%</span></div>
</t>
<div class="oe_cell">
<span t-att-title="line.description"><b><t t-raw="line.name" /></b></span> - <span t-attf-class="#{line.monetary ? 'oe_goal_field_monetary' : ''}" t-attf-data-id="#{line.monetary ? info.currency : ''}"><t t-esc="line.abs_value" /></span><t t-if="line.suffix"> <t t-esc="line.suffix"/></t>
<span t-att-title="line.description"><b><t t-raw="line.name" /></b></span> - <span t-attf-class="#{line.monetary ? 'oe_goal_field_monetary' : 'oe_goal_field_float'}" t-attf-data-id="#{line.monetary ? info.currency : ''}" t-attf-data-precision="#{info.data.precision or ''}"><t t-esc="line.abs_value" /></span><t t-if="line.suffix"> <t t-esc="line.suffix"/></t>
</div>
</div>
@ -56,7 +56,7 @@
<div class="oe_cell oe_goal_current"><t t-esc="line.slice" /><span class="small">%</span></div>
</t>
<div class="oe_cell">
<span t-att-title="line.description"><b><span t-attf-class="#{line.monetary ? 'oe_goal_field_monetary' : ''}" t-attf-data-id="#{line.monetary ? info.currency : ''}"><t t-esc="line.won" /></span></b></span> from <span t-attf-class="#{line.monetary ? 'oe_goal_field_monetary' : ''}" t-attf-data-id="#{line.monetary ? info.currency : ''}"><t t-esc="line.total" /></span><t t-if="line.suffix"> <t t-esc="line.suffix"/></t>
<span t-att-title="line.description"><b><span t-attf-class="#{line.monetary ? 'oe_goal_field_monetary' : ''}" t-attf-data-id="#{line.monetary ? info.currency : ''}"><t t-esc="line.won" /></span></b></span> from <span t-attf-class="#{line.monetary ? 'oe_goal_field_monetary' : 'oe_goal_field_float'}" t-attf-data-id="#{line.monetary ? info.currency : ''}" t-attf-data-precision="#{info.data.precision or ''}"><t t-esc="line.total" /></span><t t-if="line.suffix"> <t t-esc="line.suffix"/></t>
</div>
</div>

1
views.xml

@ -69,6 +69,7 @@
<field name="stage_field_id" attrs="{'invisible':[('type', 'not in', ['funnel'])]}"/>
<field name="value_field_id" class="oe_inline"/>
<field name="value_field_monetary" class="oe_inline"/>
<field name="precision" class="oe_inline"/>
<field name="content" attrs="{'invisible':[('type', 'not in', ['list'])]}"/>
<field name="limit" attrs="{'invisible':[('type', 'not in', ['list'])]}" class="oe_inline"/>
<field name="order" attrs="{'invisible':[('type', 'not in', ['list'])]}" class="oe_inline"/>

Loading…
Cancel
Save