From 38e73da092f3bb3377edac983aea37aceed4ed3f Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 29 Dec 2017 12:18:58 +0100 Subject: [IMP] web: support variable digits In v10, a `Float` field with `widget="monetary"` option uses the decimal precision of the field. In v11, however, it uses the decimal precision of the currency. However, in many cases `widget="monetary"` is used in the sole purpose of displaying the currency symbol. The precision of the field sould be kept. This commit introduces the support of the decimal precision of the field for this specific use case thanks to the `field_digits` option: ``` ``` If such an option is used, the field precision will prevail over the currency precision. Related to #21686 opw-800279 --- .../web/static/tests/fields/basic_fields_tests.js | 46 ++++++++++++++++++++++ 1 file changed, 46 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 6fc104246d6..9ea423250e4 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -587,6 +587,52 @@ QUnit.module('basic_fields', { form.destroy(); }); + QUnit.test('float field with monetary widget and decimal precision', function (assert) { + assert.expect(5); + + this.data.partner.records = [{ + id: 1, + qux: -8.89859, + 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'), + }, + }); + + // Non-breaking space between the currency and the amount + assert.strictEqual(form.$('.o_field_widget').first().text(), '$\u00a0-8.9', + 'The value should be displayed properly.'); + + form.$buttons.find('.o_form_button_edit').click(); + assert.strictEqual(form.$('input').val(), '-8.9', + 'The input should be rendered without the currency symbol.'); + assert.strictEqual(form.$('input').parent().children().first().text(), '$', + 'The input should be preceded by a span containing the currency symbol.'); + + form.$('input').val('109.2458938598598').trigger('input'); + assert.strictEqual(form.$('input').val(), '109.2458938598598', + 'The value should not be formated yet.'); + + form.$buttons.find('.o_form_button_save').click(); + // Non-breaking space between the currency and the amount + assert.strictEqual(form.$('.o_field_widget').first().text(), '$\u00a0109.2', + 'The new value should be rounded properly.'); + + form.destroy(); + }); + QUnit.module('FieldEmail'); QUnit.test('email field in form view', function (assert) { -- cgit v1.2.3 From 255e8ca3d92e3a77d7c2a145677623518bc2f978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Ku=CC=88hn?= Date: Fri, 5 Jan 2018 15:00:57 +0100 Subject: [FIX] web: binary field format in list view Binary fields were simply shown simply by their textual representation in list views, e.g. the base64 string. There was no formatter for binary fields, therefore it has been implemented so that it displays its estimated size. Binary fields in list views had a download link in v10.0. We provide this feature back by means of a widget called 'download_link'. It is also possible to define an option to set the field name having the filename as its value. Example: with the following record: {fname: 'document.txt', datas: 'Cg=='}, we get a file named "document.txt" by clicking on the download link. Closes #21996 --- .../web/static/tests/fields/basic_fields_tests.js | 34 ++++++++++++++++++++++ 1 file changed, 34 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 9ea423250e4..a2f59a68e2a 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -1481,6 +1481,40 @@ QUnit.module('basic_fields', { session.get_file = oldGetFile; }); + QUnit.test('download_link widget in list view', function (assert) { + assert.expect(5); + + this.data.partner.fields.filename = { string: "Filename", type: "char" }; + this.data.partner.records[0].filename = "document.txt"; + + var form = createView({ + View: ListView, + model: 'partner', + data: this.data, + arch: '' + + '' + + '' + + '', + res_id: 1, + }); + + assert.ok(form.$('.o_data_cell').first().hasClass("o_download_link_cell"), + "this should be a download link cell"); + assert.ok(form.$('.o_data_cell').first().find('a').eq(0), + "there should be a link in the cell"); + assert.strictEqual(form.$('.o_data_cell').first().find('a').eq(0).attr('download'), + "document.txt", + "it should download a file named 'document.txt'"); + assert.strictEqual(form.$('.o_data_cell').first().find('a').eq(0).attr('href').trim(), + "data:application/octet-stream;base64,coucou==", + "it should have the appropriate link of a binary"); + assert.strictEqual(form.$('.o_data_cell').first().find('a').eq(0).text(), + "Download", + "the text of the link should be 'Download'"); + + form.destroy(); + }); + QUnit.test('text field rendering in list view', function (assert) { assert.expect(1); -- cgit v1.2.3