Browse Source

Merge pull request #798 from JBF91/11.0-web_export_view

[MIG] web_export_view: Migration to 11.0
pull/1020/head
Pedro M. Baeza 6 years ago
committed by GitHub
parent
commit
9139f87110
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 75
      web_export_view/README.rst
  2. 3
      web_export_view/__init__.py
  3. 27
      web_export_view/__manifest__.py
  4. 1
      web_export_view/controllers/__init__.py
  5. 34
      web_export_view/controllers/controllers.py
  6. 40
      web_export_view/i18n/de.po
  7. 40
      web_export_view/i18n/es.po
  8. 40
      web_export_view/i18n/hr.po
  9. 40
      web_export_view/i18n/nl_NL.po
  10. 40
      web_export_view/i18n/pt_BR.po
  11. 40
      web_export_view/i18n/zh_CN.po
  12. BIN
      web_export_view/static/description/icon.png
  13. 114
      web_export_view/static/src/js/web_export_view.js
  14. 11
      web_export_view/static/src/xml/web_export_view_template.xml
  15. 9
      web_export_view/views/web_export_view_view.xml

75
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
<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.
Credits
=======
Contributors
------------
* Henry Zhou (MAXodoo) <zhouhenry@live.com>
* Rodney <https://github.com/rv-clearcorp>
* Simone Orsi <simahawk@gmail.com>
* Lorenzo Battistini <lorenzo.battistini@agilebg.com>
* Stefan Rijnhart <stefan@therp.nl>
* Leonardo Pistone <leonardo.pistone@camptocamp.com>
* Jose Maria Bernet <josemaria.bernet@guadaltech.es>
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.

3
web_export_view/__init__.py

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import controllers

27
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 (<http://www.domsense.com>)
# 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,
}

1
web_export_view/controllers/__init__.py

@ -0,0 +1 @@
from . import controllers

34
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}
)

40
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 <niki.waibel@gmail.com>, 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 <niki.waibel@gmail.com>, 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"

40
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 <transbot@odoo-community.org>, 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 <transbot@odoo-community.org>, 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"

40
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 <bole@dajmi5.com>, 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 <bole@dajmi5.com>, 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"

40
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 <hageman.p@gmail.com>, 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 <hageman.p@gmail.com>, 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"

40
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 <rmsolucoeseminformatic4@gmail.com>, 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 <rmsolucoeseminformatic4@gmail.com>, 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"

40
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 <transbot@odoo-community.org>, 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 <transbot@odoo-community.org>, 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 "是"

BIN
web_export_view/static/description/icon.png

After

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

114
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)
});
}
});
});

11
web_export_view/static/src/xml/web_export_view_template.xml

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="WebExportTreeViewXls">
<div class="o_cp_sidebar btn-group btn-group-sm">
<button class="btn btn-default export_treeview_xls" type="button" title="Export xls">
<i t-translation="off" class="fa fa-file-excel-o"></i>
</button>
</div>
</t>
</templates>

9
web_export_view/views/web_export_view_view.xml

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<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>
</odoo>
Loading…
Cancel
Save