From fd7b767637cd9563e9869adf537150867925f120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Mon, 20 Nov 2017 15:17:23 +0100 Subject: [FIX] web: empty field char should be set to false With the new views, empty char fields were sent to the server as '' (empty string) instead of false. This is not the correct behaviour, and actually cause some problems. For example, if you have a char field with a unicity constraint, then you cannot set it to '', since there is only one record that can take that value. --- .../web/static/tests/fields/basic_fields_tests.js | 32 ++++++++++++++++++++++ 1 file changed, 32 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 c6feea74b77..30e5d477882 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -718,6 +718,38 @@ QUnit.module('basic_fields', { form.destroy(); }); + QUnit.test('setting a char field to empty string is saved as a false value', function (assert) { + assert.expect(1); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '' + + '' + + '
', + res_id: 1, + viewOptions: {mode: 'edit'}, + mockRPC: function (route, args) { + if (args.method === 'write') { + assert.strictEqual(args.args[1].foo, false, + 'the foo value should be false'); + } + return this._super.apply(this, arguments); + } + }); + + form.$('input[type="text"].o_field_widget').val('').trigger('input'); + + // save + form.$buttons.find('.o_form_button_save').click(); + form.destroy(); + }); + QUnit.test('char field with size attribute', function (assert) { assert.expect(1); -- cgit v1.2.3 From 5c9f4fd67d37b088dd9453d06351310210497b6e Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Mon, 13 Nov 2017 11:14:07 +0100 Subject: [FIX] web: fieldDependency should be in fields too Commit f45edfbe6d03b15977392dda9561cd7a3e16ce34 fixed a bug on image fields but was a partial fix. The problem is that while adding field dependencies to fieldsInfo, it did not add them in the fields of the view, making the view crash. After this commit, views and subviews contain fieldDependency as both info and actual fields of the view OPW 780021, 781620, 779649 [FIX] web: tests on many2many subviews closes #20891 --- .../web/static/tests/fields/basic_fields_tests.js | 49 ++++++++++++++++++++++ 1 file changed, 49 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 30e5d477882..ef555868e94 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -1496,6 +1496,55 @@ QUnit.module('basic_fields', { }); + QUnit.test('image fields in subviews are loaded correctly', function (assert) { + assert.expect(5); + + this.data.partner.records[0].__last_update = '2017-02-08 10:00:00'; + this.data.partner.records[0].document = 'myimage'; + this.data.partner_type.fields.image = {name: 'image', type: 'binary'}; + this.data.partner_type.records[0].image = 'product_image'; + this.data.partner.records[0].timmy = [12]; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '', + res_id: 1, + mockRPC: function (route, args) { + if (route === 'data:image/png;base64,myimage') { + assert.step("The view's image should have been fetched"); + return $.when('wow'); + } + return this._super.apply(this, arguments); + }, + }); + assert.verifySteps(["The view's image should have been fetched"]); + + assert.strictEqual(form.$('tr.o_data_row').length, 1, + 'There should be one record in the many2many'); + + // Actual flow: click on an element of the m2m to get its form view + form.$('tbody td:contains(gold)').click(); + assert.strictEqual($('.modal-dialog').length, 1, + 'The modal should have opened'); + assert.strictEqual($('.modal-dialog').find('.o_field_image > img')[0].src, + 'data:image/png;base64,product_image', + 'The image of the many2many in its form view should be present'); + + form.destroy(); + }); + QUnit.module('JournalDashboardGraph'); QUnit.test('graph dashboard widget is rendered correctly', function (assert) { -- cgit v1.2.3 From 732f176fe1789eb513f77dfa0a671bd992db39c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Ku=CC=88hn?= Date: Wed, 22 Nov 2017 12:39:37 +0100 Subject: [FIX] web: readonly monetary field onchange currency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this fix: A readonly monetary field was not updating its currency symbol when selecting another currency. Scenario: 1. Activate multi-currency with $ (default) and € 2. In hr_expense, go to My Expenses to Submit 3. Create a new expense 4. Select 'EUR' as currency => Unit Price is correctly updated with €, but not Total. With this fix: Total displays the correct currency in edit mode. Explanation: Monetary fields in readonly are relying on _formatValue() to display their value. _formatValue() uses this.formatOptions.currency, which stores the currency at loading of the field. We must update its value whenever there is a change of currency. opw-783378 --- addons/web/static/tests/fields/basic_fields_tests.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 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 35431904cec..a058a490b69 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -2347,9 +2347,14 @@ QUnit.module('basic_fields', { }); QUnit.test('monetary field with real monetary field in model', function (assert) { - assert.expect(4); + assert.expect(7); this.data.partner.fields.qux.type = "monetary"; + this.data.partner.fields.quux = { + string: "Quux", type: "monetary", digits: [16,1], searchable: true, readonly: true, + }; + + (_.find(this.data.partner.records, function (record) { return record.id === 5 })).quux = 4.2; this.data.partner.onchanges = { bar: function (obj) { @@ -2364,6 +2369,7 @@ QUnit.module('basic_fields', { arch:'
' + '' + '' + + '' + '' + '' + '' + @@ -2374,7 +2380,9 @@ QUnit.module('basic_fields', { }, }); - assert.strictEqual(form.$('.o_field_monetary').html(), "$ 9.10", + assert.strictEqual(form.$('.o_field_monetary').first().html(), "$ 9.10", + "readonly value should contain the currency"); + assert.strictEqual(form.$('.o_field_monetary').first().next().html(), "$ 4.20", "readonly value should contain the currency"); form.$buttons.find('.o_form_button_edit').click(); @@ -2385,12 +2393,16 @@ QUnit.module('basic_fields', { form.$('input[type="checkbox"]').click(); // Change the field on which the monetary depends assert.strictEqual(form.$('.o_field_monetary > input').length, 1, "After the onchange, the monetary should not have been duplicated"); + assert.strictEqual(form.$('.o_field_monetary[name=quux]').length, 1, + "After the onchange, the monetary readonly field should not have been duplicated"); var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); form.$('.o_field_many2one input').click(); $dropdown.find('li:not(.o_m2o_dropdown_option):last').mouseenter().click(); assert.strictEqual(form.$('.o_field_monetary > span').html(), "€", "After currency change, the monetary field currency should have been updated"); + assert.strictEqual(form.$('.o_field_monetary').first().next().html(), "4.20 €", + "readonly value should contain the updated currency"); form.destroy(); }); -- cgit v1.2.3