Browse Source

Add the possibility to set the result of report instance in a dashboard

pull/90/head
Laetitia Gangloff 10 years ago
committed by Stéphane Bidoul
parent
commit
9e64b91a08
  1. 1
      mis_builder/__init__.py
  2. 1
      mis_builder/__openerp__.py
  3. 2
      mis_builder/models/mis_builder.py
  4. 38
      mis_builder/static/src/js/mis_builder.js
  5. 2
      mis_builder/static/src/xml/mis_widget.xml
  6. 3
      mis_builder/views/mis_builder.xml
  7. 24
      mis_builder/wizard/__init__.py
  8. BIN
      mis_builder/wizard/__init__.pyc
  9. 76
      mis_builder/wizard/mis_builder_dashboard.py
  10. 33
      mis_builder/wizard/mis_builder_dashboard.xml

1
mis_builder/__init__.py

@ -22,3 +22,4 @@
#==============================================================================
import models
from . import wizard

1
mis_builder/__openerp__.py

@ -31,6 +31,7 @@
'website': 'http://acsone.eu',
'depends': ['account'],
'data': [
'wizard/mis_builder_dashboard.xml',
'views/mis_builder.xml',
],
'test': [

2
mis_builder/models/mis_builder.py

@ -460,7 +460,7 @@ class mis_report_instance(orm.Model):
cols = []
for period in r.period_ids:
col = dict(name=period.name)
cols.append(dict(name=period.name, description=period.name))
res['cols'] = cols
return res

38
mis_builder/static/src/js/mis_builder.js

@ -1,26 +1,26 @@
openerp.mis_builder = function(instance) {
instance.mis_builder.MisReport = instance.web.form.FormWidget.extend({
template: "mis_builder.MisReport",
init: function() {
instance.mis_builder.MisReport = instance.web.form.FormWidget.extend({
template: "mis_builder.MisReport",
init: function() {
this._super.apply(this, arguments);
this.mis_report_data = null;
},
start: function() {
},
start: function() {
this._super.apply(this, arguments);
var self = this;
var self = this;
new instance.web.Model("mis.report.instance").call(
"compute",
[self.getParent().dataset.context.active_id],
{'context': new instance.web.CompoundContext()}
).then(function(result){
self.mis_report_data = result;
self.renderElement();
"compute",
[self.getParent().dataset.context.active_id],
{'context': new instance.web.CompoundContext()}
).then(function(result){
self.mis_report_data = result;
self.renderElement();
});
},
});
instance.web.form.custom_widgets.add('mis_report', 'instance.mis_builder.MisReport');
},
});
instance.web.form.custom_widgets.add('mis_report', 'instance.mis_builder.MisReport');
}

2
mis_builder/static/src/xml/mis_widget.xml

@ -4,7 +4,7 @@
<table t-if="widget.mis_report_data">
<th>
<td></td>
<td t-foreach="widget.mis_report_data.rows" t-as="col">
<td t-foreach="widget.mis_report_data.cols" t-as="col" style="padding-right:10px">
<t t-esc="col.name"/>
</td>
</th>

3
mis_builder/views/mis_builder.xml

@ -119,7 +119,8 @@
</h1>
</div>
<div class="oe_right oe_button_box" name="buttons">
<button type="action" name="%(mis_report_instance_result_action)d" string="Open result" />
<button type="action" name="%(mis_report_instance_result_action)d" string="Preview" />
<button type="action" name="%(mis_report_instance_add_to_dashboard_action)d" string="Add to dashboard" />
</div>
<group col="2">
<field name="description"/>

24
mis_builder/wizard/__init__.py

@ -0,0 +1,24 @@
#==============================================================================
# =
# mis_builder module for OpenERP, Management Information System Builder
# Copyright (C) 2014 ACSONE SA/NV (<http://acsone.eu>)
# =
# This file is a part of mis_builder
# =
# mis_builder is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License v3 or later
# as published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# =
# mis_builder is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License v3 or later for more details.
# =
# You should have received a copy of the GNU Affero General Public License
# v3 or later along with this program.
# If not, see <http://www.gnu.org/licenses/>.
# =
#==============================================================================
from . import mis_builder_dashboard

BIN
mis_builder/wizard/__init__.pyc

76
mis_builder/wizard/mis_builder_dashboard.py

@ -0,0 +1,76 @@
#==============================================================================
# =
# mis_builder module for OpenERP, Management Information System Builder
# Copyright (C) 2014 ACSONE SA/NV (<http://acsone.eu>)
# =
# This file is a part of mis_builder
# =
# mis_builder is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License v3 or later
# as published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# =
# mis_builder is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License v3 or later for more details.
# =
# You should have received a copy of the GNU Affero General Public License
# v3 or later along with this program.
# If not, see <http://www.gnu.org/licenses/>.
# =
#==============================================================================
from openerp.osv import orm, fields
from lxml import etree
class add_mis_report_instance_dashboard(orm.TransientModel):
_name = "add.mis.report.instance.dashboard.wizard"
_columns = {'name': fields.char('Name', size=32, required=True),
'dashboard_id': fields.many2one('ir.actions.act_window', string="Dashboard", required=True,
domain="[('res_model', '=', 'board.board')]"),
}
def default_get(self, cr, uid, fields, context=None):
if context is None:
context = {}
if context.get('active_id'):
res = super(add_mis_report_instance_dashboard, self).default_get(cr, uid, fields, context=context)
# get report instance name
res['name'] = self.pool['mis.report.instance'].read(cr, uid, context['active_id'], ['name'])['name']
return res
def action_add_to_dashboard(self, cr, uid, ids, context=None):
if context is None:
context = {}
assert 'active_id' in context, "active_id missing in context"
wizard_data = self.browse(cr, uid, ids, context=context)[0]
# create the act_window corresponding to this report
view_id = self.pool['ir.model.data'].get_object_reference(cr, uid, 'mis_builder', 'mis_report_instance_result_view_form')[1]
report_result = self.pool['ir.actions.act_window'].create(cr, uid, {'name': 'mis.report.instance.result.view.action.%d' % context['active_id'],
'res_model': 'mis.report.instance',
'res_id': context['active_id'],
'target': 'current',
'view_mode': 'form',
'view_id': view_id})
# add this result in the selected dashboard
last_customization = self.pool['ir.ui.view.custom'].search(cr, uid, [('user_id', '=', uid),
('ref_id', '=', wizard_data.dashboard_id.view_id.id)], limit=1)
arch = wizard_data.dashboard_id.view_id.arch
if last_customization:
arch = self.pool['ir.ui.view.custom'].read(cr, uid, last_customization[0], ['arch'])['arch']
new_arch = etree.fromstring(arch)
column = new_arch.xpath("//column")[0]
column.append(etree.Element('action', {'context': str(context),
'name': str(report_result),
'string': wizard_data.name,
'view_mode': 'form'}))
self.pool['ir.ui.view.custom'].create(cr, uid, {'user_id': uid,
'ref_id': wizard_data.dashboard_id.view_id.id,
'arch': etree.tostring(new_arch, pretty_print=True)})
return {'type': 'ir.actions.act_window_close', }
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

33
mis_builder/wizard/mis_builder_dashboard.xml

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="mis_report_instance_add_to_dashboard_form_view">
<field name="name">add.mis.report.instance.dashboard.wizard.view</field>
<field name="model">add.mis.report.instance.dashboard.wizard</field>
<field name="arch" type="xml">
<form string="Add to dashboard" version="7.0">
<group>
<field name="name"/>
<field name="dashboard_id"/>
</group>
<footer>
<button name="action_add_to_dashboard" string="Add to dashboard" type="object" default_focus="1" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="mis_report_instance_add_to_dashboard_action">
<field name="name">Add to dashboard</field>
<field name="res_model">add.mis.report.instance.dashboard.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="mis_report_instance_add_to_dashboard_form_view"/>
<field name="target">new</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save