Browse Source

[IMP] mis_builder: refactor drilldown to move the logic to the server

pull/90/head
Stéphane Bidoul 10 years ago
parent
commit
10fc763d60
  1. 32
      mis_builder/models/mis_builder.py
  2. 28
      mis_builder/static/src/js/mis_builder.js
  3. 6
      mis_builder/static/src/xml/mis_widget.xml

32
mis_builder/models/mis_builder.py

@ -480,18 +480,16 @@ class mis_report_instance_period(orm.Model):
'Period name should be unique by report'),
]
def compute_domain(self, cr, uid, ids, account_, context=None):
if isinstance(ids, (int, long)):
ids = [ids]
domain = []
this = self.browse(cr, uid, ids, context=context)[0]
def drilldown(self, cr, uid, id, expr, context=None):
this = self.browse(cr, uid, id, context=context)[0]
env = Environment(cr, uid, {})
aep = AccountingExpressionProcessor(env)
aep.parse_expr(account_)
aep.parse_expr(expr)
aep.done_parsing([('company_id', '=',
this.report_instance_id.company_id.id)])
domain.extend(aep.get_aml_domain_for_expr(account_))
if domain != []:
domain = aep.get_aml_domain_for_expr(expr)
if domain:
# TODO: reuse compute_period_domain
# compute date/period
period_ids = []
date_from = None
@ -514,9 +512,18 @@ class mis_report_instance_period(orm.Model):
if date_from:
domain.extend([('date', '>=', date_from),
('date', '<=', date_to)])
return {
'name': expr + ' - ' + this.name,
'domain': domain,
'type': 'ir.actions.act_window',
'res_model': 'account.move.line',
'views': [[False, 'list'], [False, 'form']],
'view_type': 'list',
'view_mode': 'list',
'target': 'current',
}
else:
domain = False
return domain
return False
def compute_period_domain(self, cr, uid, period_report, is_end,
is_initial, context=None):
@ -657,7 +664,8 @@ class mis_report_instance_period(orm.Model):
except:
kpi_style = None
drilldown = bool(aep.get_aml_domain_for_expr(kpi.expression))
drilldown = (kpi_val is not None and
bool(aep.get_aml_domain_for_expr(kpi.expression)))
res[kpi.name] = {
'val': kpi_val,
@ -669,7 +677,7 @@ class mis_report_instance_period(orm.Model):
'dp': kpi.dp,
'is_percentage': kpi.type == 'pct',
'period_id': c.id,
'period_name': c.name,
'expr': kpi.expression,
'drilldown': drilldown,
}

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

@ -20,32 +20,24 @@ openerp.mis_builder = function(instance) {
self.renderElement();
});
},
events: {
"click a.mis_builder_drilldown": "drilldown",
},
drilldown: 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)){
var drilldown = JSON.parse($(event.target).data("drilldown"));
if (drilldown) {
var period_id = JSON.parse($(event.target).data("period-id"));
var val_c = JSON.parse($(event.target).data("expr"));
new instance.web.Model("mis.report.instance.period").call(
"compute_domain",
"drilldown",
[period_id, val_c],
{'context': new instance.web.CompoundContext()}
).then(function(result){
if (result != false){
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',
});
).then(function(result) {
if (result) {
self.do_action(result);
}
});
}

6
mis_builder/static/src/xml/mis_widget.xml

@ -30,10 +30,10 @@
<t t-if="value_value.drilldown">
<a href="javascript:void(0)"
class="mis_builder_drilldown"
t-att-data-val="JSON.stringify(value_value.val)"
t-att-data-val-c="JSON.stringify(value_value.val_c)"
t-att-data-drilldown="JSON.stringify(value_value.drilldown)"
t-att-data-period-id="JSON.stringify(value_value.period_id)"
t-att-data-period-name="JSON.stringify(value_value.period_name)">
t-att-data-expr="JSON.stringify(value_value.expr)"
>
<t t-esc="value_value.val_r"/>
</a>
</t>

Loading…
Cancel
Save