diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index aac91081c3c..4d266db409d 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -1960,11 +1960,10 @@ var StateSelectionWidget = AbstractField.extend({ * @override */ _render: function () { - var self = this; var states = this._prepareDropdownValues(); // Adapt "FormSelection" // Like priority, default on the first possible value if no value is given. - var currentState = _.findWhere(states, {name: self.value}) || states[0]; + var currentState = _.findWhere(states, {name: this.value}) || states[0]; this.$('.o_status') .removeClass('o_status_red o_status_green') .addClass(currentState.state_class) @@ -1979,6 +1978,10 @@ var StateSelectionWidget = AbstractField.extend({ var $dropdown = this.$('.dropdown-menu'); $dropdown.children().remove(); // remove old items $items.appendTo($dropdown); + + // Disable edition if the field is readonly + var isReadonly = this.record.evalModifiers(this.attrs.modifiers).readonly; + this.$('a[data-toggle=dropdown]').toggleClass('disabled', isReadonly || false); }, //-------------------------------------------------------------------------- diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index f176b4e0ab9..32450f3d56b 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -4418,6 +4418,27 @@ QUnit.module('basic_fields', { form.destroy(); }); + QUnit.test('state_selection widget with readonly modifier', function (assert) { + assert.expect(4); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
', + res_id: 1, + }); + + assert.hasClass(form.$('.o_selection'), 'o_readonly_modifier'); + assert.hasClass(form.$('.o_selection > a'), 'disabled'); + assert.isNotVisible(form.$('.dropdown-menu.state')); + + testUtils.dom.click(form.$('.o_selection > a')); + assert.isNotVisible(form.$('.dropdown-menu.state')); + + form.destroy(); + }); + QUnit.test('state_selection widget in editable list view', function (assert) { assert.expect(32);