Browse Source

review of the computed table to get a more readable dict result. Allow to compare column with any column of the table.

pull/86/head
laetitia.gangloff@acsone.eu 10 years ago
committed by Stéphane Bidoul
parent
commit
c047f52614
  1. 56
      mis_builder/models/mis_builder.py
  2. 22
      mis_builder/static/src/xml/mis_widget.xml

56
mis_builder/models/mis_builder.py

@ -32,6 +32,7 @@ from openerp.osv import orm, fields
from openerp.tools.safe_eval import safe_eval from openerp.tools.safe_eval import safe_eval
from openerp.tools.translate import _ from openerp.tools.translate import _
from openerp import tools from openerp import tools
from collections import OrderedDict
class AutoStruct(object): class AutoStruct(object):
@ -535,42 +536,47 @@ class mis_report_instance(orm.Model):
r = self.browse(cr, uid, _ids, context=context) r = self.browse(cr, uid, _ids, context=context)
context['state'] = r.target_move context['state'] = r.target_move
res = {}
content = OrderedDict()
#empty line name for header
header = OrderedDict()
header[''] = {'kpi_name': '', 'cols': []}
rows = []
#initialize lines with kpi
for kpi in r.report_id.kpi_ids: for kpi in r.report_id.kpi_ids:
rows.append(dict(name=kpi.name,
description=kpi.description))
res['rows'] = rows
content[kpi.name] = {'kpi_name': kpi.description, 'cols': []}
cols = []
report_instance_period_obj = self.pool.get('mis.report.instance.period') report_instance_period_obj = self.pool.get('mis.report.instance.period')
kpi_obj = self.pool.get('mis.report.kpi') kpi_obj = self.pool.get('mis.report.kpi')
period_values = {}
for period in r.period_ids: for period in r.period_ids:
current_col = dict(name=period.name,
values=report_instance_period_obj._compute(cr, uid, period, context=context),
# add the column header
header['']['cols'].append(dict(name=period.name,
date=period.duration > 1 and date=period.duration > 1 and
_('from %s to %s' % (period.period_from and period.period_from.name
_('from %s to %s' %
(period.period_from and period.period_from.name
or self._format_date(cr, uid, period.date_from, context=context), or self._format_date(cr, uid, period.date_from, context=context),
period.period_to and period.period_to.name period.period_to and period.period_to.name
or self._format_date(cr, uid, period.date_to, context=context))) or self._format_date(cr, uid, period.date_to, context=context)))
or period.period_from and period.period_from.name or period.date_from)
cols.append(current_col)
or period.period_from and period.period_from.name or period.date_from))
# compute kpi values
values = report_instance_period_obj._compute(cr, uid, period, context=context)
period_values[period.name] = values
for key in values:
content[key]['cols'].append(values[key])
# add comparison column # add comparison column
for period in r.period_ids:
for compare_col in period.comparison_column_ids: for compare_col in period.comparison_column_ids:
column1 = current_col
for col in cols:
if col['name'] == compare_col.name:
column2 = col
continue
compare_values = {}
# add the column header
header['']['cols'].append(dict(name='%s - %s' % (period.name, compare_col.name), date=''))
column1_values = period_values[period.name]
column2_values = period_values[compare_col.name]
for kpi in r.report_id.kpi_ids: for kpi in r.report_id.kpi_ids:
compare_values[kpi.name] = {'val_r': kpi_obj._render_comparison(kpi,
column1['values'][kpi.name]['val'],
column2['values'][kpi.name]['val'])}
cols.append(dict(name='%s - %s' % (period.name, compare_col.name),
values=compare_values,
date=''))
res['cols'] = cols
content[kpi.name]['cols'].append({'val_r': kpi_obj._render_comparison(kpi,
column1_values[kpi.name]['val'],
column2_values[kpi.name]['val'])})
return res
return {'header': header,
'content': content}

22
mis_builder/static/src/xml/mis_widget.xml

@ -5,38 +5,38 @@
<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"></th>
<th t-foreach="widget.mis_report_data.cols" t-as="col" class="oe_list_header_char rallign">
<t t-foreach="widget.mis_report_data.header" t-as="h">
<th t-foreach="h_value.cols" t-as="header" class="oe_list_header_char rallign">
<div> <div>
<t t-esc="col.name"/>
<t t-esc="header.name"/>
</div> </div>
<div> <div>
<t t-esc="col.date"/>
<t t-esc="header.date"/>
</div> </div>
</th> </th>
</t>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr t-foreach="widget.mis_report_data.rows" t-as="row">
<tr t-foreach="widget.mis_report_data.content" t-as="c">
<th> <th>
<div> <div>
<t t-esc="row.description"/>
<t t-esc="c_value.kpi_name"/>
</div> </div>
</th> </th>
<td t-foreach="widget.mis_report_data.cols" t-as="col" class="rallign">
<t t-foreach="col.values" t-as="value">
<t t-if="value == row.name">
<td t-foreach="c_value.cols" t-as="value" class="rallign">
<label t-att="{'title': value_value.val_c}" class=" oe_form_label_help oe_align_right"> <label t-att="{'title': value_value.val_c}" class=" oe_form_label_help oe_align_right">
<t t-esc="value_value.val_r"/> <t t-esc="value_value.val_r"/>
</label> </label>
</t>
</t>
</td> </td>
</tr> </tr>
</tbody> </tbody>
<tfoot> <tfoot>
<tr> <tr>
<td class="oe_list_footer" /> <td class="oe_list_footer" />
<td t-foreach="widget.mis_report_data.cols" class="oe_list_footer" />
<t t-foreach="widget.mis_report_data.header" t-as="f">
<td t-foreach="f_value.cols" class="oe_list_footer" />
</t>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>

Loading…
Cancel
Save