Add tooltip to see the expression used. Add onclick to go to account.move.line concerned
parent
c62137ad8d
commit
3dacb87a7a
|
@ -506,6 +506,49 @@ class mis_report_instance_period(orm.Model):
|
||||||
'Period name should be unique by report'),
|
'Period name should be unique by report'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def compute_domain(self, cr, uid, ids, bal_, context=None):
|
||||||
|
if isinstance(ids, (int, long)):
|
||||||
|
ids = [ids]
|
||||||
|
domain = []
|
||||||
|
# extract all bal code
|
||||||
|
b = _get_bal_vars_in_expr(bal_, is_solde=False)
|
||||||
|
bs = _get_bal_vars_in_expr(bal_, is_solde=True)
|
||||||
|
all_code = []
|
||||||
|
all_code.extend([_get_bal_code(bal, False) for bal in b])
|
||||||
|
all_code.extend([_get_bal_code(bal, True) for bal in bs])
|
||||||
|
|
||||||
|
domain.append(('account_id.code', 'in', all_code))
|
||||||
|
|
||||||
|
# compute date/period
|
||||||
|
period_ids = []
|
||||||
|
date_from = None
|
||||||
|
date_to = None
|
||||||
|
|
||||||
|
period_obj = self.pool['account.period']
|
||||||
|
|
||||||
|
for c in self.browse(cr, uid, ids, context=context):
|
||||||
|
target_move = c.report_instance_id.target_move
|
||||||
|
if target_move == 'posted':
|
||||||
|
domain.append(('move_id.state', '=', target_move))
|
||||||
|
if c.period_from:
|
||||||
|
compute_period_ids = period_obj.build_ctx_periods(
|
||||||
|
cr, uid, c.period_from.id, c.period_to.id)
|
||||||
|
period_ids.extend(compute_period_ids)
|
||||||
|
else:
|
||||||
|
if not date_from or date_from > c.date_from:
|
||||||
|
date_from = c.date_from
|
||||||
|
if not date_to or date_to < c.date_to:
|
||||||
|
date_to = c.date_to
|
||||||
|
if period_ids:
|
||||||
|
if date_from:
|
||||||
|
domain.append('|')
|
||||||
|
domain.append(('period_id', 'in', period_ids))
|
||||||
|
if date_from:
|
||||||
|
domain.extend([('date', '>=', c.date_from),
|
||||||
|
('date', '<=', c.date_to)])
|
||||||
|
|
||||||
|
return domain
|
||||||
|
|
||||||
def _fetch_bal(self, cr, uid, company_id, bal_vars, context=None,
|
def _fetch_bal(self, cr, uid, company_id, bal_vars, context=None,
|
||||||
is_solde=False):
|
is_solde=False):
|
||||||
account_obj = self.pool['account.account']
|
account_obj = self.pool['account.account']
|
||||||
|
@ -646,19 +689,19 @@ class mis_report_instance_period(orm.Model):
|
||||||
|
|
||||||
for kpi in c.report_instance_id.report_id.kpi_ids:
|
for kpi in c.report_instance_id.report_id.kpi_ids:
|
||||||
try:
|
try:
|
||||||
|
kpi_val_comment = kpi.expression
|
||||||
kpi_val = safe_eval(kpi.expression, localdict)
|
kpi_val = safe_eval(kpi.expression, localdict)
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
kpi_val = None
|
kpi_val = None
|
||||||
kpi_val_rendered = '#DIV/0'
|
kpi_val_rendered = '#DIV/0'
|
||||||
kpi_val_comment = traceback.format_exc()
|
kpi_val_comment += '\n\n%s' % (traceback.format_exc(),)
|
||||||
except:
|
except:
|
||||||
kpi_val = None
|
kpi_val = None
|
||||||
kpi_val_rendered = '#ERR'
|
kpi_val_rendered = '#ERR'
|
||||||
kpi_val_comment = traceback.format_exc()
|
kpi_val_comment += '\n\n%s' % (traceback.format_exc(),)
|
||||||
else:
|
else:
|
||||||
kpi_val_rendered = kpi_obj._render(
|
kpi_val_rendered = kpi_obj._render(
|
||||||
cr, uid, lang_id, kpi, kpi_val, context=context)
|
cr, uid, lang_id, kpi, kpi_val, context=context)
|
||||||
kpi_val_comment = None
|
|
||||||
|
|
||||||
localdict[kpi.name] = kpi_val
|
localdict[kpi.name] = kpi_val
|
||||||
try:
|
try:
|
||||||
|
@ -677,6 +720,8 @@ class mis_report_instance_period(orm.Model):
|
||||||
'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_name': c.name,
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
.openerp .rallign {
|
.openerp .rallign {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
|
}
|
||||||
|
.openerp a.mis_builder {
|
||||||
|
color: #4c4c4c;
|
||||||
}
|
}
|
|
@ -20,6 +20,34 @@ openerp.mis_builder = function(instance) {
|
||||||
self.renderElement();
|
self.renderElement();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
events: {
|
||||||
|
"click .open_account_move a": "go_to_move",
|
||||||
|
},
|
||||||
|
go_to_move : function(event) {
|
||||||
|
var val_c = JSON.parse($(event.target).data("val-c"));
|
||||||
|
var val = JSON.parse($(event.target).data("val"));
|
||||||
|
var period_id = JSON.parse($(event.target).data("period-id"));
|
||||||
|
var period_name = JSON.parse($(event.target).data("period-name"));
|
||||||
|
var self = this;
|
||||||
|
if (!(val === null) && ((val_c.indexOf('bal_') >=0) || (val_c.indexOf('bals_') >= 0))){
|
||||||
|
new instance.web.Model("mis.report.instance.period").call(
|
||||||
|
"compute_domain",
|
||||||
|
[period_id, val_c],
|
||||||
|
{'context': new instance.web.CompoundContext()}
|
||||||
|
).then(function(result){
|
||||||
|
self.do_action({
|
||||||
|
name: val_c + ' - ' + period_name,
|
||||||
|
domain: JSON.stringify(result),
|
||||||
|
type: 'ir.actions.act_window',
|
||||||
|
res_model: "account.move.line",
|
||||||
|
views: [[false, 'list'], [false, 'form']],
|
||||||
|
view_type : "list",
|
||||||
|
view_mode : "list",
|
||||||
|
target: 'current',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
instance.web.form.custom_widgets.add('mis_report', 'instance.mis_builder.MisReport');
|
instance.web.form.custom_widgets.add('mis_report', 'instance.mis_builder.MisReport');
|
||||||
|
|
|
@ -25,9 +25,17 @@
|
||||||
</div>
|
</div>
|
||||||
</th>
|
</th>
|
||||||
<t t-foreach="c_value.cols" t-as="value">
|
<t t-foreach="c_value.cols" t-as="value">
|
||||||
<td class="rallign" t-att="{'style': c_value.default_style + ';' + value_value.style}">
|
<td class="rallign open_account_move" t-att="{'style': c_value.default_style + ';' + value_value.style}">
|
||||||
<label t-att="{'title': value_value.val_c}" class=" oe_form_label_help oe_align_right">
|
<label t-att="{'title': value_value.val_c}" class=" oe_form_label_help oe_align_right">
|
||||||
<t t-esc="value_value.val_r"/>
|
<a t-att="{'style': c_value.default_style + ';' + value_value.style}"
|
||||||
|
class="mis_builder"
|
||||||
|
href="javascript:void(0)"
|
||||||
|
t-att-data-val="JSON.stringify(value_value.val)"
|
||||||
|
t-att-data-val-c="JSON.stringify(value_value.val_c)"
|
||||||
|
t-att-data-period-id="JSON.stringify(value_value.period_id)"
|
||||||
|
t-att-data-period-name="JSON.stringify(value_value.period_name)">
|
||||||
|
<t t-esc="value_value.val_r"/>
|
||||||
|
</a>
|
||||||
</label>
|
</label>
|
||||||
</td>
|
</td>
|
||||||
</t>
|
</t>
|
||||||
|
|
|
@ -65,17 +65,25 @@ class mis_builder_test(common.TransactionCase):
|
||||||
self.ref('mis_builder.mis_report_instance_test'))
|
self.ref('mis_builder.mis_report_instance_test'))
|
||||||
self.assertDictContainsSubset(
|
self.assertDictContainsSubset(
|
||||||
{'content':
|
{'content':
|
||||||
OrderedDict([(u'total_test',
|
OrderedDict([(
|
||||||
{'kpi_name': u'total test',
|
u'total_test',
|
||||||
'default_style': None,
|
{'kpi_name': u'total test',
|
||||||
'cols': [{'style': None,
|
'default_style': None,
|
||||||
'default_style': None,
|
'cols': [{
|
||||||
'suffix': False,
|
'period_name': 'today',
|
||||||
'val_c': None,
|
'period_id':
|
||||||
'val': 0,
|
self.ref(
|
||||||
'val_r': '0 ',
|
'mis_builder.mis_report_instance_period_test'),
|
||||||
'is_percentage': False,
|
'style': None,
|
||||||
'dp': 0}]})]),
|
'default_style': None,
|
||||||
|
'suffix': False,
|
||||||
|
'val_c': 'len(test)',
|
||||||
|
'val': 0,
|
||||||
|
'val_r': '0 ',
|
||||||
|
'is_percentage': False,
|
||||||
|
'dp': 0}]
|
||||||
|
}
|
||||||
|
)]),
|
||||||
'header': OrderedDict([('',
|
'header': OrderedDict([('',
|
||||||
{'kpi_name': '',
|
{'kpi_name': '',
|
||||||
'default_style': '',
|
'default_style': '',
|
||||||
|
|
Loading…
Reference in New Issue