From e39bcae818847e9700299df60fd66edf5429c0e0 Mon Sep 17 00:00:00 2001 From: Martin Geubelle Date: Tue, 26 Feb 2019 16:37:13 +0000 Subject: [PATCH] [FIX] web: avoid crash when clicking on colored m2m in list With the BS4 update, a traceback occured when clicking on a m2m tag using colors in a list view. When using colors on m2m tags, the badge was wrapped inside a `dropdown-toggle`. However, there is no `dropdown-menu` by default (it is only rendered in FormFieldMany2ManyTags when clicking on the `.dropdown-toggle`, hence the traceback. The `dropdown-toggle` class is now only set if necessary. Task 1925313 closes odoo/odoo#31445 --- .../static/src/js/fields/relational_fields.js | 10 ++++++++ addons/web/static/src/xml/base.xml | 4 ++-- .../tests/fields/relational_fields_tests.js | 24 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index ff9d6359dd1..260266ac9a9 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -1857,6 +1857,7 @@ var FieldMany2ManyTags = AbstractField.extend({ } this.colorField = this.nodeOptions.color_field; + this.hasDropdown = false; }, //-------------------------------------------------------------------------- @@ -1923,6 +1924,7 @@ var FieldMany2ManyTags = AbstractField.extend({ return { colorField: this.colorField, elements: elements, + hasDropdown: this.hasDropdown, readonly: this.mode === "readonly", }; }, @@ -2034,6 +2036,14 @@ var FormFieldMany2ManyTags = FieldMany2ManyTags.extend({ 'mousedown .o_colorpicker a': '_onUpdateColor', 'mousedown .o_colorpicker .o_hide_in_kanban': '_onUpdateColor', }), + /** + * @override + */ + init: function () { + this._super.apply(this, arguments); + + this.hasDropdown = !!this.colorField; + }, //-------------------------------------------------------------------------- // Handlers diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 752ad974042..7ff585f37c8 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -838,11 +838,11 @@ -
+
- + diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index 316f5caeffd..640e02701c2 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -12683,6 +12683,30 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('fieldmany2many tags in tree view', function (assert) { + assert.expect(3); + + this.data.partner.records[0].timmy = [12, 14]; + var list = createView({ + View: ListView, + model: 'partner', + data: this.data, + arch: '' + + '' + + '', + }); + assert.containsN(list, '.o_field_many2manytags .badge', 2, "there should be 2 tags"); + assert.containsNone(list, '.dropdown-toggle', "the tags should not be dropdowns"); + + testUtils.intercept(list, 'switch_view', function (event) { + assert.strictEqual(event.data.view_type, "form", "should switch to form view"); + }); + // click on the tag: should do nothing and open the form view + testUtils.dom.click(list.$('.o_field_many2manytags .badge:first')); + + list.destroy(); + }); + QUnit.test('fieldmany2many tags view a domain', function (assert) { assert.expect(7);