[FIX] web: consider correct viewtype when loading data

Before this commit, when loading the data and calling the prostprocess,
the viewType was not correctly passed which could lead to broken
behaviour. For example, if one was to load a record from a list view
embedded in a form view, the viewtype passed was the list which
prevented to load the data from the form view.

OPW 1891295

closes odoo/odoo#28279
This commit is contained in:
Rémi Rahir
2018-10-30 09:24:39 +00:00
committed by len-odoo
parent 854208370c
commit a219bdb85e
2 changed files with 46 additions and 2 deletions
@@ -3573,11 +3573,12 @@ var BasicModel = AbstractModel.extend({
*/
_postprocess: function (record, options) {
var self = this;
var viewType = options && options.viewType || record.viewType;
var defs = [];
_.each(record.getFieldNames(options), function (name) {
var field = record.fields[name];
var fieldInfo = record.fieldsInfo[record.viewType][name] || {};
var fieldInfo = record.fieldsInfo[viewType][name] || {};
var options = fieldInfo.options || {};
if (options.always_reload) {
if (record.fields[name].type === 'many2one' && record.data[name]) {
@@ -3586,7 +3587,7 @@ var BasicModel = AbstractModel.extend({
model: field.relation,
method: 'name_get',
args: [element.data.id],
context: self._getContext(record, {fieldName: name}),
context: self._getContext(record, {fieldName: name, viewType: viewType}),
})
.then(function (result) {
element.data.display_name = result[0][1];
@@ -380,6 +380,49 @@ QUnit.module('relational_fields', {
form.destroy();
});
QUnit.test('show_address works in a view embedded in a view of another type', function (assert) {
assert.expect(1);
this.data.turtle.records[1].turtle_trululu = 2;
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<field name="display_name"/>' +
'<field name="turtles"/>' +
'</form>',
res_id: 1,
archs: {
"turtle,false,form": '<form string="T">' +
'<field name="display_name"/>' +
'<field name="turtle_trululu" context="{\'show_address\': 1}" options="{\'always_reload\': True}"/>' +
'</form>',
"turtle,false,list": '<tree editable="bottom">' +
'<field name="display_name"/>' +
'</tree>',
},
mockRPC: function (route, args) {
if (args.method === 'name_get') {
return this._super(route, args).then(function (result) {
if (args.model === 'partner' && args.kwargs.context.show_address) {
result[0][1] += '\nrue morgue\nparis 75013';
}
return result;
});
}
return this._super(route, args);
},
});
// click the turtle field, opens a modal with the turtle form view
form.$('.o_data_row:first td.o_data_cell').click();
assert.strictEqual($('[name="turtle_trululu"]').text(), "second recordrue morgueparis 75013",
"The partner's address should be displayed");
form.destroy();
});
QUnit.test('many2ones in form views with search more', function (assert) {
assert.expect(3);
this.data.partner.records.push({