[FIX] web: properly compute contexts in some cases
When we have a many2one widget in a one2many, editable, the context was not properly computed: it expected the parent to be a record object, but in that case, it is a list object.
This commit is contained in:
committed by
Aaron Bohy
parent
7465798ccd
commit
d7eb116fa8
@@ -1555,6 +1555,9 @@ var BasicModel = AbstractModel.extend({
|
||||
var evalContext = this.get(element.id, {raw: true}).data;
|
||||
if (element.parentID) {
|
||||
var parent = this.get(element.parentID, {raw: true});
|
||||
if (parent.type === 'list' && this.localData[element.parentID].parentID) {
|
||||
parent = this.get(this.localData[element.parentID].parentID, {raw: true});
|
||||
}
|
||||
_.extend(evalContext, {parent: parent.data});
|
||||
}
|
||||
context.set_eval_context(evalContext);
|
||||
@@ -1846,11 +1849,12 @@ var BasicModel = AbstractModel.extend({
|
||||
dataPoint = self.localData[list._cache[id]];
|
||||
} else {
|
||||
dataPoint = self._makeDataPoint({
|
||||
modelName: list.model,
|
||||
data: _.findWhere(records, {id: id}),
|
||||
fields: list.fields,
|
||||
fieldNames: list.fieldNames,
|
||||
fieldAttrs: list.fieldAttrs,
|
||||
fieldNames: list.fieldNames,
|
||||
fields: list.fields,
|
||||
modelName: list.model,
|
||||
parentID: list.id,
|
||||
});
|
||||
|
||||
// add many2one records
|
||||
@@ -1862,7 +1866,8 @@ var BasicModel = AbstractModel.extend({
|
||||
data: {
|
||||
id: dataPoint.data[name][0],
|
||||
display_name: dataPoint.data[name][1],
|
||||
}
|
||||
},
|
||||
parentID: dataPoint.id,
|
||||
});
|
||||
|
||||
dataPoint.data[name] = r.id;
|
||||
@@ -1905,6 +1910,7 @@ var BasicModel = AbstractModel.extend({
|
||||
fieldNames: list.fieldNames,
|
||||
fieldAttrs: list.fieldAttrs,
|
||||
modelName: list.model,
|
||||
parentID: list.id,
|
||||
});
|
||||
|
||||
// add many2one records
|
||||
|
||||
@@ -1431,6 +1431,44 @@ QUnit.module('relational_fields', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('one2many list, editable, with many2one and with context with parent key', function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
this.data.partner.records[0].p = [2];
|
||||
this.data.partner.records[1].product_id = 37;
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form string="Partners">' +
|
||||
'<field name="foo"/>' +
|
||||
'<field name="p">' +
|
||||
'<tree editable="bottom">' +
|
||||
'<field name="product_id" context="{\'partner_foo\':parent.foo}"/>' +
|
||||
'</tree>' +
|
||||
'</field>' +
|
||||
'</form>',
|
||||
res_id: 1,
|
||||
mockRPC: function (route, args) {
|
||||
if (args.method === 'name_search') {
|
||||
assert.strictEqual(args.kwargs.context.partner_foo, "yop",
|
||||
"should have correctly evaluated parent foo field");
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
});
|
||||
|
||||
form.$buttons.find('.o_form_button_edit').click();
|
||||
|
||||
form.$('tr.o_data_row:eq(0) td:contains(xphone)').click();
|
||||
|
||||
// trigger a name search
|
||||
form.$('table td input.o_form_input').click();
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('one2many list edition, some basic functionality', function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user