From 8aecb159708d9470ad7b048f04a301e564966598 Mon Sep 17 00:00:00 2001 From: Mohammed Shekha Date: Fri, 30 Oct 2020 11:10:53 +0000 Subject: [PATCH] [FIX] web: do not display cover images in sample data Before this commit, in sample mode, cover images might be displayed in kanban views. It isn't what we want as those images are real images from the database, not sample ones, but randomly linked to the sample records (the id of many2one fields is randomly generated). This commit tweaks the SampleServer to always set many2one fields pointing to model 'ir.attachment' to false. task-2368505 closes odoo/odoo#66381 X-original-commit: f7b2a5825e3786be53d04276af4c4c403b7a293e Signed-off-by: Aaron Bohy (aab) --- addons/web/static/src/js/views/sample_server.js | 3 +++ addons/web/static/tests/views/sample_server_tests.js | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/views/sample_server.js b/addons/web/static/src/js/views/sample_server.js index 7d4cf4f26ff..cebd4a2039e 100644 --- a/addons/web/static/src/js/views/sample_server.js +++ b/addons/web/static/src/js/views/sample_server.js @@ -250,6 +250,9 @@ if (field.relation === 'res.currency') { return session.company_currency_id; } + if (field.relation === 'ir.attachment') { + return false; + } return this._getRandomSubRecordId(); case "one2many": case "many2many": { diff --git a/addons/web/static/tests/views/sample_server_tests.js b/addons/web/static/tests/views/sample_server_tests.js index 0f1dd45f795..35e33e6366d 100644 --- a/addons/web/static/tests/views/sample_server_tests.js +++ b/addons/web/static/tests/views/sample_server_tests.js @@ -54,6 +54,7 @@ odoo.define('web.sample_server_tests', function (require) { salary: { string: "Salary", type: 'monetary' }, currency: { string: "Currency", type: 'many2one', relation: 'res.currency' }, manager_id: { string: "Manager", type: 'many2one', relation: 'res.users' }, + cover_image_id: { string: "Cover Image", type: 'many2one', relation: 'ir.attachment' }, managed_ids: { string: "Managing", type: 'one2many', relation: 'res.users' }, tag_ids: { string: "Tags", type: 'many2many', relation: 'tag' }, type: { string: "Type", type: 'selection', selection: [ @@ -70,6 +71,9 @@ odoo.define('web.sample_server_tests', function (require) { ] }, age: { string: "Age", type: 'integer' }, }, + 'ir.attachment': { + display_name: { string: "Name", type: 'char' }, + } }; }, }, function () { @@ -77,7 +81,7 @@ odoo.define('web.sample_server_tests', function (require) { QUnit.module("Basic behaviour"); QUnit.test("Sample data: people type + all field names", async function (assert) { - assert.expect(25); + assert.expect(26); mock.patch(session, { company_currency_id: 4, @@ -150,6 +154,8 @@ odoo.define('web.sample_server_tests', function (require) { assert.strictEqual(typeof rec.manager_id[0], 'number'); assert.ok(SAMPLE_PEOPLE.includes(rec.manager_id[1])); + assert.strictEqual(rec.cover_image_id, false); + assert.strictEqual(rec.managed_ids.length, 2); assert.ok(rec.managed_ids.every( (id) => typeof id === 'number')