diff options
| author | Aaron Bohy <aab@odoo.com> | 2017-05-02 12:45:07 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-05-02 15:34:43 +0200 |
| commit | c891463e509a327fc8bc1a2c4fa0fae1e00f0bab (patch) | |
| tree | df33035a58d3e8d6aa5bbb1299483f52ad2617a2 /addons/web/static/tests/fields/relational_fields_tests.js | |
| parent | e9dce2c7b655d0f0b2b1075c05a37a190f1f6473 (diff) | |
[FIX] web: BasicModel: apply onchange after x2m edition
When a record is added in an x2many field with an onchange, the
onchange is only triggered once the new record is valid (i.e. when
all its required fields have a correct value).
However, there was an issue in the code checking the validity of
a record, as it iterated on all known fields of the model (instead
of those in the view), so if there were required fields that
weren't, the record was always invalid (as those fields obviously
never had a value), and thus the onchange was never done.
This wasn't a problem with embedded views as in this case, the
known fields are those in the view. But when the view isn't
embedded, all fields of the related model are known, even if only
some of them are in the view.
This was the case for example in the stock.picking form view, when
adding a line in the stock.move o2m: the onchange wasn't done and
thus, the schedule date wasn't correctly set.
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields_tests.js')
| -rw-r--r-- | addons/web/static/tests/fields/relational_fields_tests.js | 52 |
1 files changed, 52 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 4a1d7b5bdbb..0629dfc4da1 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -2949,6 +2949,58 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('one2many list editable: trigger when row is valid', function (assert) { + // should omit require fields that aren't in the view as they (obviously) + // have no value, when checking the validity of required fields + assert.expect(7); + + this.data.turtle.fields.turtle_foo.required = true; + this.data.turtle.fields.turtle_qux.required = true; // required field not in the view + this.data.partner.onchanges = { + turtles: function (obj) { + obj.int_field = obj.turtles.length; + }, + }; + this.data.partner.records[0].int_field = 0; + this.data.partner.records[0].turtles = []; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form string="Partners">' + + '<field name="int_field"/>' + + '<field name="turtles"/>' + + '</form>', + mockRPC: function (route, args) { + assert.step(args.method); + return this._super.apply(this, arguments); + }, + archs: { + 'turtle,false,list' : '<tree editable="top">' + + '<field name="turtle_int"/>' + + '<field name="turtle_foo"/>' + + '</tree>', + }, + res_id: 1, + }); + form.$buttons.find('.o_form_button_edit').click(); + + assert.strictEqual(form.$('.o_form_field[name="int_field"]').val(), "0", + "int_field should start with value 0"); + form.$('.o_form_field_x2many_list_row_add a').click(); + assert.strictEqual(form.$('.o_form_field[name="int_field"]').val(), "0", + "int_field should still be 0 (no onchange should have been done yet"); + + assert.verifySteps(['read', 'default_get'], "no onchange should have been applied"); + + form.$('.o_field_widget[name="turtle_foo"]').val("some text").trigger('input'); + assert.strictEqual(form.$('.o_form_field[name="int_field"]').val(), "1", + "int_field should now be 1 (the onchange should have been done"); + + form.destroy(); + }); + QUnit.module('FieldMany2Many'); QUnit.test('many2many kanban: edition', function (assert) { |
