Browse Source

[IMP] mis_builder: refactor drilldown to reuse period computation and work for all modes

pull/86/head
Stéphane Bidoul 10 years ago
parent
commit
4493a4ec0b
  1. 22
      mis_builder/models/aep.py
  2. 32
      mis_builder/models/mis_builder.py

22
mis_builder/models/aep.py

@ -154,7 +154,13 @@ class AccountingExpressionProcessor(object):
account_ids.update(self._account_ids_by_code[account_code])
self._map_account_ids[key] = list(account_ids)
def get_aml_domain_for_expr(self, expr):
def has_account_var(self, expr):
return bool(self.ACC_RE.match(expr))
def get_aml_domain_for_expr(self, expr,
date_from, date_to,
period_from, period_to,
target_move):
""" Get a domain on account.move.line for an expression.
Prerequisite: done_parsing() must have been invoked.
@ -164,10 +170,10 @@ class AccountingExpressionProcessor(object):
obtained from get_aml_domain_for_dates()
"""
aml_domains = []
domain_by_mode = {}
for mo in self.ACC_RE.finditer(expr):
field, _, account_codes, domain = self._parse_match_object(mo)
field, mode, account_codes, domain = self._parse_match_object(mo)
aml_domain = list(domain)
if account_codes:
account_ids = set()
for account_code in account_codes:
account_ids.update(self._account_ids_by_code[account_code])
@ -177,7 +183,13 @@ class AccountingExpressionProcessor(object):
elif field == 'deb':
aml_domain.append(('debit', '>', 0))
aml_domains.append(expression.normalize_domain(aml_domain))
return expression.OR(aml_domains)
if mode not in domain_by_mode:
domain_by_mode[mode] = \
self.get_aml_domain_for_dates(date_from, date_to,
period_from, period_to,
mode, target_move)
return expression.OR(aml_domains) + \
expression.OR(domain_by_mode.values())
def _period_has_moves(self, period):
move_model = self.env['account.move']
@ -282,7 +294,7 @@ class AccountingExpressionProcessor(object):
domain = [('date', '>=', date_from), ('date', '<=', date_to)]
if target_move == 'posted':
domain.append(('move_id.state', '=', 'posted'))
return domain
return expression.normalize_domain(domain)
def do_queries(self, date_from, date_to, period_from, period_to,
target_move):

32
mis_builder/models/mis_builder.py

@ -482,33 +482,13 @@ class mis_report_instance_period(orm.Model):
this = self.browse(cr, uid, _id, context=context)[0]
env = Environment(cr, uid, {})
aep = AccountingExpressionProcessor(env)
if aep.has_account_var(expr):
aep.parse_expr(expr)
aep.done_parsing(this.report_instance_id.root_account)
domain = aep.get_aml_domain_for_expr(expr)
if domain:
# TODO: reuse compute_period_domain
# compute date/period
period_ids = []
date_from = None
date_to = None
period_obj = self.pool['account.period']
target_move = this.report_instance_id.target_move
if target_move == 'posted':
domain.append(('move_id.state', '=', target_move))
if this.period_from:
compute_period_ids = period_obj.build_ctx_periods(
cr, uid, this.period_from.id, this.period_to.id)
period_ids.extend(compute_period_ids)
else:
date_from = this.date_from
date_to = this.date_to
if period_ids:
if date_from:
domain.append('|')
domain.append(('period_id', 'in', period_ids))
if date_from:
domain.extend([('date', '>=', date_from),
('date', '<=', date_to)])
domain = aep.get_aml_domain_for_expr(
expr, this.date_from, this.date_to,
this.period_from, this.period_to,
this.report_instance_id.target_move)
return {
'name': expr + ' - ' + this.name,
'domain': domain,
@ -605,7 +585,7 @@ class mis_report_instance_period(orm.Model):
kpi_style = None
drilldown = (kpi_val is not None and
bool(aep.get_aml_domain_for_expr(kpi.expression)))
aep.has_account_var(kpi.expression))
res[kpi.name] = {
'val': kpi_val,

Loading…
Cancel
Save