Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0] Add option to show account details before KPI on instance #572

Open
wants to merge 4 commits into
base: 15.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, details_before_kpi=False):
"""Iterate rows in display order.

yields KpiMatrixRow.
"""
for kpi_row in self._kpi_rows.values():
yield kpi_row
if not details_before_kpi:
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 details_before_kpi:
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, details_before_kpi=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(details_before_kpi=details_before_kpi):
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."
)
details_before_kpi = fields.Boolean(
help="Show account details 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(details_before_kpi=self.details_before_kpi)

def drilldown(self, arg):
self.ensure_one()
Expand Down
5 changes: 4 additions & 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,10 @@
</div>
</div>
<div class="mis_tbody">
<t t-foreach="matrix.iter_rows()" t-as="row">
<t
t-foreach="matrix.iter_rows(o.details_before_kpi)"
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.details_before_kpi):
if (
row.style_props.hide_empty and row.is_empty()
) or row.style_props.hide_always:
Expand Down
10 changes: 10 additions & 0 deletions mis_builder/tests/test_data_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,13 @@ def test_actuals_alt(self):
self.p1.source_aml_model_id = aml_model.id
matrix = self.instance._compute_matrix()
assert_matrix(matrix, [[11, 13], [11, 30]])

def test_details_after_kpi(self):
self.instance.details_before_kpi = False
matrix_dict = self.instance.compute()
self.assertEqual(matrix_dict["body"][1]["row_id"], "k2")

def test_details_before_kpi(self):
self.instance.details_before_kpi = True
matrix_dict = self.instance.compute()
self.assertEqual(matrix_dict["body"][1]["parent_row_id"], "k2")
4 changes: 4 additions & 0 deletions mis_builder/views/mis_report_instance.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@
<group name="layout">
<field name="landscape_pdf" />
<field name="no_auto_expand_accounts" />
<field
name="details_before_kpi"
attrs="{'invisible': [('no_auto_expand_accounts', '=', True)]}"
/>
<field name="display_columns_description" />
<field name="hide_analytic_filters" />
</group>
Expand Down
Loading