From 5167dec5aaeddaec15cfcde1cb88c5d4a806f7d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Mon, 16 May 2016 12:49:35 +0200 Subject: [PATCH] [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 --- mis_builder/models/mis_report.py | 36 +++++++++---------- .../report/mis_report_instance_qweb.xml | 18 +++++----- .../report/mis_report_instance_xlsx.py | 30 +++++++++------- 3 files changed, 45 insertions(+), 39 deletions(-) diff --git a/mis_builder/models/mis_report.py b/mis_builder/models/mis_report.py index 2e654dd1..e319a3d9 100644 --- a/mis_builder/models/mis_report.py +++ b/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 diff --git a/mis_builder/report/mis_report_instance_qweb.xml b/mis_builder/report/mis_report_instance_qweb.xml index 05385e10..769034bc 100644 --- a/mis_builder/report/mis_report_instance_qweb.xml +++ b/mis_builder/report/mis_report_instance_qweb.xml @@ -37,10 +37,10 @@
- - + +
- +
@@ -53,10 +53,10 @@
- - + +
- +
@@ -65,10 +65,10 @@
- - + +
- +
diff --git a/mis_builder/report/mis_report_instance_xlsx.py b/mis_builder/report/mis_report_instance_xlsx.py index a9c15631..faf93fda 100644 --- a/mis_builder/report/mis_report_instance_xlsx.py +++ b/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: