From fed1acee10ec47f8feadc084eb72605efb2239f7 Mon Sep 17 00:00:00 2001 From: "Anh Thao Pham (pta)" Date: Wed, 23 Jun 2021 10:10:16 +0000 Subject: [PATCH] [FIX] web: fix error when getting image URL with default id Linked to commit: https://github.com/odoo/odoo/commit/7eac23573c77415c84cb9c234c8063d4c68be425 Using false as default value instead of null will lead to the following error if we try to get image URL of a record that is not the current one and if no placeholder is available: ValueError: invalid literal for int() with base 10: 'false' opw-2516188 closes odoo/odoo#72729 X-original-commit: d32c0ddbcb99385407a5030e8d3ea4df44509377 Signed-off-by: Aaron Bohy (aab) Signed-off-by: Anh Thao PHAM --- .../legacy/js/views/kanban/kanban_record.js | 4 +-- .../static/tests/legacy/views/kanban_tests.js | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/legacy/js/views/kanban/kanban_record.js b/addons/web/static/src/legacy/js/views/kanban/kanban_record.js index da81df9d89b..41964d87a7f 100644 --- a/addons/web/static/src/legacy/js/views/kanban/kanban_record.js +++ b/addons/web/static/src/legacy/js/views/kanban/kanban_record.js @@ -202,8 +202,8 @@ var KanbanRecord = Widget.extend(WidgetAdapterMixin, { * @returns {string} the url of the image */ _getImageURL: function (model, field, id, placeholder) { - id = (_.isArray(id) ? id[0] : id) || false; - var isCurrentRecord = this.modelName === model && this.recordData.id === id; + id = (_.isArray(id) ? id[0] : id) || null; + var isCurrentRecord = this.modelName === model && (this.recordData.id === id || (!this.recordData.id && !id)); var url; if (isCurrentRecord && this.record[field] && this.record[field].raw_value && !utils.is_bin_size(this.record[field].raw_value)) { // Use magic-word technique for detecting image type diff --git a/addons/web/static/tests/legacy/views/kanban_tests.js b/addons/web/static/tests/legacy/views/kanban_tests.js index 37892a2b853..1e737f0535f 100644 --- a/addons/web/static/tests/legacy/views/kanban_tests.js +++ b/addons/web/static/tests/legacy/views/kanban_tests.js @@ -6761,6 +6761,41 @@ QUnit.module('Views', { kanban.destroy(); }); + QUnit.test("test displaying image from m2o field (m2o field not set)", async function (assert) { + assert.expect(2); + this.data.foo_partner = { + fields: { + name: {string: "Foo Name", type: "char"}, + partner_id: {string: "Partner", type: "many2one", relation: "partner"}, + }, + records: [ + {id: 1, name: 'foo_with_partner_image', partner_id: 1}, + {id: 2, name: 'foo_no_partner'}, + ] + }; + + const kanban = await createView({ + View: KanbanView, + model: "foo_partner", + data: this.data, + arch: ` + + +
+ + + +
+
+
`, + }); + + assert.containsOnce(kanban, 'img[data-src*="/web/image"][data-src$="&id=1"]', "image url should contain id of set partner_id"); + assert.containsOnce(kanban, 'img[data-src*="/web/image"][data-src$="&id="]', "image url should contain an empty id if partner_id is not set"); + + kanban.destroy(); + }); + QUnit.test('check if the view destroys all widgets and instances', async function (assert) { assert.expect(2);