Browse Source

[FIX] mis_builder: OrderedDict serializes to json dict

So this was relying on non-standard and unreliable feature of
browsers to preserve order.
pull/90/head
Stéphane Bidoul 10 years ago
parent
commit
08a72bb9ae
  1. 28
      mis_builder/models/mis_builder.py
  2. 6
      mis_builder/static/src/xml/mis_widget.xml

28
mis_builder/models/mis_builder.py

@ -22,7 +22,6 @@
# #
############################################################################## ##############################################################################
from collections import OrderedDict
from datetime import datetime, timedelta from datetime import datetime, timedelta
from dateutil import parser from dateutil import parser
import re import re
@ -725,22 +724,27 @@ class mis_report_instance(orm.Model):
kpi_values_by_period_ids[period.id] = kpi_values kpi_values_by_period_ids[period.id] = kpi_values
# prepare header and content # prepare header and content
header = OrderedDict()
header[''] = {'kpi_name': '',
'cols': [],
'default_style': ''}
content = OrderedDict()
header = []
header.append({
'kpi_name': '',
'cols': []
})
content = []
rows_by_kpi_name = {}
for kpi in this.report_id.kpi_ids: for kpi in this.report_id.kpi_ids:
content[kpi.name] = {'kpi_name': kpi.description,
rows_by_kpi_name[kpi.name] = {
'kpi_name': kpi.description,
'cols': [], 'cols': [],
'default_style': kpi.default_css_style}
'default_style': kpi.default_css_style
}
content.append(rows_by_kpi_name[kpi.name])
# populate header and content # populate header and content
for period in this.period_ids: for period in this.period_ids:
if not period.valid: if not period.valid:
continue continue
# add the column header # add the column header
header['']['cols'].append(dict(
header[0]['cols'].append(dict(
name=period.name, name=period.name,
date=(period.duration > 1 or period.type == 'w') and date=(period.duration > 1 or period.type == 'w') and
_('from %s to %s' % _('from %s to %s' %
@ -755,7 +759,7 @@ class mis_report_instance(orm.Model):
# add kpi values # add kpi values
kpi_values = kpi_values_by_period_ids[period.id] kpi_values = kpi_values_by_period_ids[period.id]
for kpi_name in kpi_values: for kpi_name in kpi_values:
content[kpi_name]['cols'].append(kpi_values[kpi_name])
rows_by_kpi_name[kpi_name]['cols'].append(kpi_values[kpi_name])
# add comparison columns # add comparison columns
for compare_col in period.comparison_column_ids: for compare_col in period.comparison_column_ids:
@ -763,12 +767,12 @@ class mis_report_instance(orm.Model):
kpi_values_by_period_ids.get(compare_col.id) kpi_values_by_period_ids.get(compare_col.id)
if compare_kpi_values: if compare_kpi_values:
# add the comparison column header # add the comparison column header
header['']['cols'].append(
header[0]['cols'].append(
dict(name='%s vs %s' % (period.name, compare_col.name), dict(name='%s vs %s' % (period.name, compare_col.name),
date='')) date=''))
# add comparison values # add comparison values
for kpi in this.report_id.kpi_ids: for kpi in this.report_id.kpi_ids:
content[kpi.name]['cols'].append(
rows_by_kpi_name[kpi.name]['cols'].append(
{'val_r': kpi_obj._render_comparison( {'val_r': kpi_obj._render_comparison(
cr, cr,
uid, uid,

6
mis_builder/static/src/xml/mis_widget.xml

@ -4,7 +4,11 @@
<table t-if="widget.mis_report_data" class="oe_list_content mis_builder"> <table t-if="widget.mis_report_data" class="oe_list_content mis_builder">
<thead> <thead>
<tr class="oe_list_header_columns"> <tr class="oe_list_header_columns">
<th class="oe_list_header_char"></th>
<th class="oe_list_header_char">
<div>
<t t-esc="h_value.kpi_name"/>
</div>
</th>
<t t-foreach="widget.mis_report_data.header" t-as="h"> <t t-foreach="widget.mis_report_data.header" t-as="h">
<th t-foreach="h_value.cols" t-as="col" class="oe_list_header_char mis_builder_ralign"> <th t-foreach="h_value.cols" t-as="col" class="oe_list_header_char mis_builder_ralign">
<div> <div>

Loading…
Cancel
Save