[FIX] web: BinaryFile not download when new record

Let's have:

- on res.company a binary file field named x_file
- on res.users a related binary field to company_id.x_file, and make it readonly
- On the res.users form view, display the new field
Before this commit in create mode, upon clicking on download the file, the server crashed, because the record id was empty.
Then, the JS crashed in turn because of the unhandled 404 from the server.

Since the id of a new record will always be unset, we choose to disable the download option in this very specific case

OPW 777042
This commit is contained in:
Lucas Perais (lpe)
2017-12-05 08:19:08 +01:00
parent a8d01cbf4e
commit 519555054a
2 changed files with 51 additions and 1 deletions
@@ -1351,6 +1351,51 @@ QUnit.module('basic_fields', {
session.get_file = oldGetFile;
});
QUnit.test('binary fields that are readonly in create mode do not download', function (assert) {
assert.expect(2);
// save the session function
var oldGetFile = session.get_file;
session.get_file = function (option) {
assert.step('We shouldn\'t be getting the file.');
return oldGetFile.bind(session)(option);
};
this.data.partner.onchanges = {
product_id: function (obj) {
obj.document = "onchange==\n";
},
};
this.data.partner.fields.document.readonly = true;
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<field name="product_id"/>' +
'<field name="document" filename="\'yooo\'"/>' +
'</form>',
res_id: 1,
});
form.$buttons.find('.o_form_button_create').click();
var $dropdown = form.$('.o_field_many2one input').autocomplete('widget');
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,
'The link to download the binary should be present');
form.$('a.o_field_widget[name="document"]').click();
assert.verifySteps([]); // We shoudln't have passed through steps
form.destroy();
session.get_file = oldGetFile;
});
QUnit.test('text field rendering in list view', function (assert) {
assert.expect(1);