diff options
| author | Laurent Mignon (ACSONE) <laurent.mignon@acsone.eu> | 2019-12-03 12:52:07 +0000 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2020-01-03 15:46:17 +0000 |
| commit | ae7f574e5446a7bc6c939fc273225b41e2296bf7 (patch) | |
| tree | 2b7b8cecf7bc645a80a5a8c6fb1e695042188383 | |
| parent | a2a1e294d7485ca839bb409129c860ad91c0b334 (diff) | |
[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>
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_model.js | 10 | ||||
| -rw-r--r-- | addons/web/static/tests/views/basic_model_tests.js | 27 |
2 files changed, 37 insertions, 0 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index 7e42ad6cfca..a4c6d0e8795 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -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 = {}; diff --git a/addons/web/static/tests/views/basic_model_tests.js b/addons/web/static/tests/views/basic_model_tests.js index 7a20552968e..326c8550bb5 100644 --- a/addons/web/static/tests/views/basic_model_tests.js +++ b/addons/web/static/tests/views/basic_model_tests.js @@ -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); |
