From 6dd4aca6b4ff1548019a99db1b1fc549c09379be Mon Sep 17 00:00:00 2001 From: Mohammed Shekha Date: Tue, 15 Sep 2020 12:00:12 +0000 Subject: [PATCH] [FIX] web: do not allow to edit priority field if readonly if readonly attribute is given on priority widget then priority widget should not be clickable and hover effect should be removed so that user can easily understand that field is readonly. task-2339680 closes odoo/odoo#59199 X-original-commit: 53dbfc7a65a8eb2f41d6b2373cf628c4800d1f57 Signed-off-by: Aaron Bohy (aab) --- .../web/static/src/js/fields/basic_fields.js | 4 +++- .../static/tests/fields/basic_fields_tests.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 5d18a22c328..8c4e46e5ce6 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -2312,8 +2312,10 @@ var PriorityWidget = AbstractField.extend({ this.$el.empty(); this.empty_value = this.field.selection[0][0]; this.$el.attr('aria-label', this.string); + const isReadonly = this.record.evalModifiers(this.attrs.modifiers).readonly; _.each(this.field.selection.slice(1), function (choice, index) { - self.$el.append(self._renderStar('', index_value >= index+1, index+1, choice[1], index_value)); + const tag = isReadonly ? '' : ''; + self.$el.append(self._renderStar(tag, index_value >= index + 1, index + 1, choice[1], index_value)); }); }, diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 62e30fe285f..1564d478ee3 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -5915,6 +5915,25 @@ QUnit.module('basic_fields', { list.destroy(); }); + QUnit.test('priority widget with readonly attribute', async function (assert) { + assert.expect(1); + + const form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: ` +
+ + `, + res_id: 2, + }); + + assert.containsN(form, '.o_field_widget.o_priority span', 2, + "stars of priority widget should rendered with span tag if readonly"); + + form.destroy(); + }); QUnit.module('StateSelection Widget');