mirror of https://github.com/OCA/web.git
[FIX] x2many fields
parent
2f3b763f37
commit
b71c1b626a
|
@ -37,6 +37,7 @@ openerp.web_export_view = function (instance) {
|
||||||
// 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(),
|
||||||
|
fields_view = view.fields_view,
|
||||||
children = view.getChildren(),
|
children = view.getChildren(),
|
||||||
deferred = new jQuery.Deferred();
|
deferred = new jQuery.Deferred();
|
||||||
if (children) {
|
if (children) {
|
||||||
|
@ -79,6 +80,55 @@ openerp.web_export_view = function (instance) {
|
||||||
String(view.dataset.domain || _('All records'))
|
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) {
|
return deferred.then(function(records) {
|
||||||
var export_rows = [];
|
var export_rows = [];
|
||||||
$.each(records, function(index, record) {
|
$.each(records, function(index, record) {
|
||||||
|
|
Loading…
Reference in New Issue