Skip to content

Commit

Permalink
[IMP] add evaluate method to mis.report
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Oct 1, 2018
1 parent 6868ba5 commit 40235b3
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
59 changes: 59 additions & 0 deletions mis_builder/models/mis_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,8 @@ def declare_and_compute_period(self, kpi_matrix,
using _prepare_aep()
:param date_from, date_to: the starting and ending date
:param target_move: all|posted
:param subkpis_filter: a list of subkpis to include in the evaluation
(if empty, use all subkpis)
:param get_additional_move_line_filter: a bound method that takes
no arguments and returns
a domain compatible with
Expand All @@ -753,6 +755,9 @@ def declare_and_compute_period(self, kpi_matrix,
underlying model
:param locals_dict: personalized locals dictionary used as evaluation
context for the KPI expressions
:param aml_model: the name of a model that is compatible with
account.move.line
:param no_auto_expand_accounts: disable expansion of account details
"""
self.ensure_one()

Expand Down Expand Up @@ -838,3 +843,57 @@ def get_kpis_by_account_id(self, company):
for account_id in account_ids:
res[account_id].add(kpi)
return res

@api.multi
def evaluate(
self,
aep,
date_from,
date_to,
target_move='posted',
aml_model=None,
subkpis_filter=None,
get_additional_move_line_filter=None,
get_additional_query_filter=None,
):
""" Simplified method to evaluate a report over a time period.
:param aep: an AccountingExpressionProcessor instance created
using _prepare_aep()
:param date_from, date_to: the starting and ending date
:param target_move: all|posted
:param aml_model: the name of a model that is compatible with
account.move.line
:param subkpis_filter: a list of subkpis to include in the evaluation
(if empty, use all subkpis)
:param get_additional_move_line_filter: a bound method that takes
no arguments and returns
a domain compatible with
account.move.line
:param get_additional_query_filter: a bound method that takes a single
query argument and returns a
domain compatible with the query
underlying model
:return: a dictionary where keys are KPI names, and values are the
evaluated results; some additional keys might be present:
these should be ignored as they might be removed in the future.
"""
locals_dict = {}
kpi_matrix = self.prepare_kpi_matrix()
self.declare_and_compute_period(
kpi_matrix,
col_key=1,
col_label='',
col_description='',
aep=aep,
date_from=date_from,
date_to=date_to,
target_move=target_move,
subkpis_filter=subkpis_filter,
get_additional_move_line_filter=get_additional_move_line_filter,
get_additional_query_filter=get_additional_query_filter,
locals_dict=locals_dict,
aml_model=aml_model,
no_auto_expand_accounts=True,
)
return locals_dict
3 changes: 3 additions & 0 deletions mis_builder/readme/newsfragments/123.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add evaluate method to mis.report. This is a simplified
method to evaluate kpis of a report over a time period,
without creating a mis.report.instance.
12 changes: 12 additions & 0 deletions mis_builder/tests/test_mis_report_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,18 @@ def test_compute(self):
# k7 references k3 via subkpi names
self.assertEquals(vals, [AccountingNone, AccountingNone, 1.0])

def test_evaluate(self):
company = self.env.ref('base.main_company')
aep = self.report._prepare_aep(company)
r = self.report.evaluate(
aep,
date_from='2014-01-01',
date_to='2014-12-31',
)
self.assertEqual(r['k3'], (AccountingNone, 1.0))
self.assertEqual(r['k6'], ("bla", "blabla"))
self.assertEqual(r['k7'], (AccountingNone, 1.0))

def test_json(self):
self.report_instance.compute()

Expand Down

0 comments on commit 40235b3

Please sign in to comment.