summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields/relational_fields_tests.js
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2018-06-12 16:05:18 +0200
committerSébastien Theys <seb@odoo.com>2018-06-29 10:39:42 +0200
commitb2c1d5ede2254e13bea32451faefa28a6eddcd4c (patch)
treee5621cacbda4541b9fe3c7ad114c47a8f5ac1bf1 /addons/web/static/tests/fields/relational_fields_tests.js
parent217fee2636fb4dc4c193e67e5727a9fcef200605 (diff)
[IMP] web: fix default sequence for list with handle
The sequence had a static default value, but when there is an handle, it's important that new items are added at the top or the bottom of the list. This is a rare case where the defaul_get from the server will be ignored by the view for a certain field. This will work: - both in editable mode (inline) and in dialog mode, - both for X2Many and standalone list.
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields_tests.js')
-rw-r--r--addons/web/static/tests/fields/relational_fields_tests.js131
1 files changed, 131 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 b96e21c2855..c4267c159d3 100644
--- a/addons/web/static/tests/fields/relational_fields_tests.js
+++ b/addons/web/static/tests/fields/relational_fields_tests.js
@@ -9074,6 +9074,137 @@ QUnit.module('relational_fields', {
form.destroy();
});
+ QUnit.test('one2many with sequence field, override default_get, bottom when inline', function (assert) {
+ assert.expect(2);
+
+ this.data.partner.records[0].turtles = [3, 2, 1];
+
+ this.data.turtle.fields.turtle_int.default = 10;
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners">' +
+ '<field name="turtles">' +
+ '<tree editable="bottom">' +
+ '<field name="turtle_int" widget="handle"/>' +
+ '<field name="turtle_foo"/>' +
+ '</tree>' +
+ '</field>' +
+ '</form>',
+ res_id: 1,
+ viewOptions: {
+ mode: 'edit',
+ },
+ });
+
+ // starting condition
+ assert.strictEqual($('.o_data_cell').text(), "blipyopkawa");
+
+ // click add a new line
+ // save the record
+ // check line is at the correct place
+
+ var inputText = 'ninja';
+ form.$('.o_field_x2many_list_row_add a').click();
+ form.$('.o_input[name="turtle_foo"]').val(inputText).trigger('input');
+ form.$buttons.find('.o_form_button_save').click();
+
+ assert.strictEqual($('.o_data_cell').text(), "blipyopkawa" + inputText);
+ form.destroy();
+ });
+
+ QUnit.test('one2many with sequence field, override default_get, top when inline', function (assert) {
+ assert.expect(2);
+
+ this.data.partner.records[0].turtles = [3, 2, 1];
+
+ this.data.turtle.fields.turtle_int.default = 10;
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners">' +
+ '<field name="turtles">' +
+ '<tree editable="top">' +
+ '<field name="turtle_int" widget="handle"/>' +
+ '<field name="turtle_foo"/>' +
+ '</tree>' +
+ '</field>' +
+ '</form>',
+ res_id: 1,
+ viewOptions: {
+ mode: 'edit',
+ },
+ });
+
+ // starting condition
+ assert.strictEqual($('.o_data_cell').text(), "blipyopkawa");
+
+ // click add a new line
+ // save the record
+ // check line is at the correct place
+
+ var inputText = 'ninja';
+ form.$('.o_field_x2many_list_row_add a').click();
+ form.$('.o_input[name="turtle_foo"]').val(inputText).trigger('input');
+ form.$buttons.find('.o_form_button_save').click();
+
+ assert.strictEqual($('.o_data_cell').text(), inputText + "blipyopkawa");
+ form.destroy();
+ });
+
+ QUnit.test('one2many with sequence field, override default_get, bottom when popup', function (assert) {
+ assert.expect(3);
+
+ this.data.partner.records[0].turtles = [3, 2, 1];
+
+ this.data.turtle.fields.turtle_int.default = 10;
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners">' +
+ '<field name="turtles">' +
+ '<tree>' +
+ '<field name="turtle_int" widget="handle"/>' +
+ '<field name="turtle_foo"/>' +
+ '</tree>' +
+ '<form>' +
+ // NOTE: at some point we want to fix this in the framework so that an invisible field is not required.
+ '<field name="turtle_int" invisible="1"/>' +
+ '<field name="turtle_foo"/>' +
+ '</form>' +
+ '</field>' +
+ '</form>',
+ res_id: 1,
+ viewOptions: {
+ mode: 'edit',
+ },
+ });
+
+ // starting condition
+ assert.strictEqual($('.o_data_cell').text(), "blipyopkawa");
+
+ // click add a new line
+ // save the record
+ // check line is at the correct place
+
+ var inputText = 'ninja';
+ $('.o_field_x2many_list_row_add a').click();
+ $('.o_input[name="turtle_foo"]').val(inputText).trigger('input');
+ $('.modal .modal-footer .btn-primary:first').click();
+
+ assert.strictEqual($('.o_data_cell').text(), "blipyopkawa" + inputText);
+
+ $('.o_form_button_save').click();
+ assert.strictEqual($('.o_data_cell').text(), "blipyopkawa" + inputText);
+ form.destroy();
+ });
+
QUnit.test('one2many with sequence field, fetch name_get from empty list', function (assert) {
// There was a bug where a RPC would fail because no route was set.
// The scenario is: