[IMP] fix mistake done while merging ref-in-listviews, improve discrimination between ref-value and printable value

* Removed a test on splitting on ',' yielding more than one value, which means we're going to loop on the name_get since they're all strings
* Improved value-detection: we should only name_get the reference field if the value is an actual reference value, meaning a model name, a ',' and an id. Used regex instead of naive split, so we don't match referenced names with a comma (e.g. 'Hubert de Vaucanson, Vicomte de Blois')

bzr revid: xmo@openerp.com-20111018105255-6vz6l9lg1iiurfc9
This commit is contained in:
Xavier Morel 2011-10-18 12:52:55 +02:00
parent 7b600e82c4
commit 8c9d65c41a
1 changed files with 9 additions and 4 deletions

View File

@ -796,13 +796,18 @@ openerp.web.ListView.List = openerp.web.Class.extend( /** @lends openerp.web.Lis
var value;
if(column.type === 'reference') {
value = record.get(column.id);
if (value) {
var ref_match;
// Ensure that value is in a reference "shape", otherwise we're
// going to loop on performing name_get after we've resolved (and
// set) a human-readable version. m2o does not have this issue
// because the non-human-readable is just a number, where the
// human-readable version is a pair
if (value && (ref_match = /([\w\.]+),(\d+)/.exec(value))) {
// reference values are in the shape "$model,$id" (as a
// string), we need to split and name_get this pair in order
// to get a correctly displayable value in the field
var ref = value.split(','),
model = ref[0],
id = parseInt(ref[1], 10);
var model = ref_match[1],
id = parseInt(ref_match[2], 10);
new openerp.web.DataSet(this.view, model).name_get([id], function(names) {
if (!names.length) { return; }
record.set(column.id, names[0][1]);