diff options
| author | Aaron Bohy <aab@odoo.com> | 2020-03-03 13:33:13 +0000 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2020-03-09 14:14:39 +0000 |
| commit | 43ce727568bd92a0f3f019cd4f5b6a1815a1960a (patch) | |
| tree | 4bc917b08a1cbee7e7c753ef2e907091c4388cf1 /addons/web/static/tests/fields/relational_fields | |
| parent | f894b6a1d88f8ac946bc3481668e6556f72e83c0 (diff) | |
[FIX] web: save all values returned by onchange
Let's assume a form view with a boolean field and a one2many field,
displayed for instance with widget many2many_tags. There is an
onchange on the boolean field, which populates the one2many, e.g.
[[5], [0, 0, {display_name: 'name', other_field: 'value'}]]
Before this commit, only the display_name was sent to the server on
save, because 'other_field' is unknown by the webclient.
Similar situations occurred with one2manys displayed as lists, and
onchanges returning values for fields that aren't in the list.
These situations probably didn't exist in Odoo yet, but a pending
task on website event adds one.
This commit ensures that all values returned by the onchange for
the x2many subrecords are sent back to the server when the user
saves.
closes odoo/odoo#46807
Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields')
| -rw-r--r-- | addons/web/static/tests/fields/relational_fields/field_one2many_tests.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js b/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js index 3ae0c69bfda..e24341b1019 100644 --- a/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js +++ b/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js @@ -9161,6 +9161,53 @@ QUnit.module('fields', {}, function () { form.destroy(); }); + + QUnit.test('one2many value returned by onchange with unknown fields', async function (assert) { + assert.expect(3); + + this.data.partner.onchanges = { + bar: function (obj) { + obj.p = [ + [5], + [0, 0, { + bar: true, + display_name: "coucou", + trululu: [2, 'second record'], + turtles: [[5], [0, 0, {turtle_int: 4}]], + }] + ]; + }, + }; + + const form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: ` + <form> + <field name="bar"/> + <field name="p" widget="many2many_tags"/> + </form>`, + mockRPC(route, args) { + if (args.method === 'create') { + assert.deepEqual(args.args[0].p[0][2], { + bar: true, + display_name: "coucou", + trululu: 2, + turtles: [[5], [0, 0, {turtle_int: 4}]], + }); + } + return this._super(...arguments); + }, + }); + + assert.containsOnce(form, '.o_field_many2manytags .badge'); + assert.strictEqual(form.$('.o_field_many2manytags .o_badge_text').text(), 'coucou'); + + await testUtils.form.clickSave(form); + + form.destroy(); + }); }); }); }); |
