diff options
| author | Adrien Dieudonne <adr@odoo.com> | 2017-04-24 08:02:06 +0200 |
|---|---|---|
| committer | Adrien Dieudonne <adr@odoo.com> | 2017-04-24 17:29:52 +0200 |
| commit | fcc5ce9d4621eeb307475e5152ce820f9bc0a306 (patch) | |
| tree | 3b03898b9cf6bfbf999695125a2f0cd8aa83ee45 /addons/web/static/tests/views/basic_model_tests.js | |
| parent | 6d4e223c18c44f8429b324ccb41845d148a6e76d (diff) | |
[FIX] web: BasicModel: handle many2many default values
Before this fix, default values for many2many fields (i.e. 'replace' commands)
weren't correctly handled by the model, so the default values weren't set for
those fields.
Diffstat (limited to 'addons/web/static/tests/views/basic_model_tests.js')
| -rw-r--r-- | addons/web/static/tests/views/basic_model_tests.js | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/addons/web/static/tests/views/basic_model_tests.js b/addons/web/static/tests/views/basic_model_tests.js index ec9700b66f3..2c8ced4b217 100644 --- a/addons/web/static/tests/views/basic_model_tests.js +++ b/addons/web/static/tests/views/basic_model_tests.js @@ -462,7 +462,7 @@ QUnit.module('Views', { }); QUnit.test('can make a default_record, no onchange', function (assert) { - assert.expect(3); + assert.expect(5); this.params.context = {}; this.params.fieldNames = ['product_id', 'category', 'product_ids']; @@ -472,6 +472,10 @@ QUnit.module('Views', { var model = createModel({ Model: BasicModel, data: this.data, + mockRPC: function (route, args) { + assert.step(args.method); + return this._super(route, args); + }, }); model.load(this.params).then(function (resultID) { @@ -480,6 +484,53 @@ QUnit.module('Views', { assert.deepEqual(record.data.product_ids.data, [], "o2m default should be []"); assert.deepEqual(record.data.category.data, [], "m2m default should be []"); }); + + assert.verifySteps(['default_get'], + "there should be default_get"); + + model.destroy(); + }); + + QUnit.test('can make a default_record with default relational values', function (assert) { + assert.expect(7); + + this.data.partner.fields.product_id.default = 37; + this.data.partner.fields.product_ids.default = [ + [0, false, {name: 'xmac'}], + [0, false, {name: 'xcloud'}] + ]; + this.data.partner.fields.category.default = [ + [6, false, [12, 14]] + ]; + + this.params.fieldNames = ['product_id', 'category', 'product_ids']; + this.params.res_id = undefined; + this.params.type = 'record'; + + var model = createModel({ + Model: BasicModel, + data: this.data, + mockRPC: function (route, args) { + assert.step(args.method); + return this._super(route, args); + }, + }); + + model.load(this.params).then(function (resultID) { + var record = model.get(resultID); + assert.deepEqual(record.data.product_id.data.display_name, 'xphone', + "m2o default should be xphone"); + assert.deepEqual(record.data.product_ids.data.length, + 2, "o2m default should have two records"); + assert.deepEqual(record.data.product_ids.data[0].data.name, + 'xmac', "first o2m default value should be xmac"); + assert.deepEqual(record.data.category.res_ids, [12, 14], + "m2m default should be [12, 14]"); + }); + + assert.verifySteps(['default_get', 'name_get'], + "there should be default_get and name_get"); + model.destroy(); }); |
