Skip to content

Commit

Permalink
Add inverse detail option to instance
Browse files Browse the repository at this point in the history
  • Loading branch information
sa3m committed Oct 5, 2023
1 parent fcd2042 commit 3abaf9c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
11 changes: 7 additions & 4 deletions mis_builder/models/kpimatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,17 +432,20 @@ def compute_sums(self):
tooltips=False,
)

def iter_rows(self):
def iter_rows(self, inverse_detail=False):
"""Iterate rows in display order.
yields KpiMatrixRow.
"""
for kpi_row in self._kpi_rows.values():
yield kpi_row
if not inverse_detail:
yield kpi_row
detail_rows = self._detail_rows[kpi_row.kpi].values()
detail_rows = sorted(detail_rows, key=lambda r: r.label)
for detail_row in detail_rows:
yield detail_row
if inverse_detail:
yield kpi_row

def iter_cols(self):
"""Iterate columns in display order.
Expand Down Expand Up @@ -480,7 +483,7 @@ def get_account_name(self, account_id):
self._load_account_names()
return self._account_names[account_id]

def as_dict(self):
def as_dict(self, inverse_detail=False):
header = [{"cols": []}, {"cols": []}]
for col in self.iter_cols():
header[0]["cols"].append(
Expand All @@ -500,7 +503,7 @@ def as_dict(self):
)

body = []
for row in self.iter_rows():
for row in self.iter_rows(inverse_detail=inverse_detail):
if (
row.style_props.hide_empty and row.is_empty()
) or row.style_props.hide_always:
Expand Down
5 changes: 4 additions & 1 deletion mis_builder/models/mis_report_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,9 @@ def _compute_pivot_date(self):
display_columns_description = fields.Boolean(
help="Display the date range details in the column headers."
)
inverse_detail = fields.Boolean(
help="Show detail before KPI.",
)
comparison_mode = fields.Boolean(
compute="_compute_comparison_mode", inverse="_inverse_comparison_mode"
)
Expand Down Expand Up @@ -869,7 +872,7 @@ def _compute_matrix(self):
def compute(self):
self.ensure_one()
kpi_matrix = self._compute_matrix()
return kpi_matrix.as_dict()
return kpi_matrix.as_dict(inverse_detail=self.inverse_detail)

def drilldown(self, arg):
self.ensure_one()
Expand Down
2 changes: 1 addition & 1 deletion mis_builder/report/mis_report_instance_qweb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
</div>
</div>
<div class="mis_tbody">
<t t-foreach="matrix.iter_rows()" t-as="row">
<t t-foreach="matrix.iter_rows(o.inverse_detail)" t-as="row">
<div
t-if="not ((row.style_props.hide_empty and row.is_empty()) or row.style_props.hide_always)"
class="mis_row"
Expand Down
2 changes: 1 addition & 1 deletion mis_builder/report/mis_report_instance_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def generate_xlsx_report(self, workbook, data, objects):
row_pos += 1

# rows
for row in matrix.iter_rows():
for row in matrix.iter_rows(objects.inverse_detail):
if (
row.style_props.hide_empty and row.is_empty()
) or row.style_props.hide_always:
Expand Down
1 change: 1 addition & 0 deletions mis_builder/views/mis_report_instance.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
<field name="no_auto_expand_accounts" />
<field name="display_columns_description" />
<field name="hide_analytic_filters" />
<field name="inverse_detail" />
</group>
</page>
</notebook>
Expand Down

0 comments on commit 3abaf9c

Please sign in to comment.