Browse Source

Migrate web_export_view to v 8.0

pull/1269/head
Adil Houmadi 10 years ago
committed by ernesto
parent
commit
05a5984688
  1. 7
      web_export_view/AUTHORS.txt
  2. 60
      web_export_view/README.rst
  3. 4
      web_export_view/__init__.py
  4. 42
      web_export_view/__openerp__.py
  5. 21
      web_export_view/controllers/__init__.py
  6. 19
      web_export_view/controllers/controllers.py
  7. BIN
      web_export_view/static/description/icon.png
  8. 67
      web_export_view/static/src/js/web_export_view.js
  9. 5
      web_export_view/static/src/xml/web_export_view_template.xml
  10. 11
      web_export_view/view/web_export_view.xml

7
web_export_view/AUTHORS.txt

@ -1,7 +0,0 @@
Authors
=======
Simone Orsi <simone.orsi@domsense.com> [simahawk]
Lorenzo Battistini <lorenzo.battistini@agilebg.com>
Stefan Rijnhart <stefan@therp.nl>
Leonardo Pistone <leonardo.pistone@agilebg.com>

60
web_export_view/README.rst

@ -0,0 +1,60 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License
Export Current View
===================
One of the best OpenERP's features is exporting custom data to CSV/XLS. You can
do it by clicking on the export link in the sidebar. The export action allows
us to configure what to be exported by selecting fields, etc, and allows you
to save your export as a template so that you can export it once again without
having to configure it again.
That feature is as great and advanced as limited for an everyday experience.
A lot of customers want simply to export the tree view they are looking to.
If you miss this feature as us, probably you'll find an answer into our
web_export_view module.
Usage
=====
After you installed it, you'll find an additional link 'Export current view'
right below the 'Export' one. By clicking on it you'll get a XLS file contains
the same data of the tree view you are looking at, headers included.
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
`here <https://github.com/OCA/web/issues/new?body=module:%20web_export_view%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Contributors
------------
* Simone Orsi <simahawk@gmail.com>
* Lorenzo Battistini <lorenzo.battistini@agilebg.com>
* Stefan Rijnhart <stefan@therp.nl>
* Leonardo Pistone <leonardo.pistone@camptocamp.com>
Maintainer
----------
.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
To contribute to this module, please visit http://odoo-community.org.

4
web_export_view/__init__.py

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## ##############################################################################
#
#
# Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>) # Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2012 Domsense srl (<http://www.domsense.com>) # Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
# #
@ -18,4 +18,4 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
import controllers
from . import controllers

42
web_export_view/__openerp__.py

@ -1,9 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2012 Domsense srl (<http://www.domsense.com>) # Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2012-2013 Agile Business Group sagl
# (<http://www.agilebg.com>)
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published # it under the terms of the GNU Affero General Public License as published
@ -22,37 +21,20 @@
{ {
'name': 'Export Current View', 'name': 'Export Current View',
'version': '1.1',
'version': '8.0.1.2.0',
'category': 'Web', 'category': 'Web',
'description': """
WEB EXPORT VIEW
===============
One of the best OpenERPs features is exporting custom data to CSV/XLS. You can
do it by clicking on the export link in the sidebar. The export action allows
use to configure what to be exported by selecting fields, etc, and allows you
to save your export as a template so that you can export it once again without
having to configure it again.
That feature is as great and advanced as limited for an everyday experience.
A lot of customers want simply to export the tree view they are looking to.
If you miss this feature as us, probably youll find an answer into our
web_export_view module.
After you installed it, youll find an additional link Export current view
right below the Export one. By clicking on it youll get a XLS file contains
the same data of the tree view you are looking at, headers included.
""",
'author': 'Agile Business Group',
'author': "Agile Business Group,Odoo Community Association (OCA)",
'website': 'http://www.agilebg.com', 'website': 'http://www.agilebg.com',
'license': 'AGPL-3', 'license': 'AGPL-3',
'depends': ['web'],
# 'external_dependencies': {
# 'python': ['xlwt'],
# },
'js': ['static/*/*.js', 'static/*/js/*.js'],
'qweb': ['static/xml/web_advanced_export.xml'],
'depends': [
'web',
],
'data': [
'view/web_export_view.xml',
],
'qweb': [
'static/src/xml/web_export_view_template.xml',
],
'installable': True, 'installable': True,
'auto_install': False, 'auto_install': False,
'web_preload': False, 'web_preload': False,

21
web_export_view/controllers/__init__.py

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import controllers

19
web_export_view/controllers.py → web_export_view/controllers/controllers.py

@ -1,8 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2012 Domsense srl (<http://www.domsense.com>) # Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2012-2013:
# Agile Business Group sagl (<http://www.agilebg.com>)
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published # it under the terms of the GNU Affero General Public License as published
@ -23,31 +24,29 @@ try:
except ImportError: except ImportError:
import simplejson as json import simplejson as json
import web.http as openerpweb
from web.controllers.main import ExcelExport
import openerp.http as http
from openerp.http import request
from openerp.addons.web.controllers.main import ExcelExport
class ExcelExportView(ExcelExport): class ExcelExportView(ExcelExport):
_cp_path = '/web/export/xls_view'
def __getattribute__(self, name): def __getattribute__(self, name):
if name == 'fmt': if name == 'fmt':
raise AttributeError() raise AttributeError()
return super(ExcelExportView, self).__getattribute__(name) return super(ExcelExportView, self).__getattribute__(name)
@openerpweb.httprequest
def index(self, req, data, token):
@http.route('/web/export/xls_view', type='http', auth='user')
def index(self, data, token):
data = json.loads(data) data = json.loads(data)
model = data.get('model', []) model = data.get('model', [])
columns_headers = data.get('headers', []) columns_headers = data.get('headers', [])
rows = data.get('rows', []) rows = data.get('rows', [])
return req.make_response(
return request.make_response(
self.from_data(columns_headers, rows), self.from_data(columns_headers, rows),
headers=[ headers=[
('Content-Disposition', 'attachment; filename="%s"' ('Content-Disposition', 'attachment; filename="%s"'
% self.filename(model)),
% self.filename(model)),
('Content-Type', self.content_type) ('Content-Type', self.content_type)
], ],
cookies={'fileToken': token} cookies={'fileToken': token}

BIN
web_export_view/static/description/icon.png

After

Width: 128  |  Height: 126  |  Size: 3.5 KiB

67
web_export_view/static/js/web_advanced_export.js → web_export_view/static/src/js/web_export_view.js

@ -18,28 +18,28 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
//############################################################################# //#############################################################################
openerp.web_export_view = function (instance) {
openerp.web_export_view = function(instance, m) {
var _t = instance.web._t,
QWeb = instance.web.qweb;
var _t = instance.web._t, QWeb = instance.web.qweb;
instance.web.Sidebar.include({ instance.web.Sidebar.include({
redraw: function() {
redraw: function () {
var self = this; var self = this;
this._super.apply(this, arguments); this._super.apply(this, arguments);
self.$el.find('.oe_sidebar').append(QWeb.render('AddExportViewMain', {widget: self}));
self.$el.find('.oe_sidebar_export_view_xls').on('click', self.on_sidebar_export_view_xls);
if (self.getParent().ViewManager.active_view == 'list') {
self.$el.find('.oe_sidebar').append(QWeb.render('AddExportViewMain', {widget: self}));
self.$el.find('.oe_sidebar_export_view_xls').on('click', self.on_sidebar_export_view_xls);
}
}, },
on_sidebar_export_view_xls: function() {
on_sidebar_export_view_xls: function () {
// Select the first list of the current (form) view // Select the first list of the current (form) view
// or assume the main view is a list view and use that // or assume the main view is a list view and use that
var self = this, var self = this,
view = this.getParent(),
children = view.getChildren();
view = this.getParent(),
children = view.getChildren();
if (children) { if (children) {
children.every(function(child) {
children.every(function (child) {
if (child.field && child.field.type == 'one2many') { if (child.field && child.field.type == 'one2many') {
view = child.viewmanager.views.list.controller; view = child.viewmanager.views.list.controller;
return false; // break out of the loop return false; // break out of the loop
@ -53,8 +53,8 @@ openerp.web_export_view = function(instance, m) {
} }
export_columns_keys = []; export_columns_keys = [];
export_columns_names = []; export_columns_names = [];
$.each(view.visible_columns, function(){
if(this.tag=='field'){
$.each(view.visible_columns, function () {
if (this.tag == 'field') {
// non-fields like `_group` or buttons // non-fields like `_group` or buttons
export_columns_keys.push(this.id); export_columns_keys.push(this.id);
export_columns_names.push(this.string); export_columns_names.push(this.string);
@ -62,51 +62,50 @@ openerp.web_export_view = function(instance, m) {
}); });
rows = view.$el.find('.oe_list_content > tbody > tr'); rows = view.$el.find('.oe_list_content > tbody > tr');
export_rows = []; export_rows = [];
$.each(rows,function(){
$.each(rows, function () {
$row = $(this); $row = $(this);
// find only rows with data // find only rows with data
if($row.attr('data-id')){
if ($row.attr('data-id')) {
export_row = []; export_row = [];
checked = $row.find('th input[type=checkbox]').attr("checked"); checked = $row.find('th input[type=checkbox]').attr("checked");
if (children && checked === "checked"){
$.each(export_columns_keys,function(){
cell = $row.find('td[data-field="'+this+'"]').get(0);
if (children && checked === "checked") {
$.each(export_columns_keys, function () {
cell = $row.find('td[data-field="' + this + '"]').get(0);
text = cell.text || cell.textContent || cell.innerHTML || ""; text = cell.text || cell.textContent || cell.innerHTML || "";
if (cell.classList.contains("oe_list_field_float")){
if (cell.classList.contains("oe_list_field_float")) {
export_row.push(instance.web.parse_value(text, {'type': "float"})); export_row.push(instance.web.parse_value(text, {'type': "float"}));
} }
else if (cell.classList.contains("oe_list_field_boolean")){
var data_id = $( '<div>' + cell.innerHTML + '</div>');
if(data_id.find('input').get(0).checked){
export_row.push(_t("True"));
else if (cell.classList.contains("oe_list_field_boolean")) {
var data_id = $('<div>' + cell.innerHTML + '</div>');
if (data_id.find('input').get(0).checked) {
export_row.push(_t("True"));
} }
else { else {
export_row.push(_t("False"));
export_row.push(_t("False"));
} }
} }
else if (cell.classList.contains("oe_list_field_integer")){
export_row.push(parseInt(text));
else if (cell.classList.contains("oe_list_field_integer")) {
export_row.push(parseInt(text));
} }
else{
export_row.push(text.trim());
else {
export_row.push(text.trim());
} }
}); });
export_rows.push(export_row); export_rows.push(export_row);
};
}
} }
}); });
$.blockUI(); $.blockUI();
view.session.get_file({ view.session.get_file({
url: '/web/export/xls_view', url: '/web/export/xls_view',
data: {data: JSON.stringify({ data: {data: JSON.stringify({
model : view.model,
headers : export_columns_names,
rows : export_rows,
model: view.model,
headers: export_columns_names,
rows: export_rows
})}, })},
complete: $.unblockUI complete: $.unblockUI
}); });
},
}
}); });
}; };

5
web_export_view/static/xml/web_advanced_export.xml → web_export_view/static/src/xml/web_export_view_template.xml

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- vim:fdl=1:
-->
<templates id="template" xml:space="preserve"> <templates id="template" xml:space="preserve">
<t t-name="AddExportViewMain"> <t t-name="AddExportViewMain">
<div class="oe_form_dropdown_section"> <div class="oe_form_dropdown_section">
@ -10,4 +9,4 @@
</ul> </ul>
</div> </div>
</t> </t>
</templates>
</templates>

11
web_export_view/view/web_export_view.xml

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" name="web_export_view assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/web_export_view/static/src/js/web_export_view.js"></script>
</xpath>
</template>
</data>
</openerp>
Loading…
Cancel
Save