diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 97b1ee36a9e7bcf1777239587b9ecde7edb1a613..1469ae514bac1900c70754128adccb595a87d101 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -1295,22 +1295,13 @@ var FieldBinaryFile = AbstractFieldBinary.extend({ this.filename_value = this.recordData[this.attrs.filename]; }, _renderReadonly: function () { - this.do_toggle(!!this.value); - if (this.value) { - this.$el.empty().append($("<span/>").addClass('fa fa-download')); - if (this.recordData.id) { - this.$el.css('cursor', 'pointer'); - } else { - this.$el.css('cursor', 'not-allowed'); - } - if (this.filename_value) { - this.$el.append(" " + this.filename_value); - } - } - if (!this.res_id) { - this.$el.css('cursor', 'not-allowed'); - } else { - this.$el.css('cursor', 'pointer'); + var visible = !!(this.value && this.res_id); + this.$el.empty().css('cursor', 'not-allowed'); + this.do_toggle(visible); + if (visible) { + this.$el.css('cursor', 'pointer') + .text(this.filename_value || '') + .prepend($('<span class="fa fa-download"/>'), ' '); } }, _renderEdit: function () { diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index c0ba0353c491d5ae88553d60f56f850c6ee1890e..40186334db5b7d4a1d3da6499ea71e16e78dc529 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -1512,7 +1512,7 @@ QUnit.module('basic_fields', { }); QUnit.test('binary fields that are readonly in create mode do not download', function (assert) { - assert.expect(2); + assert.expect(3); // save the session function var oldGetFile = session.get_file; @@ -1546,10 +1546,13 @@ QUnit.module('basic_fields', { form.$('.o_field_many2one input').click(); $dropdown.find('li:not(.o_m2o_dropdown_option):contains(xphone)').click(); - assert.strictEqual(form.$('a.o_field_widget[name="document"] > .fa-download').length, 1, + var $field = form.$('a.o_field_widget[name="document"]'); + assert.strictEqual($field.length, 1, 'The link to download the binary should be present'); + assert.strictEqual($field.find('.fa-download').length, 0, + 'the download icon should not be present'); - form.$('a.o_field_widget[name="document"]').click(); + $field.click(); assert.verifySteps([]); // We shoudln't have passed through steps