From 8859d25bc5b719734b7d02bc26adfd38dca79e56 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 15 Jun 2017 12:37:42 +0200 Subject: [FIX] web: FieldWidgets: use correct format/parse functions Field widgets must format and parse values according to the widget type, not to the field type. For example, if a monetary field is inserted in a form view with widget="float", the field's value must be formatted with the float formatter, not the montetary one. This wasn't the case before this rev. --- .../web/static/tests/fields/basic_fields_tests.js | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'addons/web/static/tests/fields/basic_fields_tests.js') diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 4b850b26d34..a2d0c100fd8 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -536,6 +536,35 @@ QUnit.module('basic_fields', { form.destroy(); }); + QUnit.test('float widget on monetary field', function (assert) { + assert.expect(1); + + this.data.partner.fields.monetary = {string: "Monetary", type: 'monetary'}; + this.data.partner.records[0].monetary = 9.99; + this.data.partner.records[0].currency_id = 1; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'
' + + '' + + '' + + '' + + '' + + '
', + res_id: 1, + session: { + currencies: _.indexBy(this.data.currency.records, 'id'), + }, + }); + + assert.strictEqual(form.$('.o_field_widget[name=monetary]').text(), '9.99', + 'value should be correctly formatted (with the float formatter)'); + + form.destroy(); + }); + QUnit.module('FieldEmail'); QUnit.test('email field in form view', function (assert) { -- cgit v1.2.3 From c62a4edcb04fb1e3d65dea056123cece72425b7e Mon Sep 17 00:00:00 2001 From: Martin Geubelle Date: Wed, 21 Jun 2017 16:43:21 +0200 Subject: [FIX] web: set 0 as default value for numeric fields When creating a new record, the numeric field default value should be 0 in order to avoid manually setting mandatory fields to 0. This behaviour has been removed with the new views but one wants to restore it. The `mockRead` function has also been adapted in this commit because the server returns 0 for unset numeric fields. --- addons/web/static/tests/fields/basic_fields_tests.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'addons/web/static/tests/fields/basic_fields_tests.js') diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index a2d0c100fd8..467d567a53d 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -394,7 +394,7 @@ QUnit.module('basic_fields', { QUnit.module('FieldFloat'); QUnit.test('float field when unset', function (assert) { - assert.expect(1); + assert.expect(2); var form = createView({ View: FormView, @@ -408,8 +408,10 @@ QUnit.module('basic_fields', { res_id: 4, }); - assert.ok(form.$('.o_field_widget').hasClass('o_field_empty'), - 'Non-set float field should be recognized as unset.'); + assert.notOk(form.$('.o_field_widget').hasClass('o_field_empty'), + 'Non-set float field should be considered as 0.'); + assert.strictEqual(form.$('.o_field_widget').text(), "0.000", + 'Non-set float field should be considered as 0.'); form.destroy(); }); @@ -1955,7 +1957,7 @@ QUnit.module('basic_fields', { QUnit.module('FieldInteger'); QUnit.test('integer field when unset', function (assert) { - assert.expect(1); + assert.expect(2); var form = createView({ View: FormView, @@ -1965,8 +1967,10 @@ QUnit.module('basic_fields', { res_id: 4, }); - assert.ok(form.$('.o_field_widget').hasClass('o_field_empty'), - 'Non-set integer field should be recognized as unset.'); + assert.notOk(form.$('.o_field_widget').hasClass('o_field_empty'), + 'Non-set integer field should be recognized as 0.'); + assert.strictEqual(form.$('.o_field_widget').text(), "0", + 'Non-set integer field should be recognized as 0.'); form.destroy(); }); -- cgit v1.2.3 From 378efa14449baeb19a8fb6a810b8db148971c0c1 Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Fri, 23 Jun 2017 15:36:09 +0200 Subject: [FIX] web: update filename correctly in binary fields The update_field event is not used anymore so it needs to trigger a field_changed instead. --- .../web/static/tests/fields/basic_fields_tests.js | 27 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'addons/web/static/tests/fields/basic_fields_tests.js') diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 467d567a53d..c492537c63f 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -1046,7 +1046,7 @@ QUnit.module('basic_fields', { QUnit.module('FieldBinary'); QUnit.test('binary fields are correctly rendered', function (assert) { - assert.expect(9); + assert.expect(16); // save the session function var oldGetFile = session.get_file; @@ -1059,18 +1059,24 @@ QUnit.module('basic_fields', { return $.when(); }; + this.data.partner.records[0].foo = 'coucou.txt'; var form = createView({ View: FormView, model: 'partner', data: this.data, arch: '
' + - '' + + '' + + '' + '', res_id: 1, }); assert.strictEqual(form.$('a.o_field_widget[name="document"] > .fa-download').length, 1, "the binary field should be rendered as a downloadable link in readonly"); + assert.strictEqual(form.$('a.o_field_widget[name="document"]').text().trim(), 'coucou.txt', + "the binary field should display the name of the file in the link"); + assert.strictEqual(form.$('.o_field_char').text(), 'coucou.txt', + "the filename field should have the file name as value"); form.$('a.o_field_widget[name="document"]').click(); @@ -1078,12 +1084,15 @@ QUnit.module('basic_fields', { assert.strictEqual(form.$('a.o_field_widget[name="document"] > .fa-download').length, 0, "the binary field should not be rendered as a downloadable link in edit"); - assert.strictEqual(form.$('div.o_field_binary_file[name="document"]').length, 1, - "the binary field should be correctly rendered in edit"); + assert.strictEqual(form.$('div.o_field_binary_file[name="document"] > input').val(), 'coucou.txt', + "the binary field should display the file name in the input edit mode"); assert.strictEqual(form.$('.o_field_binary_file > input').attr('readonly'), 'readonly', "the input should be readonly"); assert.strictEqual(form.$('.o_field_binary_file > .o_clear_file_button').length, 1, "there shoud be a button to clear the file"); + assert.strictEqual(form.$('input.o_field_char').val(), 'coucou.txt', + "the filename field should have the file name as value"); + form.$('.o_field_binary_file > .o_clear_file_button').click(); @@ -1091,6 +1100,16 @@ QUnit.module('basic_fields', { "the input should be hidden"); assert.strictEqual(form.$('.o_field_binary_file > .o_select_file_button:not(.o_hidden)').length, 1, "there shoud be a button to upload the file"); + assert.strictEqual(form.$('input.o_field_char').val(), '', + "the filename field should be empty since we removed the file"); + + form.$buttons.find('.o_form_button_save').click(); + assert.strictEqual(form.$('a.o_field_widget[name="document"] > .fa-download').length, 0, + "the binary field should not render as a downloadable link since we removed the file"); + assert.strictEqual(form.$('a.o_field_widget[name="document"]').text().trim(), '', + "the binary field should not display a filename in the link since we removed the file"); + assert.strictEqual(form.$('.o_field_char').text().trim(), '', + "the filename field should be empty since we removed the file"); form.destroy(); -- cgit v1.2.3