[FIX] web: X2Many read propagates field context

Most operations on X2Many widget possibly propagates a field context
(name_create, name_search, ...) but the original read or read on an
onchange does not.

With this changeset, the field context is also used in these instances.

The assertions added in the added test failed with:
  expected: ["world"], result: [undefined]
  expected: ["world","world"], result: [undefined,undefined]

fixes #29203
opw-1914466
closes #29866
This commit is contained in:
Nicolas Lempereur
2019-01-04 09:44:49 +00:00
parent 04369bab39
commit 3125d20da3
2 changed files with 35 additions and 2 deletions
@@ -1701,7 +1701,7 @@ var BasicModel = AbstractModel.extend({
model: list.model,
method: 'read',
args: [_.pluck(data, 'id'), fieldNames],
context: record.context,
context: _.extend({}, record.context, field.context),
}).then(function (records) {
_.each(records, function (record) {
list_records[record.id].data = record;
@@ -2543,7 +2543,7 @@ var BasicModel = AbstractModel.extend({
var ids = record.data[fieldName] || [];
var list = self._makeDataPoint({
count: ids.length,
context: record.context,
context: _.extend({}, record.context, field.context),
fieldsInfo: fieldsInfo,
fields: view ? view.fields : fieldInfo.relatedFields,
limit: fieldInfo.limit,
@@ -10943,6 +10943,39 @@ QUnit.module('relational_fields', {
form.destroy();
});
QUnit.test('many2many read, field context is properly sent', function (assert) {
assert.expect(4);
this.data.partner.fields.timmy.context = {hello: 'world'};
this.data.partner.records[0].timmy = [12];
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<field name="timmy" widget="many2many_tags"/>' +
'</form>',
res_id: 1,
mockRPC: function (route, args) {
if (args.method === 'read' && args.model === 'partner_type') {
assert.step(args.kwargs.context.hello);
}
return this._super.apply(this, arguments);
},
});
assert.verifySteps(['world']);
form.$buttons.find('.o_form_button_edit').click();
var $m2mInput = form.$('.o_field_many2manytags input');
$m2mInput.click();
$m2mInput.autocomplete('widget').find('li:first()').click();
assert.verifySteps(['world', 'world']);
form.destroy();
});
QUnit.module('FieldStatus');
QUnit.test('static statusbar widget on many2one field', function (assert) {