Browse Source

[IMP] mis_builder: be more consistent in naming row/column labels

- label: the main row/column label
- description: a more detailed description of the row/column,
  currently displayed as a second line in the header cell
- comment: a even more detailed comment,
  currently displayed as a tooltip in the interactive widget only
pull/189/head
Stéphane Bidoul 8 years ago
parent
commit
5167dec5aa
  1. 36
      mis_builder/models/mis_report.py
  2. 18
      mis_builder/report/mis_report_instance_qweb.xml
  3. 30
      mis_builder/report/mis_report_instance_xlsx.py

36
mis_builder/models/mis_report.py

@ -46,7 +46,7 @@ class KpiMatrixRow(object):
self._matrix = matrix
self.kpi = kpi
self.account_id = account_id
self.comment = ''
self.description = ''
self.parent_row = parent_row
if not self.account_id:
self.style_props = self._matrix._style_model.merge([
@ -58,7 +58,7 @@ class KpiMatrixRow(object):
self.kpi.auto_expand_accounts_style_id])
@property
def description(self):
def label(self):
if not self.account_id:
return self.kpi.description
else:
@ -86,9 +86,9 @@ class KpiMatrixRow(object):
class KpiMatrixCol(object):
def __init__(self, description, comment, locals_dict, subkpis):
def __init__(self, label, description, locals_dict, subkpis):
self.label = label
self.description = description
self.comment = comment
self.locals_dict = locals_dict
self.colspan = subkpis and len(subkpis) or 1
self._subcols = []
@ -117,10 +117,10 @@ class KpiMatrixCol(object):
class KpiMatrixSubCol(object):
def __init__(self, col, description, comment, index=0):
def __init__(self, col, label, description, index=0):
self.col = col
self.label = label
self.description = description
self.comment = comment
self.index = index
@property
@ -184,13 +184,13 @@ class KpiMatrix(object):
self._kpi_rows[kpi] = KpiMatrixRow(self, kpi)
self._detail_rows[kpi] = {}
def declare_col(self, col_key, description, comment,
def declare_col(self, col_key, label, description,
locals_dict, subkpis):
""" Declare a new column, giving it an identifier (key).
Invoke this and declare_comparison in display order.
"""
self._cols[col_key] = KpiMatrixCol(description, comment,
self._cols[col_key] = KpiMatrixCol(label, description,
locals_dict, subkpis)
def declare_comparison(self, col_key, base_col_key):
@ -282,9 +282,9 @@ class KpiMatrix(object):
raise UserError('Columns {} and {} are not comparable'.
format(col.description,
base_col.description))
description = u'{} vs {}'.\
format(col.description, base_col.description)
comparison_col = KpiMatrixCol(description, None, {},
label = u'{} vs {}'.\
format(col.label, base_col.label)
comparison_col = KpiMatrixCol(label, None, {},
sorted(common_subkpis,
key=lambda s: s.sequence))
for row in self.iter_rows():
@ -369,14 +369,14 @@ class KpiMatrix(object):
header = [{'cols': []}, {'cols': []}]
for col in self.iter_cols():
header[0]['cols'].append({
'label': col.description,
'description': col.comment,
'label': col.label,
'description': col.description,
'colspan': col.colspan,
})
for subcol in col.iter_subcols():
header[1]['cols'].append({
'label': subcol.label,
'description': subcol.description,
'comment': subcol.comment,
'colspan': 1,
})
@ -386,8 +386,8 @@ class KpiMatrix(object):
'row_id': row.row_id,
'parent_row_id': (row.parent_row and
row.parent_row.row_id or None),
'label': row.description,
'description': row.comment,
'label': row.label,
'description': row.description,
'style': self._style_model.to_css_style(
row.style_props),
'cells': []
@ -855,8 +855,8 @@ class MisReport(models.Model):
@api.multi
def declare_and_compute_period(self, kpi_matrix,
col_key,
col_label,
col_description,
col_comment,
aep,
date_from, date_to,
target_move,
@ -914,7 +914,7 @@ class MisReport(models.Model):
else:
subkpis = self.subkpi_ids
kpi_matrix.declare_col(col_key,
col_description, col_comment,
col_label, col_description,
locals_dict, subkpis)
compute_queue = self.kpi_ids

18
mis_builder/report/mis_report_instance_qweb.xml

@ -37,10 +37,10 @@
<div class="mis_cell mis_collabel"></div>
<t t-foreach="matrix.iter_cols()" t-as="col">
<div class="mis_cell mis_collabel">
<t t-esc="col.description"/>
<t t-if="col.comment">
<t t-esc="col.label"/>
<t t-if="col.description">
<br/>
<t t-esc="col.comment"/>
<t t-esc="col.description"/>
</t>
</div>
<!-- add empty cells because we have no colspan with css tables -->
@ -53,10 +53,10 @@
<div class="mis_cell mis_collabel"></div>
<t t-foreach="matrix.iter_subcols()" t-as="subcol">
<div class="mis_cell mis_collabel">
<t t-esc="subcol.description"/>
<t t-if="subcol.comment">
<t t-esc="subcol.label"/>
<t t-if="subcol.description">
<br/>
<t t-esc="subcol.comment"/>
<t t-esc="subcol.description"/>
</t>
</div>
</t>
@ -65,10 +65,10 @@
<div class="mis_tbody">
<div t-foreach="matrix.iter_rows()" t-as="row" class="mis_row">
<div t-att-style="style_obj.to_css_style(row.style_props)" class="mis_cell mis_rowlabel">
<t t-esc="row.description"/>
<t t-if="row.comment">
<t t-esc="row.label"/>
<t t-if="row.description">
<br/>
<t t-esc="row.comment"/>
<t t-esc="row.description"/>
</t>
</div>
<t t-foreach="row.iter_cells()" t-as="cell">

30
mis_builder/report/mis_report_instance_xlsx.py

@ -61,9 +61,9 @@ class MisBuilderXslx(ReportXlsx):
sheet.write(row_pos, 0, '', header_format)
col_pos = 1
for col in matrix.iter_cols():
label = col.description
if col.comment:
label += '\n' + col.comment
label = col.label
if col.description:
label += '\n' + col.description
sheet.set_row(row_pos, ROW_HEIGHT * 2)
if col.colspan > 1:
sheet.merge_range(
@ -73,8 +73,8 @@ class MisBuilderXslx(ReportXlsx):
else:
sheet.write(row_pos, col_pos, label, header_format)
col_width[col_pos] = max(col_width[col_pos],
len(col.description or ''),
len(col.comment or ''))
len(col.label or ''),
len(col.description or ''))
col_pos += col.colspan
row_pos += 1
@ -82,14 +82,14 @@ class MisBuilderXslx(ReportXlsx):
sheet.write(row_pos, 0, '', header_format)
col_pos = 1
for subcol in matrix.iter_subcols():
label = subcol.description
if subcol.comment:
label += '\n' + subcol.comment
label = subcol.label
if subcol.description:
label += '\n' + subcol.description
sheet.set_row(row_pos, ROW_HEIGHT * 2)
sheet.write(row_pos, col_pos, label, header_format)
col_width[col_pos] = max(col_width[col_pos],
len(subcol.description or ''),
len(subcol.comment or ''))
len(subcol.label or ''),
len(subcol.description or ''))
col_pos += 1
row_pos += 1
@ -98,8 +98,14 @@ class MisBuilderXslx(ReportXlsx):
row_xlsx_style = style_obj.to_xlsx_style(row.style_props)
row_format = workbook.add_format(row_xlsx_style)
col_pos = 0
sheet.write(row_pos, col_pos, row.description, row_format)
label_col_width = max(label_col_width, len(row.description or ''))
label = row.label
if row.description:
label += '\n' + row.description
sheet.set_row(row_pos, ROW_HEIGHT * 2)
sheet.write(row_pos, col_pos, label, row_format)
label_col_width = max(label_col_width,
len(row.label or ''),
len(row.description or ''))
for cell in row.iter_cells():
col_pos += 1
if not cell or cell.val is AccountingNone:

Loading…
Cancel
Save