Browse Source

[IMP][mis_builder] MIS Builder widget improvement, add print and export button in the widget.

pull/189/head
Adrien Peiffer (ACSONE) 9 years ago
committed by Stéphane Bidoul
parent
commit
350c996592
  1. 24
      mis_builder/models/mis_builder.py
  2. 2
      mis_builder/report/mis_builder_xls.py
  3. 3
      mis_builder/report/mis_builder_xlsx.py
  4. 67
      mis_builder/static/src/js/mis_builder.js
  5. 115
      mis_builder/static/src/xml/mis_widget.xml
  6. 24
      mis_builder/views/mis_builder.xml

24
mis_builder/models/mis_builder.py

@ -603,6 +603,30 @@ class MisReportInstance(models.Model):
'target': 'new',
}
@api.multi
def print_pdf(self):
self.ensure_one()
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,
}
@api.multi
def export_xls(self):
self.ensure_one()
return {
'name': 'MIS report instance XLSX report',
'model': 'mis.report.instance',
'type': 'ir.actions.report.xml',
'report_name': 'mis.report.instance.xlsx',
'report_type': 'xlsx',
'context': self.env.context,
}
@api.multi
def compute(self):
assert len(self) == 1

2
mis_builder/report/mis_builder_xls.py

@ -61,7 +61,7 @@ class MisBuilderXls(report_xls):
# get the computed result of the report
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
header_name_list = ['']

3
mis_builder/report/mis_builder_xlsx.py

@ -23,6 +23,7 @@
##############################################################################
from openerp.addons.report_xlsx.report.report_xlsx import ReportXlsx
from openerp.report import report_sxw
import logging
_logger = logging.getLogger(__name__)
@ -91,4 +92,4 @@ class MisBuilderXslx(ReportXlsx):
MisBuilderXslx('report.mis.report.instance.xlsx',
'mis.report.instance')
'mis.report.instance', parser=report_sxw.rml_parse)

67
mis_builder/static/src/js/mis_builder.js

@ -5,6 +5,7 @@ var core = require('web.core');
var form_common = require('web.form_common');
var Model = require('web.DataModel');
var data = require('web.data');
var ActionManager = require('web.ActionManager');
var MisReport = form_common.FormWidget.extend({
/**
@ -16,21 +17,67 @@ var MisReport = form_common.FormWidget.extend({
init: function() {
this._super.apply(this, arguments);
this.mis_report_data = null;
this.mis_report_instance_id = false;
},
start: function() {
this._super.apply(this, arguments);
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;
var context = {}
if (this.mis_report_instance_id){
context['active_ids'] = [this.mis_report_instance_id];
}
return context
},
print: function() {
var self = this
var context = new data.CompoundContext(self.build_context(), self.get_context()|| {})
new 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
var context = new data.CompoundContext(self.build_context(), self.get_context()|| {})
new Model("mis.report.instance").call(
"export_xls",
[self.mis_report_instance_id],
{'context': context}
).then(function(result){
self.do_action(result).done(function(result){
});
});
},
generate_content: function() {
var self = this
var context = new data.CompoundContext(self.build_context(), self.get_context()|| {})
new Model("mis.report.instance").call(
"compute",
[self.getParent().dataset.context.active_id],
{'context': new data.CompoundContext()}
[self.mis_report_instance_id],
{'context': context}
).then(function(result){
self.mis_report_data = result;
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: {
"click a.mis_builder_drilldown": "drilldown",
},
@ -54,6 +101,18 @@ var MisReport = form_common.FormWidget.extend({
},
});
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);
}
}
});
core.form_custom_registry.add('mis_report', MisReport);
});

115
mis_builder/static/src/xml/mis_widget.xml

@ -1,62 +1,67 @@
<template>
<t t-name="mis_builder.MisReport">
<p> </p>
<table t-if="widget.mis_report_data" class="oe_list_content mis_builder">
<thead>
<tr class="oe_list_header_columns">
<t t-foreach="widget.mis_report_data.header" t-as="h">
<th class="oe_list_header_char">
<div class="oe_mis_builder_content">
<table t-if="widget.mis_report_data" class="oe_list_content mis_builder">
<thead>
<tr class="oe_list_header_columns">
<t t-foreach="widget.mis_report_data.header" t-as="h">
<th class="oe_list_header_char">
<div>
<t t-esc="h_value.kpi_name"/>
</div>
</th>
<th t-foreach="h_value.cols" t-as="col" class="oe_list_header_char mis_builder_ralign">
<div>
<t t-esc="col.name"/>
</div>
<div>
<t t-esc="col.date"/>
</div>
</th>
</t>
</tr>
</thead>
<tbody>
<tr t-foreach="widget.mis_report_data.content" t-as="c">
<td t-att="{'style': c_value.default_style}">
<div>
<t t-esc="h_value.kpi_name"/>
</div>
</th>
<th t-foreach="h_value.cols" t-as="col" class="oe_list_header_char mis_builder_ralign">
<div>
<t t-esc="col.name"/>
</div>
<div>
<t t-esc="col.date"/>
</div>
</th>
</t>
</tr>
</thead>
<tbody>
<tr t-foreach="widget.mis_report_data.content" t-as="c">
<td t-att="{'style': c_value.default_style}">
<div>
<t t-esc="c_value.kpi_name"/>
</div>
</td>
<t t-foreach="c_value.cols" t-as="value">
<td t-att="{'style': c_value.default_style}" class="mis_builder_ralign">
<div t-att="{'style': value_value.style, 'title': value_value.val_c}">
<t t-if="value_value.drilldown">
<a href="javascript:void(0)"
class="mis_builder_drilldown"
t-att-data-drilldown="JSON.stringify(value_value.drilldown)"
t-att-data-period-id="JSON.stringify(value_value.period_id)"
t-att-data-expr="JSON.stringify(value_value.expr)"
>
<t t-esc="value_value.val_r"/>
</a>
</t>
<t t-if="!value_value.drilldown">
<t t-esc="value_value.val_r"/>
</t>
<t t-esc="c_value.kpi_name"/>
</div>
</td>
</t>
</tr>
</tbody>
<tfoot>
<tr>
<td class="oe_list_footer" />
<t t-foreach="widget.mis_report_data.header" t-as="f">
<td t-foreach="f_value.cols" class="oe_list_footer" />
</t>
</tr>
</tfoot>
</table>
<t t-foreach="c_value.cols" t-as="value">
<td t-att="{'style': c_value.default_style}" class="mis_builder_ralign">
<div t-att="{'style': value_value.style, 'title': value_value.val_c}">
<t t-if="value_value.drilldown">
<a href="javascript:void(0)"
class="mis_builder_drilldown"
t-att-data-drilldown="JSON.stringify(value_value.drilldown)"
t-att-data-period-id="JSON.stringify(value_value.period_id)"
t-att-data-expr="JSON.stringify(value_value.expr)"
>
<t t-esc="value_value.val_r"/>
</a>
</t>
<t t-if="!value_value.drilldown">
<t t-esc="value_value.val_r"/>
</t>
</div>
</td>
</t>
</tr>
</tbody>
<tfoot>
<tr>
<td class="oe_list_footer" />
<t t-foreach="widget.mis_report_data.header" t-as="f">
<td t-foreach="f_value.cols" class="oe_list_footer" />
</t>
</tr>
</tfoot>
</table>
<div class="oe_mis_builder_buttons">
<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>
</div>
</t>
</template>

24
mis_builder/views/mis_builder.xml

@ -99,15 +99,15 @@
<menuitem id="mis_report_view_menu" parent="account.account_management_menu" name="MIS Report Templates" action="mis_report_view_action" sequence="21"/>
<record id="xls_export" model="ir.actions.report.xml">
<field name="name">MIS report instance XLS report</field>
<field name="model">mis.report.instance</field>
<field name="type">ir.actions.report.xml</field>
<field name="report_name">mis.report.instance.xlsx</field>
<field name="report_type">xlsx</field>
<field name="auto" eval="False"/>
</record>
<record id="xls_export" model="ir.actions.report.xml">
<field name="name">MIS report instance XLS report</field>
<field name="model">mis.report.instance</field>
<field name="type">ir.actions.report.xml</field>
<field name="report_name">mis.report.instance.xlsx</field>
<field name="report_type">xlsx</field>
<field name="auto" eval="False"/>
</record>
<record id="qweb_pdf_export" model="ir.actions.report.xml">
<field name="name">MIS report instance QWEB PDF report</field>
<field name="model">mis.report.instance</field>
@ -124,8 +124,6 @@
<field name="arch" type="xml">
<form string="MIS Report Result" version="7.0">
<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>
</field>
</record>
@ -162,8 +160,8 @@
</div>
<div class="oe_right oe_button_box" name="buttons">
<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="action" name="%(xls_export)d" string="Export" icon="gtk-execute" />
<button type="object" name="print_pdf" string="Print" icon="gtk-print" />
<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" />
</div>
<group col="4">

Loading…
Cancel
Save