[WIP] mis_builder refactoring: move the "json" conversion to the matrix
mis.report.instance.compute() is now as simple as possible, and rest is nicely factored in manageable methods \o/pull/189/head
parent
3461d123d3
commit
83d943be5f
|
@ -55,11 +55,15 @@ class KpiMatrixRow(object):
|
||||||
else:
|
else:
|
||||||
return None # TODO style for expanded accounts
|
return None # TODO style for expanded accounts
|
||||||
|
|
||||||
def iter_cell_tuples(self, cols):
|
def iter_cell_tuples(self, cols=None):
|
||||||
|
if cols is None:
|
||||||
|
cols = self._matrix.iter_cols()
|
||||||
for col in cols:
|
for col in cols:
|
||||||
yield col.get_cell_tuple_for_row(self)
|
yield col.get_cell_tuple_for_row(self)
|
||||||
|
|
||||||
def iter_cells(self, subcols):
|
def iter_cells(self, subcols=None):
|
||||||
|
if subcols is None:
|
||||||
|
subcols = self._matrix.iter_subcols()
|
||||||
for subcol in subcols:
|
for subcol in subcols:
|
||||||
yield subcol.get_cell_for_row(self)
|
yield subcol.get_cell_for_row(self)
|
||||||
|
|
||||||
|
@ -307,6 +311,50 @@ class KpiMatrix(object):
|
||||||
self._load_account_names()
|
self._load_account_names()
|
||||||
return self._account_names[account_id]
|
return self._account_names[account_id]
|
||||||
|
|
||||||
|
def as_dict(self):
|
||||||
|
header = [{'cols': []}, {'cols': []}]
|
||||||
|
for col in self.iter_cols():
|
||||||
|
header[0]['cols'].append({
|
||||||
|
'description': col.description,
|
||||||
|
'comment': col.comment,
|
||||||
|
'colspan': col.colspan,
|
||||||
|
})
|
||||||
|
for subcol in col.iter_subcols():
|
||||||
|
header[1]['cols'].append({
|
||||||
|
'description': subcol.description,
|
||||||
|
'comment': subcol.comment,
|
||||||
|
'colspan': 1,
|
||||||
|
})
|
||||||
|
|
||||||
|
content = []
|
||||||
|
for row in self.iter_rows():
|
||||||
|
row_data = {
|
||||||
|
'row_id': id(row),
|
||||||
|
'parent_row_id': row.parent_row and id(row.parent_row) or None,
|
||||||
|
'description': row.description,
|
||||||
|
'comment': row.comment,
|
||||||
|
'style': row.style and row.style.to_css_style() or '',
|
||||||
|
'cols': []
|
||||||
|
}
|
||||||
|
for cell in row.iter_cells():
|
||||||
|
if cell is None:
|
||||||
|
row_data['cols'].append({})
|
||||||
|
else:
|
||||||
|
row_data['cols'].append({
|
||||||
|
'val': (cell.val
|
||||||
|
if cell.val is not AccountingNone else None),
|
||||||
|
'val_r': cell.val_rendered,
|
||||||
|
'val_c': cell.val_comment,
|
||||||
|
# TODO FIXME style
|
||||||
|
# TODO FIXME drilldown
|
||||||
|
})
|
||||||
|
content.append(row_data)
|
||||||
|
|
||||||
|
return {
|
||||||
|
'header': header,
|
||||||
|
'content': content,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def _get_selection_label(selection, value):
|
def _get_selection_label(selection, value):
|
||||||
for v, l in selection:
|
for v, l in selection:
|
||||||
|
@ -1336,46 +1384,4 @@ class MisReportInstance(models.Model):
|
||||||
for comparison_column in period.comparison_column_ids:
|
for comparison_column in period.comparison_column_ids:
|
||||||
kpi_matrix.declare_comparison(period.id, comparison_column.id)
|
kpi_matrix.declare_comparison(period.id, comparison_column.id)
|
||||||
kpi_matrix.compute_comparisons()
|
kpi_matrix.compute_comparisons()
|
||||||
|
return kpi_matrix.as_dict()
|
||||||
header = [{'cols': []}, {'cols': []}]
|
|
||||||
for col in kpi_matrix.iter_cols():
|
|
||||||
header[0]['cols'].append({
|
|
||||||
'description': col.description,
|
|
||||||
'comment': col.comment,
|
|
||||||
'colspan': col.colspan,
|
|
||||||
})
|
|
||||||
for subcol in col.iter_subcols():
|
|
||||||
header[1]['cols'].append({
|
|
||||||
'description': subcol.description,
|
|
||||||
'comment': subcol.comment,
|
|
||||||
'colspan': 1,
|
|
||||||
})
|
|
||||||
|
|
||||||
content = []
|
|
||||||
for row in kpi_matrix.iter_rows():
|
|
||||||
row_data = {
|
|
||||||
'row_id': id(row),
|
|
||||||
'parent_row_id': row.parent_row and id(row.parent_row) or None,
|
|
||||||
'description': row.description,
|
|
||||||
'comment': row.comment,
|
|
||||||
'style': row.style and row.style.to_css_style() or '',
|
|
||||||
'cols': []
|
|
||||||
}
|
|
||||||
for cell in row.iter_cells(kpi_matrix.iter_subcols()):
|
|
||||||
if cell is None:
|
|
||||||
row_data['cols'].append({})
|
|
||||||
else:
|
|
||||||
row_data['cols'].append({
|
|
||||||
'val': (cell.val
|
|
||||||
if cell.val is not AccountingNone else None),
|
|
||||||
'val_r': cell.val_rendered,
|
|
||||||
'val_c': cell.val_comment,
|
|
||||||
# TODO FIXME style
|
|
||||||
# TODO FIXME drilldown
|
|
||||||
})
|
|
||||||
content.append(row_data)
|
|
||||||
|
|
||||||
return {
|
|
||||||
'header': header,
|
|
||||||
'content': content,
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue