[FIX] web: calendar: allow to use fields.Reference

Before this change, fields.Reference displayed into the popover of
a calendar view was always empty. This was because the popover view
generated from a double click on an element in the calendar view
creates its own recordModel in JS and the function to create this
record did not handle the reference field case.

This commit detects if a reference field is defined into the record
and adds the necessary processing to process its value and creates
the corresponding dataPoint.

opw 2151635
Closes #41262

closes odoo/odoo#42707

Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
Co-authored-by: Aaron Bohy <aab@odoo.com>
This commit is contained in:
Laurent Mignon (ACSONE)
2020-01-03 15:46:17 +00:00
committed by Aaron Bohy
co-authored by Aaron Bohy
parent a2a1e294d7
commit ae7f574e54
2 changed files with 37 additions and 0 deletions
@@ -818,6 +818,16 @@ var BasicModel = AbstractModel.extend({
defs.push(self._fetchNameGet(dataPoint));
}
}
} else if (field.type === 'reference' && field.value) {
const ref = field.value.split(',');
dataPoint = self._makeDataPoint({
context: record.context,
data: { id: parseInt(ref[1], 10) },
modelName: ref[0],
parentID: record.id,
});
defs.push(self._fetchNameGet(dataPoint));
record.data[field.name] = dataPoint.id;
} else if (field.type === 'one2many' || field.type === 'many2many') {
var relatedFieldsInfo = {};
relatedFieldsInfo.default = {};
@@ -1884,6 +1884,33 @@ odoo.define('web.basic_model_tests', function (require) {
model.destroy();
});
QUnit.test('call makeRecord with a reference field', async function (assert) {
assert.expect(2);
let rpcCount = 0;
const model = createModel({
Model: BasicModel,
data: this.data,
mockRPC: function (route, args) {
rpcCount++;
return this._super(route, args);
},
});
const field = this.data.partner.fields.reference;
const recordID = await model.makeRecord('coucou', [{
name: 'reference',
type: 'reference',
selection: field.selection,
value: 'product,37',
}]);
const record = model.get(recordID);
assert.deepEqual(record.data.reference.data, { id: 37, display_name: 'xphone' });
assert.strictEqual(rpcCount, 1);
model.destroy();
});
QUnit.test('check id, active_id, active_ids, active_model values in record\'s context', async function (assert) {
assert.expect(2);