Skip to content

Commit

Permalink
[FIX] web: reload many2one data if the context has changed
Browse files Browse the repository at this point in the history
When a view is loaded, it checks which fields it has to load.
In the case of a many2one, it could be the case that a context key is present in
one view and not in the other; if it happens, we should reload the data, as a
name_get result could vary.

opw 1891295

closes odoo#28298
  • Loading branch information
len-odoo committed Oct 31, 2018
1 parent a219bdb commit 180f528
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
8 changes: 8 additions & 0 deletions addons/web/static/src/js/views/basic/basic_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ var BasicView = AbstractView.extend({
}
}
}
// Many2one: context is not the same between the different views
// this means the result of a name_get could differ
if (fieldType === 'many2one') {
if (JSON.stringify(record.data[name].context) !==
JSON.stringify(fieldInfo.context)) {
fieldNames.push(name);
}
}
}
});

Expand Down
44 changes: 44 additions & 0 deletions addons/web/static/tests/fields/relational_fields_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,50 @@ QUnit.module('relational_fields', {
form.destroy();
});

QUnit.test('many2one data is reloaded if there is a context to take into account', 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"/>' +
'<field name="turtle_trululu"/>' +
'</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').click();

assert.strictEqual($('.modal [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({
Expand Down

0 comments on commit 180f528

Please sign in to comment.