Browse Source

Add tooltip to see the expression used. Add onclick to go to account.move.line concerned

pull/90/head
Laetitia Gangloff 10 years ago
committed by Stéphane Bidoul
parent
commit
b95b5ef5c9
  1. 51
      mis_builder/models/mis_builder.py
  2. 3
      mis_builder/static/src/css/custom.css
  3. 28
      mis_builder/static/src/js/mis_builder.js
  4. 10
      mis_builder/static/src/xml/mis_widget.xml
  5. 16
      mis_builder/tests/mis_builder_test.py

51
mis_builder/models/mis_builder.py

@ -506,6 +506,49 @@ class mis_report_instance_period(orm.Model):
'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,
is_solde=False):
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:
try:
kpi_val_comment = kpi.expression
kpi_val = safe_eval(kpi.expression, localdict)
except ZeroDivisionError:
kpi_val = None
kpi_val_rendered = '#DIV/0'
kpi_val_comment = traceback.format_exc()
kpi_val_comment += '\n\n%s' % (traceback.format_exc(),)
except:
kpi_val = None
kpi_val_rendered = '#ERR'
kpi_val_comment = traceback.format_exc()
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)
kpi_val_comment = None
localdict[kpi.name] = kpi_val
try:
@ -677,6 +720,8 @@ class mis_report_instance_period(orm.Model):
'suffix': kpi.suffix,
'dp': kpi.dp,
'is_percentage': kpi.type == 'pct',
'period_id': c.id,
'period_name': c.name,
}
return res

3
mis_builder/static/src/css/custom.css

@ -1,3 +1,6 @@
.openerp .rallign {
text-align: right;
}
.openerp a.mis_builder {
color: #4c4c4c;
}

28
mis_builder/static/src/js/mis_builder.js

@ -20,6 +20,34 @@ openerp.mis_builder = function(instance) {
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');

10
mis_builder/static/src/xml/mis_widget.xml

@ -25,9 +25,17 @@
</div>
</th>
<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">
<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>
</td>
</t>

16
mis_builder/tests/mis_builder_test.py

@ -65,17 +65,25 @@ class mis_builder_test(common.TransactionCase):
self.ref('mis_builder.mis_report_instance_test'))
self.assertDictContainsSubset(
{'content':
OrderedDict([(u'total_test',
OrderedDict([(
u'total_test',
{'kpi_name': u'total test',
'default_style': None,
'cols': [{'style': None,
'cols': [{
'period_name': 'today',
'period_id':
self.ref(
'mis_builder.mis_report_instance_period_test'),
'style': None,
'default_style': None,
'suffix': False,
'val_c': None,
'val_c': 'len(test)',
'val': 0,
'val_r': '0 ',
'is_percentage': False,
'dp': 0}]})]),
'dp': 0}]
}
)]),
'header': OrderedDict([('',
{'kpi_name': '',
'default_style': '',

Loading…
Cancel
Save