Browse Source

Merge pull request #128 from acsone/8.0-mis_builder-analytic-filter-hook-sbi

[ADD] mis_builder: hooks for analytic filtering
pull/131/head
Pedro M. Baeza 9 years ago
parent
commit
3c96527ac7
  1. 16
      mis_builder/README.rst
  2. 4
      mis_builder/models/aep.py
  3. 33
      mis_builder/models/mis_builder.py

16
mis_builder/README.rst

@ -50,6 +50,16 @@ For further information, please visit:
* https://www.odoo.com/forum/help-1 * https://www.odoo.com/forum/help-1
Developer notes
===============
A typical extension is to provide a mechanism to filter reports on analytic dimensions
or operational units. To implement this, you can override _get_additional_move_line_filter
and _get_additional_filter to further filter move lines or queries based on a user
selection. A typical use case could be to add an analytic account field on mis.report.instance,
or even on mis.report.instance.period if you want different columns to show different
analytic accounts.
Known issues / Roadmap Known issues / Roadmap
====================== ======================
@ -60,12 +70,6 @@ Known issues / Roadmap
but would be more efficient if one could write balp[user_type=...], as it would but would be more efficient if one could write balp[user_type=...], as it would
involve much less queries to the database. involve much less queries to the database.
* A mechanism to have a global move line filter at the level of the report template,
report instance, or even column. Such a domain filter would be ANDed with the
other filters and would allow to easily create reports filtered on analytic axis
or business unit. To be complete such a mechanism should allow implementing similar
filters on non accounting queries.
* More tests should be added. The first part is creating test data, then it will be * More tests should be added. The first part is creating test data, then it will be
easier. At the minimum, We need the following test data: easier. At the minimum, We need the following test data:

4
mis_builder/models/aep.py

@ -328,7 +328,7 @@ class AccountingExpressionProcessor(object):
return expression.normalize_domain(domain) return expression.normalize_domain(domain)
def do_queries(self, date_from, date_to, period_from, period_to, def do_queries(self, date_from, date_to, period_from, period_to,
target_move):
target_move, additional_move_line_filter=None):
"""Query sums of debit and credit for all accounts and domains """Query sums of debit and credit for all accounts and domains
used in expressions. used in expressions.
@ -347,6 +347,8 @@ class AccountingExpressionProcessor(object):
mode, target_move) mode, target_move)
domain = list(domain) + domain_by_mode[mode] domain = list(domain) + domain_by_mode[mode]
domain.append(('account_id', 'in', self._map_account_ids[key])) domain.append(('account_id', 'in', self._map_account_ids[key]))
if additional_move_line_filter:
domain.extend(additional_move_line_filter)
# fetch sum of debit/credit, grouped by account_id # fetch sum of debit/credit, grouped by account_id
accs = aml_model.read_group(domain, accs = aml_model.read_group(domain,
['debit', 'credit', 'account_id'], ['debit', 'credit', 'account_id'],

33
mis_builder/models/mis_builder.py

@ -260,6 +260,20 @@ class MisReportQuery(models.Model):
def _check_name(self): def _check_name(self):
return _is_valid_python_var(self.name) return _is_valid_python_var(self.name)
@api.multi
def _get_additional_filter(self):
""" Prepare an additional filter to apply on the query
This filter is combined to the query domain with a AND
operator. This hook is intended
to be inherited, and is useful to implement filtering
on analytic dimensions or operational units.
Returns an Odoo domain expression (a python list)
compatible with the model of the query."""
self.ensure_one()
return []
class MisReport(models.Model): class MisReport(models.Model):
""" A MIS report template (without period information) """ A MIS report template (without period information)
@ -398,6 +412,20 @@ class MisReportInstancePeriod(models.Model):
'Period name should be unique by report'), 'Period name should be unique by report'),
] ]
@api.multi
def _get_additional_move_line_filter(self):
""" Prepare a filter to apply on all move lines
This filter is applied with a AND operator on all
accounting expression domains. This hook is intended
to be inherited, and is useful to implement filtering
on analytic dimensions or operational units.
Returns an Odoo domain expression (a python list)
compatible with account.move.line."""
self.ensure_one()
return []
@api.multi @api.multi
def drilldown(self, expr): def drilldown(self, expr):
assert len(self) == 1 assert len(self) == 1
@ -410,6 +438,7 @@ class MisReportInstancePeriod(models.Model):
self.date_from, self.date_to, self.date_from, self.date_to,
self.period_from, self.period_to, self.period_from, self.period_to,
self.report_instance_id.target_move) self.report_instance_id.target_move)
domain.extend(self._get_additional_move_line_filter())
return { return {
'name': expr + ' - ' + self.name, 'name': expr + ' - ' + self.name,
'domain': domain, 'domain': domain,
@ -439,6 +468,7 @@ class MisReportInstancePeriod(models.Model):
} }
domain = query.domain and \ domain = query.domain and \
safe_eval(query.domain, eval_context) or [] safe_eval(query.domain, eval_context) or []
domain.extend(query._get_additional_filter())
if query.date_field.ttype == 'date': if query.date_field.ttype == 'date':
domain.extend([(query.date_field.name, '>=', self.date_from), domain.extend([(query.date_field.name, '>=', self.date_from),
(query.date_field.name, '<=', self.date_to)]) (query.date_field.name, '<=', self.date_to)])
@ -492,7 +522,8 @@ class MisReportInstancePeriod(models.Model):
aep.do_queries(self.date_from, self.date_to, aep.do_queries(self.date_from, self.date_to,
self.period_from, self.period_to, self.period_from, self.period_to,
self.report_instance_id.target_move)
self.report_instance_id.target_move,
self._get_additional_move_line_filter())
compute_queue = self.report_instance_id.report_id.kpi_ids compute_queue = self.report_instance_id.report_id.kpi_ids
recompute_queue = [] recompute_queue = []

Loading…
Cancel
Save