[FIX] m2o values display in list views (mostly under onchange condition)

Normal m2o values are pairs of (id, name) (name_get format, basically)
but in some cases (lazyness & al), APIs (often onchange results) only
return the `id` part, which is not sufficient to display the m2o
as-is, a name_get has to be performed.

Added an intermediate step in displaying a table cell (in list view):
if we're displaying an m2o cell (~a cell for an m2o column) and the
value is a number, then dispatch a name_get and keep trucking (display
the rows without the m2o values).

When the name_get returns, it will simply refresh the row and diplay
the m2o name.

bzr revid: xmo@openerp.com-20111014084310-pv2mmmy28fwwk9sm
This commit is contained in:
Xavier Morel 2011-10-14 10:43:10 +02:00
parent 55af4c6c9f
commit 405beaa3c6
2 changed files with 23 additions and 3 deletions

View File

@ -785,6 +785,26 @@ openerp.web.ListView.List = openerp.web.Class.extend( /** @lends openerp.web.Lis
[this.records.at(this.dataset.index).get('id'),
this.dataset]);
},
render_cell: function (record, column) {
if (column.type === 'many2one') {
var value = record.get(column.id);
// m2o values are usually name_get formatted, [Number, String]
// pairs, but in some cases only the id is provided. In these
// cases, we need to perform a name_get call to fetch the actual
// displayable value
if (typeof value === 'number' || value instanceof Number) {
// fetch the name, set it on the record (in the right field)
// and let the various registered events handle refreshing the
// row
new openerp.web.DataSet(this.view, column.relation)
.name_get([value], function (names) {
if (!names.length) { return; }
record.set(column.id, names[0]);
});
}
}
return openerp.web.format_cell(record.toForm().data, column);
},
render: function () {
if (this.$current) {
this.$current.remove();
@ -792,7 +812,7 @@ openerp.web.ListView.List = openerp.web.Class.extend( /** @lends openerp.web.Lis
this.$current = this.$_element.clone(true);
this.$current.empty().append(
QWeb.render('ListView.rows', _.extend({
render_cell: openerp.web.format_cell}, this)));
render_cell: $.proxy(this, 'render_cell')}, this)));
this.pad_table_to(5);
},
pad_table_to: function (count) {
@ -900,7 +920,7 @@ openerp.web.ListView.List = openerp.web.Class.extend( /** @lends openerp.web.Lis
record: record,
row_parity: (index % 2 === 0) ? 'even' : 'odd',
view: this.view,
render_cell: openerp.web.format_cell
render_cell: $.proxy(this, 'render_cell')
});
},
/**

View File

@ -636,7 +636,7 @@
<td t-if="!column.meta and column.invisible !== '1'" t-att-title="column.help"
t-att-class="'oe-field-cell' + (align ? ' oe-number' : '')"
t-att-data-field="column.id">
<t t-raw="render_cell(record.toForm().data, column)"/>
<t t-raw="render_cell(record, column)"/>
</td>
</t>
<td t-if="options.deletable" class='oe-record-delete' width="1">