[FIX] resolve m2m content to record names in list view

bzr revid: xmo@openerp.com-20120928113524-1jw0uj3nccupcjjq
This commit is contained in:
Xavier Morel 2012-09-28 13:35:24 +02:00
parent d6ba1b61f8
commit 6f16fc3df9
2 changed files with 25 additions and 0 deletions

View File

@ -138,6 +138,9 @@ instance.web.format_value = function (value, descriptor, value_if_empty) {
return value[1];
case 'one2many':
case 'many2many':
if (typeof value === 'string') {
return value;
}
return _.str.sprintf(_t("(%d records)"), value.length);
case 'datetime':
if (typeof(value) == "string")

View File

@ -1010,6 +1010,28 @@ instance.web.ListView.List = instance.web.Class.extend( /** @lends instance.web.
record.set(column.id, names[0]);
});
}
} else if (column.type === 'many2many') {
value = record.get(column.id);
// non-resolved (string) m2m values are arrays
if (value instanceof Array && !_.isEmpty(value)) {
var ids;
// they come in two shapes:
if (value[0] instanceof Array) {
var command = value[0];
// 1. an array of m2m commands (usually (6, false, ids))
if (command[0] !== 6) {
throw new Error(_t("Unknown m2m command ") + command[0]);
}
ids = command[2];
} else {
// 2. an array of ids
ids = value;
}
new instance.web.Model(column.relation)
.call('name_get', [ids]).then(function (names) {
record.set(column.id, _(names).pluck(1).join(', '));
})
}
}
return column.format(record.toForm().data, {
model: this.dataset.model,