Browse Source

[FIX] x2many fields

pull/816/head
Holger Brunn 7 years ago
parent
commit
b71c1b626a
No known key found for this signature in database GPG Key ID: 1C9760FECA3AE18
  1. 50
      web_export_view/static/src/js/web_export_view.js

50
web_export_view/static/src/js/web_export_view.js

@ -37,6 +37,7 @@ openerp.web_export_view = function (instance) {
// or assume the main view is a list view and use that
var self = this,
view = this.getParent(),
fields_view = view.fields_view,
children = view.getChildren(),
deferred = new jQuery.Deferred();
if (children) {
@ -79,6 +80,55 @@ openerp.web_export_view = function (instance) {
String(view.dataset.domain || _('All records'))
);
}
var x2many = _(export_columns_keys).filter(function(field) {
return ['one2many', 'many2many']
.indexOf(fields_view.fields[field].type) > -1;
});
if(x2many.length) {
deferred = deferred.then(function(records) {
var name_gets = [], names = {};
_(records).chain().map(function(record) {
return _(record).chain().pairs().filter(function(pair)
{
return x2many.indexOf(pair[0]) > -1;
})
.value()
})
.flatten(true)
.groupBy(0)
.each(function(pairs, field) {
name_gets.push(
new instance.web.Model(
fields_view.fields[field].relation
)
.call('name_get', [
_(pairs).chain().pluck(1).flatten(true)
.value(),
view.dataset.get_context()
])
.then(function(name_gets) {
names[field] = _.object(name_gets);
})
);
})
return jQuery.when.apply(jQuery, name_gets)
.then(function() {
_(records).each(function(record) {
_(x2many).each(function(field) {
record[field] = _(record[field])
.map(function(id) {
return names[field][id];
})
.join(', ');
record[
_.str.sprintf('%s__display', field)
] = record[field];
});
});
return records;
});
});
}
return deferred.then(function(records) {
var export_rows = [];
$.each(records, function(index, record) {

Loading…
Cancel
Save