Merge pull request #151 from acsone/8.0-imp-mis-builder-widget-ape
[IMP][mis_builder] MIS Builder widget improvement, add print and export button in the widget.pull/167/head
commit
e0ca63df25
|
@ -639,6 +639,32 @@ class MisReportInstance(models.Model):
|
||||||
'target': 'new',
|
'target': 'new',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def print_pdf(self):
|
||||||
|
self.ensure_one()
|
||||||
|
data = {'context': self.env.context}
|
||||||
|
return {
|
||||||
|
'name': 'MIS report instance QWEB PDF report',
|
||||||
|
'model': 'mis.report.instance',
|
||||||
|
'type': 'ir.actions.report.xml',
|
||||||
|
'report_name': 'mis_builder.report_mis_report_instance',
|
||||||
|
'report_type': 'qweb-pdf',
|
||||||
|
'context': self.env.context,
|
||||||
|
'data': data,
|
||||||
|
}
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def export_xls(self):
|
||||||
|
self.ensure_one()
|
||||||
|
return {
|
||||||
|
'name': 'MIS report instance XLS report',
|
||||||
|
'model': 'mis.report.instance',
|
||||||
|
'type': 'ir.actions.report.xml',
|
||||||
|
'report_name': 'mis.report.instance.xls',
|
||||||
|
'report_type': 'xls',
|
||||||
|
'context': self.env.context,
|
||||||
|
}
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def compute(self):
|
def compute(self):
|
||||||
assert len(self) == 1
|
assert len(self) == 1
|
||||||
|
|
|
@ -61,7 +61,7 @@ class MisBuilderXls(report_xls):
|
||||||
|
|
||||||
# get the computed result of the report
|
# get the computed result of the report
|
||||||
data = self.pool.get('mis.report.instance').compute(
|
data = self.pool.get('mis.report.instance').compute(
|
||||||
self.cr, self.uid, objects[0].id)
|
self.cr, self.uid, objects[0].id, self.context)
|
||||||
|
|
||||||
# Column headers
|
# Column headers
|
||||||
header_name_list = ['']
|
header_name_list = ['']
|
||||||
|
|
|
@ -35,6 +35,9 @@ class Report(models.Model):
|
||||||
@api.v7
|
@api.v7
|
||||||
def get_pdf(self, cr, uid, ids, report_name, html=None, data=None,
|
def get_pdf(self, cr, uid, ids, report_name, html=None, data=None,
|
||||||
context=None):
|
context=None):
|
||||||
|
if not ids and context.get('active_ids') and\
|
||||||
|
report_name == 'mis_builder.report_mis_report_instance':
|
||||||
|
ids = context.get('active_ids')
|
||||||
if ids:
|
if ids:
|
||||||
report = self._get_report_from_name(cr, uid, report_name)
|
report = self._get_report_from_name(cr, uid, report_name)
|
||||||
obj = self.pool[report.model].browse(cr, uid, ids,
|
obj = self.pool[report.model].browse(cr, uid, ids,
|
||||||
|
|
|
@ -6,21 +6,67 @@ openerp.mis_builder = function(instance) {
|
||||||
init: function() {
|
init: function() {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
this.mis_report_data = null;
|
this.mis_report_data = null;
|
||||||
|
this.mis_report_instance_id = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
start: function() {
|
start: function() {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
var self = this;
|
var self = this;
|
||||||
|
self.mis_report_instance_id = self.getParent().dataset.context.active_id
|
||||||
|
self.getParent().dataset.context['no_destroy'] = true;
|
||||||
|
self.generate_content();
|
||||||
|
},
|
||||||
|
|
||||||
|
get_context: function() {
|
||||||
|
var self = this;
|
||||||
|
context = {}
|
||||||
|
if (this.mis_report_instance_id){
|
||||||
|
context['active_ids'] = [this.mis_report_instance_id];
|
||||||
|
}
|
||||||
|
return context
|
||||||
|
},
|
||||||
|
print: function() {
|
||||||
|
var self = this
|
||||||
|
context = new instance.web.CompoundContext(self.build_context(), self.get_context()|| {})
|
||||||
|
new instance.web.Model("mis.report.instance").call(
|
||||||
|
"print_pdf",
|
||||||
|
[self.mis_report_instance_id],
|
||||||
|
{'context': context}
|
||||||
|
).then(function(result){
|
||||||
|
self.do_action(result);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
export_pdf: function() {
|
||||||
|
var self = this
|
||||||
|
context = new instance.web.CompoundContext(self.build_context(), self.get_context()|| {})
|
||||||
|
new instance.web.Model("mis.report.instance").call(
|
||||||
|
"export_xls",
|
||||||
|
[self.mis_report_instance_id],
|
||||||
|
{'context': context}
|
||||||
|
).then(function(result){
|
||||||
|
self.do_action(result).done(function(result){
|
||||||
|
a = 2;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
generate_content: function() {
|
||||||
|
var self = this
|
||||||
|
context = new instance.web.CompoundContext(self.build_context(), self.get_context()|| {})
|
||||||
new instance.web.Model("mis.report.instance").call(
|
new instance.web.Model("mis.report.instance").call(
|
||||||
"compute",
|
"compute",
|
||||||
[self.getParent().dataset.context.active_id],
|
[self.mis_report_instance_id],
|
||||||
{'context': new instance.web.CompoundContext()}
|
{'context': context}
|
||||||
).then(function(result){
|
).then(function(result){
|
||||||
self.mis_report_data = result;
|
self.mis_report_data = result;
|
||||||
self.renderElement();
|
self.renderElement();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
renderElement: function() {
|
||||||
|
this._super();
|
||||||
|
var self = this;
|
||||||
|
self.$(".oe_mis_builder_print").click(_.bind(this.print, this));
|
||||||
|
self.$(".oe_mis_builder_export").click(_.bind(this.export_pdf, this));
|
||||||
|
},
|
||||||
events: {
|
events: {
|
||||||
"click a.mis_builder_drilldown": "drilldown",
|
"click a.mis_builder_drilldown": "drilldown",
|
||||||
},
|
},
|
||||||
|
@ -31,10 +77,11 @@ openerp.mis_builder = function(instance) {
|
||||||
if (drilldown) {
|
if (drilldown) {
|
||||||
var period_id = JSON.parse($(event.target).data("period-id"));
|
var period_id = JSON.parse($(event.target).data("period-id"));
|
||||||
var val_c = JSON.parse($(event.target).data("expr"));
|
var val_c = JSON.parse($(event.target).data("expr"));
|
||||||
|
context = new instance.web.CompoundContext(self.build_context(), self.get_context()|| {})
|
||||||
new instance.web.Model("mis.report.instance.period").call(
|
new instance.web.Model("mis.report.instance.period").call(
|
||||||
"drilldown",
|
"drilldown",
|
||||||
[period_id, val_c],
|
[period_id, val_c],
|
||||||
{'context': new instance.web.CompoundContext()}
|
{'context': context}
|
||||||
).then(function(result) {
|
).then(function(result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
self.do_action(result);
|
self.do_action(result);
|
||||||
|
@ -44,5 +91,19 @@ openerp.mis_builder = function(instance) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
instance.web.ActionManager.include({
|
||||||
|
dialog_stop: function (reason) {
|
||||||
|
var self = this
|
||||||
|
if (self.dialog_widget && self.dialog_widget.dataset && self.dialog_widget.dataset.context) {
|
||||||
|
var context = self.dialog_widget.dataset.context
|
||||||
|
if (!context['no_destroy']) {
|
||||||
|
this._super.apply(this, arguments);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this._super.apply(this, arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
instance.web.form.custom_widgets.add('mis_report', 'instance.mis_builder.MisReport');
|
instance.web.form.custom_widgets.add('mis_report', 'instance.mis_builder.MisReport');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
<template>
|
<template>
|
||||||
<t t-name="mis_builder.MisReport">
|
<t t-name="mis_builder.MisReport">
|
||||||
<p> </p>
|
<div class="oe_mis_builder_content">
|
||||||
|
<div class="oe_mis_builder_buttons oe_right">
|
||||||
|
<button class="oe_mis_builder_print"><img src="/web/static/src/img/icons/gtk-print.png"/> Print</button>
|
||||||
|
<button class="oe_mis_builder_export"><img src="/web/static/src/img/icons/gtk-execute.png"/>Export</button>
|
||||||
|
</div>
|
||||||
<table t-if="widget.mis_report_data" class="oe_list_content mis_builder">
|
<table t-if="widget.mis_report_data" class="oe_list_content mis_builder">
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="oe_list_header_columns">
|
<tr class="oe_list_header_columns">
|
||||||
|
@ -58,5 +62,6 @@
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
|
</div>
|
||||||
</t>
|
</t>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -124,8 +124,6 @@
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form string="MIS Report Result" version="7.0">
|
<form string="MIS Report Result" version="7.0">
|
||||||
<widget type="mis_report"></widget>
|
<widget type="mis_report"></widget>
|
||||||
<button icon="gtk-print" name="%(qweb_pdf_export)d" string="Print" type="action" colspan="2"/>
|
|
||||||
<button icon="gtk-execute" name="%(xls_export)d" string="Export" type="action" colspan="2"/>
|
|
||||||
</form>
|
</form>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
@ -162,8 +160,8 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="oe_right oe_button_box" name="buttons">
|
<div class="oe_right oe_button_box" name="buttons">
|
||||||
<button type="object" name="preview" string="Preview" icon="gtk-print-preview" />
|
<button type="object" name="preview" string="Preview" icon="gtk-print-preview" />
|
||||||
<button type="action" name="%(qweb_pdf_export)d" string="Print" icon="gtk-print" />
|
<button type="object" name="print_pdf" string="Print" icon="gtk-print" />
|
||||||
<button type="action" name="%(xls_export)d" string="Export" icon="gtk-execute" />
|
<button type="object" name="export_xls" string="Export" icon="gtk-execute" />
|
||||||
<button type="action" name="%(mis_report_instance_add_to_dashboard_action)d" string="Add to dashboard" icon="gtk-add" />
|
<button type="action" name="%(mis_report_instance_add_to_dashboard_action)d" string="Add to dashboard" icon="gtk-add" />
|
||||||
</div>
|
</div>
|
||||||
<group col="4">
|
<group col="4">
|
||||||
|
|
Loading…
Reference in New Issue