[IMP] mis_builder: recompute on ValueError

so kpi can be displayed in an other sequence than the computation dependency order
pull/86/head
Stéphane Bidoul 2015-04-25 16:10:16 +02:00
parent 22d59f3aa4
commit bae95527e1
1 changed files with 55 additions and 35 deletions

View File

@ -622,43 +622,63 @@ class mis_report_instance_period(orm.Model):
localdict.update(self._fetch_queries(cr, uid, c, localdict.update(self._fetch_queries(cr, uid, c,
context=context)) context=context))
for kpi in c.report_instance_id.report_id.kpi_ids: compute_queue = c.report_instance_id.report_id.kpi_ids
try: recompute_queue = []
kpi_val_comment = kpi.expression while True:
kpi_eval_expression = aep.replace_expr(kpi.expression) for kpi in compute_queue:
kpi_val = safe_eval(kpi_eval_expression, localdict) try:
except ZeroDivisionError: kpi_val_comment = kpi.expression
kpi_val = None kpi_eval_expression = aep.replace_expr(kpi.expression)
kpi_val_rendered = '#DIV/0' kpi_val = safe_eval(kpi_eval_expression, localdict)
kpi_val_comment += '\n\n%s' % (traceback.format_exc(),) except ZeroDivisionError:
except: kpi_val = None
kpi_val = None kpi_val_rendered = '#DIV/0'
kpi_val_rendered = '#ERR' kpi_val_comment += '\n\n%s' % (traceback.format_exc(),)
kpi_val_comment += '\n\n%s' % (traceback.format_exc(),) except ValueError:
else: recompute_queue.append(kpi)
kpi_val_rendered = kpi_obj._render( kpi_val = None
cr, uid, lang_id, kpi, kpi_val, context=context) kpi_val_rendered = '#ERR'
kpi_val_comment += '\n\n%s' % (traceback.format_exc(),)
except:
kpi_val = None
kpi_val_rendered = '#ERR'
kpi_val_comment += '\n\n%s' % (traceback.format_exc(),)
else:
kpi_val_rendered = kpi_obj._render(
cr, uid, lang_id, kpi, kpi_val, context=context)
localdict[kpi.name] = kpi_val localdict[kpi.name] = kpi_val
try: try:
kpi_style = None kpi_style = None
if kpi.css_style: if kpi.css_style:
kpi_style = safe_eval(kpi.css_style, localdict) kpi_style = safe_eval(kpi.css_style, localdict)
except: except:
kpi_style = None kpi_style = None
res[kpi.name] = { res[kpi.name] = {
'val': kpi_val, 'val': kpi_val,
'val_r': kpi_val_rendered, 'val_r': kpi_val_rendered,
'val_c': kpi_val_comment, 'val_c': kpi_val_comment,
'style': kpi_style, 'style': kpi_style,
'default_style': kpi.default_css_style or None, 'default_style': kpi.default_css_style or None,
'suffix': kpi.suffix, 'suffix': kpi.suffix,
'dp': kpi.dp, 'dp': kpi.dp,
'is_percentage': kpi.type == 'pct', 'is_percentage': kpi.type == 'pct',
'period_id': c.id, 'period_id': c.id,
'period_name': c.name, 'period_name': c.name,
} }
if len(recompute_queue) == 0:
# nothing to recompute, we are done
break
if len(recompute_queue) == len(compute_queue):
# could not compute anything in this iteration
# (ie real Value errors or cyclic dependency)
# so we stop trying
break
# try again
compute_queue = recompute_queue
recompute_queue = []
return res return res