[FIX] web: basicmodel: properly link parent in m2m

In some cases, the parentID was not properly set, which is a problem
when we need to evaluate the parent in a context.

Note: I also added a better error explanation in the mock server, to
make it better for the developper to see what is wrong.
This commit is contained in:
Parth Gajjar
2017-06-01 11:26:53 +02:00
committed by Géry Debongnie
parent eb24f96448
commit d24ea500e6
3 changed files with 38 additions and 0 deletions
@@ -1168,6 +1168,7 @@ var BasicModel = AbstractModel.extend({
fieldsInfo: view ? view.fieldsInfo : fieldInfo.fieldsInfo,
res_id: d.id,
viewType: view ? view.type : fieldInfo.viewType,
parentID: list.id,
});
list_records[d.id] = rec;
list._changes.push(rec.id);
@@ -196,6 +196,9 @@ var MockServer = Class.extend({
// 'transfer_field_to_modifiers' simulation
var field = fields[node.attrs.name];
if (!field) {
throw new Error("Field " + node.attrs.name + " does not exist");
}
var defaultValues = {};
var stateExceptions = {};
_.each(modifiersNames, function (attr) {
@@ -407,6 +407,40 @@ QUnit.module('Views', {
model.destroy();
});
QUnit.test('many2many with ADD_M2M command and context with parent key', function (assert) {
assert.expect(1);
this.data.partner_type.fields.some_char = {type: "char"};
this.params.fieldsInfo = {
default: {
category: {
fieldsInfo: {default: {some_char: { context: "{'a': parent.foo}"}}},
relatedFields: {some_char: {type: "char"}},
viewType: 'default',
},
foo: {},
},
};
var model = createModel({
Model: BasicModel,
data: this.data,
});
model.load(this.params).then(function (resultID) {
var changes = {
category: {operation: 'ADD_M2M', ids: [{id: 12}]}
};
model.notifyChanges(resultID, changes).then(function () {
var record = model.get(resultID);
var categoryRecord = record.data.category.data[0];
assert.deepEqual(categoryRecord.getContext({fieldName: 'some_char'}), {a:'gnap'},
"should properly evaluate context");
});
});
model.destroy();
});
QUnit.test('can fetch a list', function (assert) {
assert.expect(4);