diff options
| author | Aaron Bohy <aab@odoo.com> | 2019-02-06 09:43:34 +0000 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2019-02-06 14:03:25 +0000 |
| commit | 495d475d1d3ab6726d7e5d5f2dd8044e60d1a3da (patch) | |
| tree | e331e5bd0a35980f3164701071384bd65b661f30 /addons/web/static/tests/fields/relational_fields_tests.js | |
| parent | 5fcf891e07bf61518e6bf0be0dc4f27859d45778 (diff) | |
[FIX] web: only call name_get when necessary
For many2one fields, 'default_get' only returns the id, whereas
'onchange' (like 'read') returns an array with id and display_name.
Before this rev., when creating a new record, we always called
'name_get' for all many2ones, whether or not their value was
obtained by 'default_get' or 'onchange', i.e. even if their
display_name was already known.
It may just look like unnecessary RPCs, but those RPCs could
actually cause a crash when the user has access to the main model
(and thus can access the display_name of the many2one thanks to
related sudo), but doesn't have access to the many2one comodel.
closes odoo/odoo#30892
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields_tests.js')
| -rw-r--r-- | addons/web/static/tests/fields/relational_fields_tests.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index e0ab5ae7a5f..316f5caeffd 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -2644,6 +2644,42 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('do not call name_get if display_name already known', function (assert) { + // default_get only returns the id for many2one fields + // onchange returns an array with the id and the display_name + // thus, when an onchange is performed, there is no need to call + // name_get as the display_name is alreay available + assert.expect(6); + + this.data.partner.fields.product_id.default = 37; + this.data.partner.onchanges = { + trululu: function (obj) { + obj.trululu = [1, 'first record']; + }, + }; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form><field name="trululu"/><field name="product_id"/></form>', + mockRPC: function (route, args) { + assert.step(args.method + ' on ' + args.model); + return this._super.apply(this, arguments); + }, + }); + + assert.strictEqual(form.$('.o_field_widget[name=trululu] input').val(), 'first record'); + assert.strictEqual(form.$('.o_field_widget[name=product_id] input').val(), 'xphone'); + assert.verifySteps([ + 'default_get on partner', + 'onchange on partner', + 'name_get on product', + ]); + + form.destroy(); + }); + QUnit.test('many2one in one2many: domain updated by an onchange', function (assert) { assert.expect(3); |
