From 05a5984688121dcff4913be55f1560deaf312963 Mon Sep 17 00:00:00 2001 From: Adil Houmadi Date: Sat, 26 Jul 2014 14:37:23 +0200 Subject: [PATCH] Migrate web_export_view to v 8.0 --- web_export_view/AUTHORS.txt | 7 -- web_export_view/README.rst | 60 ++++++++++++++++ web_export_view/__init__.py | 4 +- web_export_view/__openerp__.py | 42 ++++------- web_export_view/controllers/__init__.py | 21 ++++++ .../{ => controllers}/controllers.py | 19 +++-- web_export_view/static/description/icon.png | Bin 0 -> 3550 bytes .../js/web_export_view.js} | 67 +++++++++--------- .../xml/web_export_view_template.xml} | 5 +- web_export_view/view/web_export_view.xml | 11 +++ 10 files changed, 150 insertions(+), 86 deletions(-) delete mode 100644 web_export_view/AUTHORS.txt create mode 100644 web_export_view/README.rst create mode 100644 web_export_view/controllers/__init__.py rename web_export_view/{ => controllers}/controllers.py (80%) create mode 100644 web_export_view/static/description/icon.png rename web_export_view/static/{js/web_advanced_export.js => src/js/web_export_view.js} (66%) rename web_export_view/static/{xml/web_advanced_export.xml => src/xml/web_export_view_template.xml} (92%) create mode 100644 web_export_view/view/web_export_view.xml diff --git a/web_export_view/AUTHORS.txt b/web_export_view/AUTHORS.txt deleted file mode 100644 index 76bbca72..00000000 --- a/web_export_view/AUTHORS.txt +++ /dev/null @@ -1,7 +0,0 @@ -Authors -======= - -Simone Orsi [simahawk] -Lorenzo Battistini -Stefan Rijnhart -Leonardo Pistone diff --git a/web_export_view/README.rst b/web_export_view/README.rst new file mode 100644 index 00000000..6a0ccb67 --- /dev/null +++ b/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 `_. +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 `_. + + +Credits +======= + +Contributors +------------ + + * Simone Orsi + * Lorenzo Battistini + * Stefan Rijnhart + * Leonardo Pistone + +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. diff --git a/web_export_view/__init__.py b/web_export_view/__init__.py index 09691964..9a651413 100644 --- a/web_export_view/__init__.py +++ b/web_export_view/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # Copyright (C) 2012 Agile Business Group sagl () # Copyright (C) 2012 Domsense srl () # @@ -18,4 +18,4 @@ # along with this program. If not, see . # ############################################################################## -import controllers +from . import controllers diff --git a/web_export_view/__openerp__.py b/web_export_view/__openerp__.py index 555f9b27..b582b26c 100644 --- a/web_export_view/__openerp__.py +++ b/web_export_view/__openerp__.py @@ -1,9 +1,8 @@ # -*- coding: utf-8 -*- ############################################################################## # +# Copyright (C) 2012 Agile Business Group sagl () # Copyright (C) 2012 Domsense srl () -# Copyright (C) 2012-2013 Agile Business Group sagl -# () # # 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 @@ -22,37 +21,20 @@ { 'name': 'Export Current View', - 'version': '1.1', + 'version': '8.0.1.2.0', 'category': 'Web', - 'description': """ -WEB EXPORT 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 -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 you’ll find an answer into our -web_export_view module. - -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. -""", - 'author': 'Agile Business Group', + 'author': "Agile Business Group,Odoo Community Association (OCA)", 'website': 'http://www.agilebg.com', '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, 'auto_install': False, 'web_preload': False, diff --git a/web_export_view/controllers/__init__.py b/web_export_view/controllers/__init__.py new file mode 100644 index 00000000..9a651413 --- /dev/null +++ b/web_export_view/controllers/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2012 Agile Business Group sagl () +# Copyright (C) 2012 Domsense srl () +# +# 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 . +# +############################################################################## +from . import controllers diff --git a/web_export_view/controllers.py b/web_export_view/controllers/controllers.py similarity index 80% rename from web_export_view/controllers.py rename to web_export_view/controllers/controllers.py index 01e3e1f9..15148edb 100644 --- a/web_export_view/controllers.py +++ b/web_export_view/controllers/controllers.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- ############################################################################## # -# Copyright (C) 2012 Agile Business Group sagl () # Copyright (C) 2012 Domsense srl () +# Copyright (C) 2012-2013: +# Agile Business Group sagl () # # 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 @@ -23,31 +24,29 @@ try: except ImportError: 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): - _cp_path = '/web/export/xls_view' - def __getattribute__(self, name): if name == 'fmt': raise AttributeError() 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) model = data.get('model', []) columns_headers = data.get('headers', []) rows = data.get('rows', []) - return req.make_response( + return request.make_response( self.from_data(columns_headers, rows), headers=[ ('Content-Disposition', 'attachment; filename="%s"' - % self.filename(model)), + % self.filename(model)), ('Content-Type', self.content_type) ], cookies={'fileToken': token} diff --git a/web_export_view/static/description/icon.png b/web_export_view/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..1b1b0d1e36eff948e53360e84145f3eff07e2f0e GIT binary patch literal 3550 zcmV<44I%Q0P)`gZBePnM}Td@O1R5oP^nas?4uYWMmkWAitlguQu+~0@$ zN#^C;%gjB$d+xdCo_j~40N|VJC;ao!|6d3EGSDBWOq654pJdV0`fxBbE}!~F%_~I* z{Dgy{rq6m~aJDbtuLLdxE&@6skh=uvInU3|pEXl-H=vg<;O_$rNtDxtit~&BzJR|I z8a;dg|LMR`zz>`wRGH%h=y{W$oy$&`r;8JFayMWYP@OR00{KJ$U%>AK%F!wJ1^mN+ zF~DU)H91ZIU*HnL!9O-uv;*)0#R*63ibN?AYRF*%H1)g_ODrc))cC5d`uCk}u$&222A61CB&dMAsz6R$#u(fnX#`Yalmy-B=$|qXF5tBzvv_2Z1ku zkHf*xfn)?QgkB2<22clV4hKWyd;z~8Kmp@mI2bAu1So7wP(>fuM_kv4L>qGU{W}yD zr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*+cL~Hb!PyZ9$Y)4-cpa^{WG@B$ z;UBNkXMVLU*+?wP3v*Y}ug6)<9LZicU6$74;WcAtGh@(LL4ZudNZb=>cg4{1J%RD0 zH;1&A0BtxcA+FdKK7fEAfPf%?fFOW?Ab@}%fIvY(7jb|Tpy|5hv9)7}#2S*W&kdkH z8cEw`m2T+7wN@XN6<@cJ3WoQsV%gOBwvLG#kn~<7hobV~vW;oox@f}84iY?5CkYpEC9~*1^gl_I7Ms$0;J~{ zie&M+RkKtJzsG@k;LC6@v>U(|@DmP(P=VdR$wIfb@MSm{dOIIJNH}=(+uP)DFw~W! z0imw~V}Kf96Hq7go&Qi1Y%qWid;$Ll;b3UPu|N6(eizUW=nD)0z5$#Mh|`z(vb1eY zC11c_njpk^iP9gaEP(!69}b4b<(&m+#r$y)c-a^5zkF;iNf4s~xFAu^0nP^ch;f!@ z7N8XtqdPDd7?kiedILR$1t<^#m=L2kFdVo9=mngXwklxro. // //############################################################################# +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({ - redraw: function() { + redraw: function () { var self = this; 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 // or assume the main view is a list view and use that var self = this, - view = this.getParent(), - children = view.getChildren(); + view = this.getParent(), + children = view.getChildren(); if (children) { - children.every(function(child) { + children.every(function (child) { if (child.field && child.field.type == 'one2many') { view = child.viewmanager.views.list.controller; return false; // break out of the loop @@ -53,8 +53,8 @@ openerp.web_export_view = function(instance, m) { } export_columns_keys = []; 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 export_columns_keys.push(this.id); 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'); export_rows = []; - $.each(rows,function(){ + $.each(rows, function () { $row = $(this); // find only rows with data - if($row.attr('data-id')){ + if ($row.attr('data-id')) { export_row = []; 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 || ""; - 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"})); } - else if (cell.classList.contains("oe_list_field_boolean")){ - var data_id = $( '
' + cell.innerHTML + '
'); - 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 = $('
' + cell.innerHTML + '
'); + if (data_id.find('input').get(0).checked) { + export_row.push(_t("True")); } 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); - }; + } } }); $.blockUI(); view.session.get_file({ url: '/web/export/xls_view', 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 }); - }, - + } }); }; diff --git a/web_export_view/static/xml/web_advanced_export.xml b/web_export_view/static/src/xml/web_export_view_template.xml similarity index 92% rename from web_export_view/static/xml/web_advanced_export.xml rename to web_export_view/static/src/xml/web_export_view_template.xml index cb4b5004..fbd855d9 100644 --- a/web_export_view/static/xml/web_advanced_export.xml +++ b/web_export_view/static/src/xml/web_export_view_template.xml @@ -1,6 +1,5 @@ - +
@@ -10,4 +9,4 @@
-
+ \ No newline at end of file diff --git a/web_export_view/view/web_export_view.xml b/web_export_view/view/web_export_view.xml new file mode 100644 index 00000000..502070f1 --- /dev/null +++ b/web_export_view/view/web_export_view.xml @@ -0,0 +1,11 @@ + + + + + + +