diff --git a/web_export_view/README.rst b/web_export_view/README.rst new file mode 100644 index 00000000..f510e845 --- /dev/null +++ b/web_export_view/README.rst @@ -0,0 +1,75 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License + +Export Current View +=================== + +One of the best Odoo'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 on the sidebar. By clicking on it you'll get a XLS file contains +the same data of the tree view you are looking at, headers included. + + +Known Issues +============ + +Pedro M. Baeza (pedro.baeza@gmail.com): +When you have groups, they are not exported to Excel. It would be desirable to have this option. +One of the problems with this module is that you can't export data from a view with mode="tree". +Changing the approach to have the button always visible (we should relocate it also to another place, +as the current location is not visible for these views), and digging correctly in the DOM elements +for this view (very similar to the normal tree view one) will do the trick. This will also help users +to locate the feature, as it's hidden now by default and users don't think about selecting records. +The behavior will be: nothing selected > you export all (including groups). +Something or all selected: export the selection. + + +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. + +Credits +======= + +Contributors +------------ + + * Henry Zhou (MAXodoo) + * Rodney + * Simone Orsi + * Lorenzo Battistini + * Stefan Rijnhart + * Leonardo Pistone + * Jose Maria Bernet + +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 new file mode 100644 index 00000000..b0f26a9a --- /dev/null +++ b/web_export_view/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import controllers diff --git a/web_export_view/__manifest__.py b/web_export_view/__manifest__.py new file mode 100644 index 00000000..a70928b1 --- /dev/null +++ b/web_export_view/__manifest__.py @@ -0,0 +1,27 @@ +# Copyright 2016 Henry Zhou (http://www.maxodoo.com) +# Copyright 2016 Rodney (http://clearcorp.cr/) +# Copyright 2012 Agile Business Group +# Copyright 2012 Domsense srl () +# Copyright 2012 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + 'name': 'Web Export Current View', + 'version': '11.0.1.0.0', + 'category': 'Web', + 'author': 'Henry Zhou, Agile Business Group, \ + Odoo Community Association (OCA)', + 'website': 'https://github.com/OCA/web', + 'license': 'AGPL-3', + 'depends': [ + 'web', + ], + "data": [ + 'views/web_export_view_view.xml', + ], + 'qweb': [ + "static/src/xml/web_export_view_template.xml", + ], + 'installable': True, + 'auto_install': False, +} diff --git a/web_export_view/controllers/__init__.py b/web_export_view/controllers/__init__.py new file mode 100644 index 00000000..e046e49f --- /dev/null +++ b/web_export_view/controllers/__init__.py @@ -0,0 +1 @@ +from . import controllers diff --git a/web_export_view/controllers/controllers.py b/web_export_view/controllers/controllers.py new file mode 100644 index 00000000..fed05996 --- /dev/null +++ b/web_export_view/controllers/controllers.py @@ -0,0 +1,34 @@ +# Copyright 2016 Henry Zhou (http://www.maxodoo.com) +# Copyright 2016 Rodney (http://clearcorp.cr/) +# Copyright 2012 Agile Business Group +# Copyright 2012 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import json +import odoo.http as http +from odoo.http import request +from odoo.addons.web.controllers.main import ExcelExport + + +class ExcelExportView(ExcelExport): + def __getattribute__(self, name): + if name == 'fmt': + raise AttributeError() + return super(ExcelExportView, self).__getattribute__(name) + + @http.route('/web/export/xls_view', type='http', auth='user') + def export_xls_view(self, data, token): + data = json.loads(data) + model = data.get('model', []) + columns_headers = data.get('headers', []) + rows = data.get('rows', []) + + return request.make_response( + self.from_data(columns_headers, rows), + headers=[ + ('Content-Disposition', 'attachment; filename="%s"' + % self.filename(model)), + ('Content-Type', self.content_type) + ], + cookies={'fileToken': token} + ) diff --git a/web_export_view/i18n/de.po b/web_export_view/i18n/de.po new file mode 100644 index 00000000..0bc8e4f8 --- /dev/null +++ b/web_export_view/i18n/de.po @@ -0,0 +1,40 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_export_view +# +# Translators: +# Niki Waibel , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-04-28 18:03+0000\n" +"PO-Revision-Date: 2017-04-28 18:03+0000\n" +"Last-Translator: Niki Waibel , 2017\n" +"Language-Team: German (https://www.transifex.com/oca/teams/23907/de/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: de\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: web_export_view +#. openerp-web +#: code:addons/web_export_view/static/src/xml/web_export_view_template.xml:6 +#, python-format +msgid "Export xls" +msgstr "Exportiere xls" + +#. module: web_export_view +#. openerp-web +#: code:addons/web_export_view/static/src/js/web_export_view.js:63 +#, python-format +msgid "False" +msgstr "Falsch" + +#. module: web_export_view +#. openerp-web +#: code:addons/web_export_view/static/src/js/web_export_view.js:63 +#, python-format +msgid "True" +msgstr "Richtig" diff --git a/web_export_view/i18n/es.po b/web_export_view/i18n/es.po new file mode 100644 index 00000000..b2e3decf --- /dev/null +++ b/web_export_view/i18n/es.po @@ -0,0 +1,40 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_export_view +# +# Translators: +# OCA Transbot , 2016 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-04-28 18:03+0000\n" +"PO-Revision-Date: 2017-04-28 18:03+0000\n" +"Last-Translator: OCA Transbot , 2016\n" +"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: es\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: web_export_view +#. openerp-web +#: code:addons/web_export_view/static/src/xml/web_export_view_template.xml:6 +#, python-format +msgid "Export xls" +msgstr "Exportar XLS" + +#. module: web_export_view +#. openerp-web +#: code:addons/web_export_view/static/src/js/web_export_view.js:63 +#, python-format +msgid "False" +msgstr "Falso" + +#. module: web_export_view +#. openerp-web +#: code:addons/web_export_view/static/src/js/web_export_view.js:63 +#, python-format +msgid "True" +msgstr "Verdadero" diff --git a/web_export_view/i18n/hr.po b/web_export_view/i18n/hr.po new file mode 100644 index 00000000..786e25fd --- /dev/null +++ b/web_export_view/i18n/hr.po @@ -0,0 +1,40 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_export_view +# +# Translators: +# Bole , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-04-28 18:03+0000\n" +"PO-Revision-Date: 2017-04-28 18:03+0000\n" +"Last-Translator: Bole , 2017\n" +"Language-Team: Croatian (https://www.transifex.com/oca/teams/23907/hr/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: hr\n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" + +#. module: web_export_view +#. openerp-web +#: code:addons/web_export_view/static/src/xml/web_export_view_template.xml:6 +#, python-format +msgid "Export xls" +msgstr "Izvoz u XLS" + +#. module: web_export_view +#. openerp-web +#: code:addons/web_export_view/static/src/js/web_export_view.js:63 +#, python-format +msgid "False" +msgstr "NE" + +#. module: web_export_view +#. openerp-web +#: code:addons/web_export_view/static/src/js/web_export_view.js:63 +#, python-format +msgid "True" +msgstr "DA" diff --git a/web_export_view/i18n/nl_NL.po b/web_export_view/i18n/nl_NL.po new file mode 100644 index 00000000..6204c697 --- /dev/null +++ b/web_export_view/i18n/nl_NL.po @@ -0,0 +1,40 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_export_view +# +# Translators: +# Peter Hageman , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-07-01 03:34+0000\n" +"PO-Revision-Date: 2017-07-01 03:34+0000\n" +"Last-Translator: Peter Hageman , 2017\n" +"Language-Team: Dutch (Netherlands) (https://www.transifex.com/oca/teams/23907/nl_NL/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: nl_NL\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: web_export_view +#. openerp-web +#: code:addons/web_export_view/static/src/xml/web_export_view_template.xml:6 +#, python-format +msgid "Export xls" +msgstr "Exporteer xls" + +#. module: web_export_view +#. openerp-web +#: code:addons/web_export_view/static/src/js/web_export_view.js:63 +#, python-format +msgid "False" +msgstr "Fout" + +#. module: web_export_view +#. openerp-web +#: code:addons/web_export_view/static/src/js/web_export_view.js:63 +#, python-format +msgid "True" +msgstr "Waar" diff --git a/web_export_view/i18n/pt_BR.po b/web_export_view/i18n/pt_BR.po new file mode 100644 index 00000000..08eaaf44 --- /dev/null +++ b/web_export_view/i18n/pt_BR.po @@ -0,0 +1,40 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_export_view +# +# Translators: +# Rodrigo de Almeida Sottomaior Macedo , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-06-22 08:26+0000\n" +"PO-Revision-Date: 2017-06-22 08:26+0000\n" +"Last-Translator: Rodrigo de Almeida Sottomaior Macedo , 2017\n" +"Language-Team: Portuguese (Brazil) (https://www.transifex.com/oca/teams/23907/pt_BR/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: pt_BR\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: web_export_view +#. openerp-web +#: code:addons/web_export_view/static/src/xml/web_export_view_template.xml:6 +#, python-format +msgid "Export xls" +msgstr "Exportar xls" + +#. module: web_export_view +#. openerp-web +#: code:addons/web_export_view/static/src/js/web_export_view.js:63 +#, python-format +msgid "False" +msgstr "Falso" + +#. module: web_export_view +#. openerp-web +#: code:addons/web_export_view/static/src/js/web_export_view.js:63 +#, python-format +msgid "True" +msgstr "Verdadeiro" diff --git a/web_export_view/i18n/zh_CN.po b/web_export_view/i18n/zh_CN.po new file mode 100644 index 00000000..63084d07 --- /dev/null +++ b/web_export_view/i18n/zh_CN.po @@ -0,0 +1,40 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_export_view +# +# Translators: +# OCA Transbot , 2016 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-04-28 18:03+0000\n" +"PO-Revision-Date: 2017-04-28 18:03+0000\n" +"Last-Translator: OCA Transbot , 2016\n" +"Language-Team: Chinese (China) (https://www.transifex.com/oca/teams/23907/zh_CN/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: zh_CN\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#. module: web_export_view +#. openerp-web +#: code:addons/web_export_view/static/src/xml/web_export_view_template.xml:6 +#, python-format +msgid "Export xls" +msgstr "导出 xls" + +#. module: web_export_view +#. openerp-web +#: code:addons/web_export_view/static/src/js/web_export_view.js:63 +#, python-format +msgid "False" +msgstr "否" + +#. module: web_export_view +#. openerp-web +#: code:addons/web_export_view/static/src/js/web_export_view.js:63 +#, python-format +msgid "True" +msgstr "是" diff --git a/web_export_view/static/description/icon.png b/web_export_view/static/description/icon.png new file mode 100644 index 00000000..1b1b0d1e Binary files /dev/null and b/web_export_view/static/description/icon.png differ diff --git a/web_export_view/static/src/js/web_export_view.js b/web_export_view/static/src/js/web_export_view.js new file mode 100644 index 00000000..5f6d4bd0 --- /dev/null +++ b/web_export_view/static/src/js/web_export_view.js @@ -0,0 +1,114 @@ +odoo.define('web_export_view', function (require) { +"use strict"; + + var core = require('web.core'); + var Sidebar = require('web.Sidebar'); + var session = require('web.session'); + var crash_manager = require('web.crash_manager'); + + var QWeb = core.qweb; + + var _t = core._t; + + Sidebar.include({ + + _redraw: function () { + var self = this; + this._super.apply(this, arguments); + if (self.getParent().renderer.viewType == 'list') { + self.$el.find('.o_dropdown').last().append(QWeb.render('WebExportTreeViewXls', {widget: self})); + self.$el.find('.export_treeview_xls').on('click', self.on_sidebar_export_treeview_xls); + } + }, + + on_sidebar_export_treeview_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(); + var c = crash_manager; + + if (children) { + children.every(function (child) { + if (child.field && child.field.type == 'one2many') { + view = child.viewmanager.views.list.controller; + return false; // break out of the loop + } + if (child.field && child.field.type == 'many2many') { + view = child.list_view; + return false; // break out of the loop + } + return true; + }); + } + var export_columns_keys = []; + var export_columns_names = []; + var column_index = 0; + var column_header_selector; + $.each(view.renderer.columns, function () { + if (this.tag == 'field' && (this.attrs.widget === undefined || this.attrs.widget != 'handle')) { + // non-fields like `_group` or buttons + export_columns_keys.push(column_index); + column_header_selector = '.o_list_view > thead > tr> th:not([class*="o_list_record_selector"]):eq('+column_index+')'; + export_columns_names.push(view.$el.find(column_header_selector)[0].textContent); + } + column_index ++; + }); + var export_rows = []; + $.blockUI(); + if (children) { + // find only rows with data + view.$el.find('.o_list_view > tbody > tr.o_data_row:has(.o_list_record_selector input:checkbox:checked)') + .each(function () { + var $row = $(this); + var export_row = []; + $.each(export_columns_keys, function () { + var $cell = $row.find('td.o_data_cell:eq('+this+')') + var $cellcheckbox = $cell.find('.o_checkbox input:checkbox'); + if ($cellcheckbox.length) { + export_row.push( + $cellcheckbox.is(":checked") + ? _t("True") : _t("False") + ); + } + else { + var text = $cell.text().trim(); + var is_number = ( + $cell.hasClass('o_list_number') && + !$cell.hasClass('o_float_time_cell') + ); + if (is_number) { + export_row.push(parseFloat( + text + // Remove thousands separator + .split(_t.database.parameters.thousands_sep) + .join("") + // Always use a `.` as decimal separator + .replace(_t.database.parameters.decimal_point, ".") + // Remove non-numeric characters + .replace(/[^\d\.-]/g, "") + )); + } else { + export_row.push(text); + } + } + }); + export_rows.push(export_row); + }); + } + + session.get_file({ + url: '/web/export/xls_view', + data: {data: JSON.stringify({ + model: view.modelName, + headers: export_columns_names, + rows: export_rows + })}, + complete: $.unblockUI, + error: c.rpc_error.bind(c) + }); + } + + }); +}); diff --git a/web_export_view/static/src/xml/web_export_view_template.xml b/web_export_view/static/src/xml/web_export_view_template.xml new file mode 100644 index 00000000..32bd002e --- /dev/null +++ b/web_export_view/static/src/xml/web_export_view_template.xml @@ -0,0 +1,11 @@ + + + + +
+ +
+
+
diff --git a/web_export_view/views/web_export_view_view.xml b/web_export_view/views/web_export_view_view.xml new file mode 100644 index 00000000..4787238e --- /dev/null +++ b/web_export_view/views/web_export_view_view.xml @@ -0,0 +1,9 @@ + + + + +