From 1edd61c160ef2c7cba47b133105bd1df91960f8f Mon Sep 17 00:00:00 2001 From: Prakash Prajapati Date: Thu, 27 Aug 2020 10:23:23 +0000 Subject: [PATCH] [IMP] web: The float_toggle widget button appear in the kanban view Currently, float_toggle widget is not applied in kanban view because kanban the view has read-only mode. So in this commit, enable the button to the kanban view. closes odoo/odoo#53782 Task-id: 2264613 Related: https://github.com/odoo/enterprise/pull/11497 Related: odoo/enterprise#11497 Signed-off-by: Yannick Tivisse (yti) --- .../web/static/src/js/fields/basic_fields.js | 8 ++++--- .../static/tests/fields/basic_fields_tests.js | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 8a2a238e6d8..a137dd76051 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -1262,7 +1262,8 @@ var FieldFloatToggle = AbstractField.extend({ this.formatType = 'float_factor'; - if (this.mode === 'edit') { + // force the button to work in readonly mode + if (this.mode === 'edit' || this.nodeOptions.force_button) { this.tagName = 'button'; } @@ -1352,8 +1353,9 @@ var FieldFloatToggle = AbstractField.extend({ * @param {OdooEvent} ev */ _onClick: function(ev) { - if (this.mode === 'edit') { - ev.stopPropagation(); // only stop propagation in edit mode + // force the button to work in readonly mode + if (this.mode === 'edit' || this.nodeOptions.force_button) { + ev.stopPropagation(); var next_val = this._nextValue(); next_val = field_utils.format['float'](next_val); this._setValue(next_val); // will be parsed in _setValue diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index cd6ff8347de..9a0702fdf2b 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -5633,6 +5633,29 @@ QUnit.module('basic_fields', { form.destroy(); }); + QUnit.test('float_toggle widget in kanban view(readonly) with option force_button', async function (assert) { + assert.expect(2); + + var kanban = await createView({ + View: KanbanView, + model: 'partner', + data: this.data, + arch: '' + + '' + + '
' + + '' + + '
' + + '
' + + '
', + domain: [['id', 'in', [1]]], + }); + assert.containsOnce(kanban, 'button.o_field_float_toggle', "should have rendered toggle button"); + const value = kanban.$('button.o_field_float_toggle').text(); + await testUtils.dom.click(kanban.$('button.o_field_float_toggle')); + assert.notEqual(kanban.$('button.o_field_float_toggle').text(), value, "qux field value should be changed"); + kanban.destroy(); + }); + QUnit.module('PhoneWidget');