[IMP] mis_builder: refactor drilldown to move the logic to the server
parent
842c57206d
commit
d0d3d1478a
|
@ -480,18 +480,16 @@ 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, account_, context=None):
|
def drilldown(self, cr, uid, id, expr, context=None):
|
||||||
if isinstance(ids, (int, long)):
|
this = self.browse(cr, uid, id, context=context)[0]
|
||||||
ids = [ids]
|
|
||||||
domain = []
|
|
||||||
this = self.browse(cr, uid, ids, context=context)[0]
|
|
||||||
env = Environment(cr, uid, {})
|
env = Environment(cr, uid, {})
|
||||||
aep = AccountingExpressionProcessor(env)
|
aep = AccountingExpressionProcessor(env)
|
||||||
aep.parse_expr(account_)
|
aep.parse_expr(expr)
|
||||||
aep.done_parsing([('company_id', '=',
|
aep.done_parsing([('company_id', '=',
|
||||||
this.report_instance_id.company_id.id)])
|
this.report_instance_id.company_id.id)])
|
||||||
domain.extend(aep.get_aml_domain_for_expr(account_))
|
domain = aep.get_aml_domain_for_expr(expr)
|
||||||
if domain != []:
|
if domain:
|
||||||
|
# TODO: reuse compute_period_domain
|
||||||
# compute date/period
|
# compute date/period
|
||||||
period_ids = []
|
period_ids = []
|
||||||
date_from = None
|
date_from = None
|
||||||
|
@ -514,9 +512,18 @@ class mis_report_instance_period(orm.Model):
|
||||||
if date_from:
|
if date_from:
|
||||||
domain.extend([('date', '>=', date_from),
|
domain.extend([('date', '>=', date_from),
|
||||||
('date', '<=', date_to)])
|
('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:
|
else:
|
||||||
domain = False
|
return False
|
||||||
return domain
|
|
||||||
|
|
||||||
def compute_period_domain(self, cr, uid, period_report, is_end,
|
def compute_period_domain(self, cr, uid, period_report, is_end,
|
||||||
is_initial, context=None):
|
is_initial, context=None):
|
||||||
|
@ -657,7 +664,8 @@ class mis_report_instance_period(orm.Model):
|
||||||
except:
|
except:
|
||||||
kpi_style = None
|
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] = {
|
res[kpi.name] = {
|
||||||
'val': kpi_val,
|
'val': kpi_val,
|
||||||
|
@ -669,7 +677,7 @@ class mis_report_instance_period(orm.Model):
|
||||||
'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,
|
'expr': kpi.expression,
|
||||||
'drilldown': drilldown,
|
'drilldown': drilldown,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,32 +20,24 @@ openerp.mis_builder = function(instance) {
|
||||||
self.renderElement();
|
self.renderElement();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
"click a.mis_builder_drilldown": "drilldown",
|
"click a.mis_builder_drilldown": "drilldown",
|
||||||
},
|
},
|
||||||
|
|
||||||
drilldown: function(event) {
|
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;
|
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(
|
new instance.web.Model("mis.report.instance.period").call(
|
||||||
"compute_domain",
|
"drilldown",
|
||||||
[period_id, val_c],
|
[period_id, val_c],
|
||||||
{'context': new instance.web.CompoundContext()}
|
{'context': new instance.web.CompoundContext()}
|
||||||
).then(function(result){
|
).then(function(result) {
|
||||||
if (result != false){
|
if (result) {
|
||||||
self.do_action({
|
self.do_action(result);
|
||||||
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',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,10 +30,10 @@
|
||||||
<t t-if="value_value.drilldown">
|
<t t-if="value_value.drilldown">
|
||||||
<a href="javascript:void(0)"
|
<a href="javascript:void(0)"
|
||||||
class="mis_builder_drilldown"
|
class="mis_builder_drilldown"
|
||||||
t-att-data-val="JSON.stringify(value_value.val)"
|
t-att-data-drilldown="JSON.stringify(value_value.drilldown)"
|
||||||
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-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"/>
|
<t t-esc="value_value.val_r"/>
|
||||||
</a>
|
</a>
|
||||||
</t>
|
</t>
|
||||||
|
|
Loading…
Reference in New Issue