summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields/basic_fields_tests.js
diff options
context:
space:
mode:
authorLucas Perais (lpe) <lpe@odoo.com>2017-12-04 12:05:22 +0100
committerLucas Perais (lpe) <lpe@odoo.com>2017-12-05 08:19:08 +0100
commit519555054a3a0e2e0b8a139518da081c4d5e80aa (patch)
tree347c2ad441d9bb9928602a5d72a0926f043b2536 /addons/web/static/tests/fields/basic_fields_tests.js
parenta8d01cbf4ea88f894ff927a6a5424bbb58e630d0 (diff)
[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
Diffstat (limited to 'addons/web/static/tests/fields/basic_fields_tests.js')
-rw-r--r--addons/web/static/tests/fields/basic_fields_tests.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js
index ef555868e94..e18a9e871c8 100644
--- a/addons/web/static/tests/fields/basic_fields_tests.js
+++ b/addons/web/static/tests/fields/basic_fields_tests.js
@@ -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);