|
@ -134,14 +134,14 @@ class KpiMatrixCell(object): |
|
|
|
|
|
|
|
|
def __init__(self, row, subcol, |
|
|
def __init__(self, row, subcol, |
|
|
val, val_rendered, val_comment, |
|
|
val, val_rendered, val_comment, |
|
|
style=None, drilldown_key=None): |
|
|
|
|
|
|
|
|
style=None, drilldown_arg=None): |
|
|
self.row = row |
|
|
self.row = row |
|
|
self.subcol = subcol |
|
|
self.subcol = subcol |
|
|
self.val = val |
|
|
self.val = val |
|
|
self.val_rendered = val_rendered |
|
|
self.val_rendered = val_rendered |
|
|
self.val_comment = val_comment |
|
|
self.val_comment = val_comment |
|
|
self.style = style |
|
|
self.style = style |
|
|
self.drilldown_key = None |
|
|
|
|
|
|
|
|
self.drilldown_arg = drilldown_arg |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class KpiMatrix(object): |
|
|
class KpiMatrix(object): |
|
@ -191,14 +191,17 @@ class KpiMatrix(object): |
|
|
self._comparison_todo[last_period_key].append( |
|
|
self._comparison_todo[last_period_key].append( |
|
|
(period_key, base_period_key)) |
|
|
(period_key, base_period_key)) |
|
|
|
|
|
|
|
|
def set_values(self, kpi, period_key, vals): |
|
|
|
|
|
|
|
|
def set_values(self, kpi, period_key, vals, |
|
|
|
|
|
drilldown_args): |
|
|
""" Set values for a kpi and a period. |
|
|
""" Set values for a kpi and a period. |
|
|
|
|
|
|
|
|
Invoke this after declaring the kpi and the period. |
|
|
Invoke this after declaring the kpi and the period. |
|
|
""" |
|
|
""" |
|
|
self.set_values_detail_account(kpi, period_key, None, vals) |
|
|
|
|
|
|
|
|
self.set_values_detail_account(kpi, period_key, None, vals, |
|
|
|
|
|
drilldown_args) |
|
|
|
|
|
|
|
|
def set_values_detail_account(self, kpi, period_key, account_id, vals): |
|
|
|
|
|
|
|
|
def set_values_detail_account(self, kpi, period_key, account_id, vals, |
|
|
|
|
|
drilldown_args): |
|
|
""" Set values for a kpi and a period and a detail account. |
|
|
""" Set values for a kpi and a period and a detail account. |
|
|
|
|
|
|
|
|
Invoke this after declaring the kpi and the period. |
|
|
Invoke this after declaring the kpi and the period. |
|
@ -215,7 +218,8 @@ class KpiMatrix(object): |
|
|
col = self._cols[period_key] |
|
|
col = self._cols[period_key] |
|
|
cell_tuple = [] |
|
|
cell_tuple = [] |
|
|
assert len(vals) == col.colspan |
|
|
assert len(vals) == col.colspan |
|
|
for val, subcol in izip(vals, col.iter_subcols()): |
|
|
|
|
|
|
|
|
for val, drilldown_arg, subcol in \ |
|
|
|
|
|
izip(vals, drilldown_args, col.iter_subcols()): |
|
|
if isinstance(val, DataError): |
|
|
if isinstance(val, DataError): |
|
|
val_rendered = val.name |
|
|
val_rendered = val.name |
|
|
val_comment = val.msg |
|
|
val_comment = val.msg |
|
@ -231,8 +235,8 @@ class KpiMatrix(object): |
|
|
row.kpi.name, |
|
|
row.kpi.name, |
|
|
row.kpi.expression) |
|
|
row.kpi.expression) |
|
|
# TODO style |
|
|
# TODO style |
|
|
# TODO drilldown_key |
|
|
|
|
|
cell = KpiMatrixCell(row, subcol, val, val_rendered, val_comment) |
|
|
|
|
|
|
|
|
cell = KpiMatrixCell(row, subcol, val, val_rendered, val_comment, |
|
|
|
|
|
None, drilldown_arg) |
|
|
cell_tuple.append(cell) |
|
|
cell_tuple.append(cell) |
|
|
col._set_cell_tuple(row, cell_tuple) |
|
|
col._set_cell_tuple(row, cell_tuple) |
|
|
|
|
|
|
|
@ -358,14 +362,16 @@ class KpiMatrix(object): |
|
|
if cell is None: |
|
|
if cell is None: |
|
|
row_data['cols'].append({}) |
|
|
row_data['cols'].append({}) |
|
|
else: |
|
|
else: |
|
|
row_data['cols'].append({ |
|
|
|
|
|
|
|
|
col_data = { |
|
|
'val': (cell.val |
|
|
'val': (cell.val |
|
|
if cell.val is not AccountingNone else None), |
|
|
if cell.val is not AccountingNone else None), |
|
|
'val_r': cell.val_rendered, |
|
|
'val_r': cell.val_rendered, |
|
|
'val_c': cell.val_comment, |
|
|
'val_c': cell.val_comment, |
|
|
# TODO FIXME style |
|
|
# TODO FIXME style |
|
|
# TODO FIXME drilldown |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
if cell.drilldown_arg: |
|
|
|
|
|
col_data['drilldown_arg'] = cell.drilldown_arg |
|
|
|
|
|
row_data['cols'].append(col_data) |
|
|
content.append(row_data) |
|
|
content.append(row_data) |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
@ -975,11 +981,19 @@ class MisReport(models.Model): |
|
|
expressions.append(expression.name) |
|
|
expressions.append(expression.name) |
|
|
|
|
|
|
|
|
vals = [] |
|
|
vals = [] |
|
|
|
|
|
drilldown_args = [] |
|
|
try: |
|
|
try: |
|
|
for expression in expressions: |
|
|
for expression in expressions: |
|
|
replaced_expr = aep.replace_expr(expression) |
|
|
replaced_expr = aep.replace_expr(expression) |
|
|
vals.append( |
|
|
vals.append( |
|
|
mis_safe_eval(replaced_expr, locals_dict)) |
|
|
mis_safe_eval(replaced_expr, locals_dict)) |
|
|
|
|
|
if replaced_expr != expression: |
|
|
|
|
|
drilldown_args.append({ |
|
|
|
|
|
'period_id': period_key, |
|
|
|
|
|
'expr': expression, |
|
|
|
|
|
}) |
|
|
|
|
|
else: |
|
|
|
|
|
drilldown_args.append(None) |
|
|
except NameError: |
|
|
except NameError: |
|
|
recompute_queue.append(kpi) |
|
|
recompute_queue.append(kpi) |
|
|
break |
|
|
break |
|
@ -991,19 +1005,29 @@ class MisReport(models.Model): |
|
|
else: |
|
|
else: |
|
|
locals_dict[kpi.name] = SimpleArray(vals) |
|
|
locals_dict[kpi.name] = SimpleArray(vals) |
|
|
|
|
|
|
|
|
kpi_matrix.set_values(kpi, period_key, vals) |
|
|
|
|
|
|
|
|
kpi_matrix.set_values( |
|
|
|
|
|
kpi, period_key, vals, drilldown_args) |
|
|
|
|
|
|
|
|
if not kpi.auto_expand_accounts: |
|
|
if not kpi.auto_expand_accounts: |
|
|
continue |
|
|
continue |
|
|
|
|
|
|
|
|
for account_id, replaced_exprs in \ |
|
|
for account_id, replaced_exprs in \ |
|
|
aep.replace_exprs_by_account_id(expressions): |
|
|
aep.replace_exprs_by_account_id(expressions): |
|
|
account_id_vals = [] |
|
|
|
|
|
for replaced_expr in replaced_exprs: |
|
|
|
|
|
account_id_vals.append( |
|
|
|
|
|
mis_safe_eval(replaced_expr, locals_dict)) |
|
|
|
|
|
|
|
|
vals = [] |
|
|
|
|
|
drilldown_args = [] |
|
|
|
|
|
for expression, replaced_expr in \ |
|
|
|
|
|
izip(expressions, replaced_exprs): |
|
|
|
|
|
vals.append(mis_safe_eval(replaced_expr, locals_dict)) |
|
|
|
|
|
if replaced_expr != expression: |
|
|
|
|
|
drilldown_args.append({ |
|
|
|
|
|
'period_id': period_key, |
|
|
|
|
|
'expr': expression, |
|
|
|
|
|
'account_id': account_id |
|
|
|
|
|
}) |
|
|
|
|
|
else: |
|
|
|
|
|
drilldown_args.append(None) |
|
|
kpi_matrix.set_values_detail_account( |
|
|
kpi_matrix.set_values_detail_account( |
|
|
kpi, period_key, account_id, account_id_vals) |
|
|
|
|
|
|
|
|
kpi, period_key, account_id, vals, drilldown_args) |
|
|
|
|
|
|
|
|
if len(recompute_queue) == 0: |
|
|
if len(recompute_queue) == 0: |
|
|
# nothing to recompute, we are done |
|
|
# nothing to recompute, we are done |
|
|