diff options
| author | Adrien Dieudonne <adr@odoo.com> | 2017-04-19 10:49:07 +0200 |
|---|---|---|
| committer | Adrien Dieudonne <adr@odoo.com> | 2017-04-20 13:08:14 +0200 |
| commit | ef3200f9409aab0a247e234154f18e77087ece05 (patch) | |
| tree | 35401aed2d247146f70dc68afe111ae799c42c54 /addons/web/static/tests/views/basic_model_tests.js | |
| parent | e18c63e007196c1502b25c79d65fdb3bf309c3b2 (diff) | |
[FIX] web: BasicModel: id in evalContext
The evalContext contains the current data of a record
(the value of the fields that have been fetched,
i.e. the ones referenced in the view).
However, 'id' is a particular field that should always
be in the evalContext, even if not in the view
(as we always know its value).
Before this rev., 'id' was in the evalContext if
the record already existed, but not on new records, so it crashed
on new records if 'id' was used in the context defined on a field's node.
Diffstat (limited to 'addons/web/static/tests/views/basic_model_tests.js')
| -rw-r--r-- | addons/web/static/tests/views/basic_model_tests.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/addons/web/static/tests/views/basic_model_tests.js b/addons/web/static/tests/views/basic_model_tests.js index 0cfbf36983e..cd290dd0a13 100644 --- a/addons/web/static/tests/views/basic_model_tests.js +++ b/addons/web/static/tests/views/basic_model_tests.js @@ -1242,4 +1242,38 @@ QUnit.module('Views', { model.destroy(); }); + QUnit.test('check id, active_id, active_ids, active_model values in record\'s context', function (assert) { + assert.expect(2); + + this.data.partner.fields.product_id.context = "{'id': id, 'active_id': active_id, 'active_ids': active_ids, 'active_model': active_model}"; + + var model = createModel({ + Model: BasicModel, + data: this.data, + }); + + this.params.fieldNames = ['product_id']; + + model.load(this.params).then(function (resultID) { + var recordPartner = model.get(resultID); + assert.deepEqual( + recordPartner.getContext({fieldName: "product_id"}), + {id: 2, active_id: 2, active_ids: [2], active_model: "partner"}, + "wrong values for id, active_id, active_ids or active_model"); + }); + + // Try again without record + this.params.res_id = undefined; + + model.load(this.params).then(function (resultID) { + var recordPartner = model.get(resultID); + assert.deepEqual( + recordPartner.getContext({fieldName: "product_id"}), + {id: false, active_id: false, active_ids: [], active_model: "partner"}, + "wrong values for id, active_id, active_ids or active_model. Have to be defined even if there is no record."); + }); + + model.destroy(); + }); + });}); |
