Browse Source

Merge pull request #785 from hbrunn/8.0-web_export_view-active_domain

[ADD] [web_export_view] export all records if all checkbox is selected
pull/812/merge
Stefan Rijnhart (Opener) 7 years ago
committed by GitHub
parent
commit
1492afdd23
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      web_export_view/__openerp__.py
  2. 74
      web_export_view/static/src/js/web_export_view.js

2
web_export_view/__openerp__.py

@ -21,7 +21,7 @@
{ {
'name': 'Export Current View', 'name': 'Export Current View',
'version': '8.0.1.2.0',
'version': '8.0.1.3.0',
'category': 'Web', 'category': 'Web',
'author': "Agile Business Group,Odoo Community Association (OCA)", 'author': "Agile Business Group,Odoo Community Association (OCA)",
'website': 'http://www.agilebg.com', 'website': 'http://www.agilebg.com',

74
web_export_view/static/src/js/web_export_view.js

@ -32,12 +32,13 @@ openerp.web_export_view = function (instance) {
} }
}, },
on_sidebar_export_view_xls: function () {
on_sidebar_export_view_xls: function (e, active_domain) {
// 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(), view = this.getParent(),
children = view.getChildren();
children = view.getChildren(),
deferred = new jQuery.Deferred();
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') {
@ -60,56 +61,47 @@ openerp.web_export_view = function (instance) {
export_columns_names.push(this.string); export_columns_names.push(this.string);
} }
}); });
rows = view.$el.find('.oe_list_content > tbody > tr');
export_rows = [];
$.each(rows, function () {
$row = $(this);
// find only rows with data
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);
text = cell.text || cell.textContent || cell.innerHTML || "";
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 = $('<div>' + cell.innerHTML + '</div>');
if (data_id.find('input').get(0).checked) {
export_row.push(_t("True"));
}
else {
export_row.push(_t("False"));
}
}
else if (cell.classList.contains("oe_list_field_integer")) {
var tmp2 = text;
do {
tmp = tmp2;
tmp2 = tmp.replace(instance.web._t.database.parameters.thousands_sep, "");
} while (tmp !== tmp2);
export_row.push(parseInt(tmp2));
if(view.$(
'tr.oe_list_header_columns > th > ' +
'input.oe_list_record_selector:checked'
).length == 0) {
row_ids = view.$(
'.oe_list_content > tbody > tr[data-id]' +
':has(th.oe_list_record_selector > input:checked)'
).map(function() {
return parseInt(jQuery(this).data('id'));
}).toArray();
deferred = view.dataset.read_ids(row_ids, export_columns_keys);
} }
else { else {
export_row.push(text.trim());
deferred = view.dataset.read_slice(export_columns_keys);
export_columns_names.push(
String(view.dataset.domain || _('All records'))
);
} }
});
return deferred.then(function(records) {
var export_rows = [];
$.each(records, function(index, record) {
var export_row = [],
record = new instance.web.list.Record(record).toForm();
$.each(view.visible_columns, function() {
export_row.push(
this.type != 'integer' && this.type != 'float' ?
this.format(
record.data, {process_modifiers: false}
) : record.data[this.id].value
);
})
export_rows.push(export_row); export_rows.push(export_row);
}
}
}); });
$.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, model: view.model,
headers: export_columns_names, headers: export_columns_names,
rows: export_rows
rows: export_rows,
})}, })},
complete: $.unblockUI
});
}); });
} }
}); });

Loading…
Cancel
Save