diff options
| author | Martin Geubelle <mge@odoo.com> | 2017-09-07 17:19:38 +0200 |
|---|---|---|
| committer | Martin Geubelle <mge@odoo.com> | 2017-09-08 12:27:43 +0200 |
| commit | 14cb9af0d672e544484d6dc7b3432722217f4e10 (patch) | |
| tree | 5a7e2cd2525d7657d52de3b4dc59d7f44780e961 /addons/web/static/tests/fields/relational_fields_tests.js | |
| parent | b2c916de836d55e2c6deb0c0f344de51de86ba63 (diff) | |
[FIX] web: only send changed fields on one2many after onchange
The server response to an `onchange` on a one2many is a list of
commands. In case of one2many update (command 1), the server
returns all fields (and not only the modified ones).
When saving the record, this is the client responsability to
specify which fields really changed.
Before this commit, all fields were sent at `write` and not only
the changed ones. This was causing issues when the user couldn't
write on the field ; an error was triggered even though the user
didn't change anything.
To fix this, we only tag as changed (in the datapoint `_changes`
attribute) the fields that have a different value after the onchange.
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields_tests.js')
| -rw-r--r-- | addons/web/static/tests/fields/relational_fields_tests.js | 70 |
1 files changed, 70 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 d318255b82a..45110c7cf9a 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -106,6 +106,8 @@ QUnit.module('relational_fields', { turtle_qux: {string: "Qux", type: "float", digits: [16,1], required: true, default: 1.5}, turtle_description: {string: "Description", type: "text"}, turtle_trululu: {string: "Trululu", type: "many2one", relation: 'partner'}, + turtle_ref: {string: "Reference", type: 'reference', selection: [ + ["product", "Product"], ["partner", "Partner"]]}, product_id: {string: "Product", type: "many2one", relation: 'product', required: true}, partner_ids: {string: "Partner", type: "many2many", relation: 'partner'}, }, @@ -125,11 +127,13 @@ QUnit.module('relational_fields', { }, { id: 3, display_name: "raphael", + product_id: 37, turtle_bar: false, turtle_foo: "kawa", turtle_int: 21, turtle_qux: 9.8, partner_ids: [], + turtle_ref: 'product,37', }], }, user: { @@ -3416,6 +3420,72 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('one2many and onchange only write modified field', function (assert) { + assert.expect(2); + + this.data.partner.onchanges = { + turtles: function (obj) { + obj.turtles = [ + [5], // delete all + [1, 3, { // the server returns all fields + display_name: "coucou", + product_id: [37, "xphone"], + turtle_bar: false, + turtle_foo: "has changed", + turtle_int: 42, + turtle_qux: 9.8, + partner_ids: [], + turtle_ref: 'product,37', + }], + ]; + }, + }; + + this.data.partner.records[0].turtles = [3]; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'<form string="Partners">' + + '<field name="foo"/>' + + '<field name="turtles">' + + '<tree editable="bottom">' + + '<field name="display_name"/>' + + '<field name="product_id"/>' + + '<field name="turtle_bar"/>' + + '<field name="turtle_foo"/>' + + '<field name="turtle_int"/>' + + '<field name="turtle_qux"/>' + + '<field name="turtle_ref"/>' + + '</tree>' + + '</field>' + + '</form>', + mockRPC: function (method, args) { + if (args.method === 'write') { + // debugger; + assert.deepEqual(args.args[1].turtles, [ + [1, 3, {display_name: 'coucou', turtle_foo: 'has changed', turtle_int: 42}], + ], "correct commands should be sent (only send changed values)"); + } + return this._super.apply(this, arguments); + }, + res_id: 1, + viewOptions: { + mode: 'edit', + }, + }); + + assert.strictEqual(form.$('.o_data_row').length, 1, + "o2m should contain one row"); + + form.$('.o_field_one2many .o_list_view tbody tr:first td:first').click(); + form.$('.o_field_one2many .o_list_view tbody tr:first input:first').val('blurp').trigger('input'); + + form.$buttons.find('.o_form_button_save').click(); + form.destroy(); + }); + QUnit.test('one2many list (editable): readonly domain is evaluated', function (assert) { assert.expect(2); |
