From d4c8a7cfb4acf54b730c149c025b355b2f88ec77 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Mon, 12 Mar 2018 15:50:09 +0100 Subject: [PATCH] [FIX] web: view dialog select among filtered entries On an editable line with a many2one Click to create a record Click on create a record in the many2one It opens the form view of the object in a modal, which has a many2many list, which choices are domainized Click 'add an item' on this list It should open a modal with the filtered choices Click on any of the existing record Before this commit: There was a traceback in JS That was because the event bubbled up to a parent, when it shouldn't After this commit: The whole flow unfolds without errors OPW 1823205 --- .../web/static/src/js/views/view_dialogs.js | 1 + .../static/tests/views/view_dialogs_tests.js | 124 +++++++++++++++++- 2 files changed, 124 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/views/view_dialogs.js b/addons/web/static/src/js/views/view_dialogs.js index 6f62483a81c..f16317a29e3 100644 --- a/addons/web/static/src/js/views/view_dialogs.js +++ b/addons/web/static/src/js/views/view_dialogs.js @@ -254,6 +254,7 @@ var SelectCreateDialog = ViewDialog.extend({ } }, selection_changed: function (event) { + event.stopPropagation(); this.$footer.find(".o_select_button").prop('disabled', !event.data.selection.length); }, search: function (event) { diff --git a/addons/web/static/tests/views/view_dialogs_tests.js b/addons/web/static/tests/views/view_dialogs_tests.js index fa7e783e34d..e45b4c13c83 100644 --- a/addons/web/static/tests/views/view_dialogs_tests.js +++ b/addons/web/static/tests/views/view_dialogs_tests.js @@ -4,6 +4,9 @@ odoo.define('web.view_dialogs_tests', function (require) { var testUtils = require('web.test_utils'); var dialogs = require('web.view_dialogs'); var Widget = require('web.Widget'); +var FormView = require('web.FormView'); + +var createView = testUtils.createView; QUnit.module('Views', { beforeEach: function () { @@ -13,6 +16,7 @@ QUnit.module('Views', { display_name: { string: "Displayed name", type: "char" }, foo: {string: "Foo", type: 'char'}, bar: {string: "Bar", type: "boolean"}, + instrument: {string: 'Instruments', type: 'many2one', relation: 'instrument'}, }, records: [ {id: 1, foo: 'blip', display_name: 'blipblip', bar: true}, @@ -20,9 +24,35 @@ QUnit.module('Views', { {id: 3, foo: 'piou piou', display_name: "Jack O'Neill", bar: true}, ], }, - }; + instrument: { + fields: { + name: {string: "name", type: "char"}, + badassery: {string: 'level', type: 'many2many', relation: 'badassery', domain: [['level', '=', 'Awsome']]}, + }, + }, + + badassery: { + fields: { + level: {string: 'level', type: "char"}, + }, + records: [ + {id: 1, level: 'Awsome'}, + ], + }, + + product: { + fields : { + name: {string: "name", type: "char" }, + partner : {string: 'Doors', type: 'one2many', relation: 'partner'}, + }, + records: [ + {id: 1, name: 'The end'}, + ], + }, + }; }, + }, function () { QUnit.module('view_dialogs'); @@ -243,6 +273,98 @@ QUnit.module('Views', { parent.destroy(); }); + QUnit.test('SelectCreateDialog cascade x2many in create mode', function (assert) { + assert.expect(5); + + var form = createView({ + View: FormView, + model: 'product', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '', + res_id: 1, + archs: { + 'partner,false,form': '
' + + '' + + '' + + '', + + 'instrument,false,form': '
'+ + ''+ + '' + + ''+ + ''+ + '' + + '' + + '', + + 'badassery,false,list': ''+ + ''+ + '', + + 'badassery,false,search': ''+ + ''+ + '', + }, + + mockRPC: function(route, args) { + if (route === '/web/dataset/call_kw/partner/get_formview_id') { + return $.when(false); + } + if (route === '/web/dataset/call_kw/instrument/get_formview_id') { + return $.when(false); + } + if (route === '/web/dataset/call_kw/instrument/create') { + assert.deepEqual(args.args, [{badassery: [[6, false, [1]]], name: false}], + 'The method create should have been called with the right arguments'); + return $.when(false); + } + return this._super(route, args); + }, + }); + + form.$buttons.find('.o_form_button_edit').click(); + form.$('.o_field_x2many_list_row_add a').click(); + form.$('.o_field_widget .o_field_many2one[name=instrument] input').click(); + $('ul.ui-autocomplete.ui-front.ui-menu.ui-widget.ui-widget-content li.o_m2o_dropdown_option').first().click(); + + var $modal = $('.modal-dialog.modal-lg'); + + assert.equal($modal.length, 1, + 'There should be one modal'); + + $modal.find('.o_field_x2many_list_row_add a').click(); + + var $modals = $('.modal-dialog.modal-lg'); + + assert.equal($modals.length, 2, + 'There should be two modals'); + + var $second_modal = $modals.not($modal); + $second_modal.find('.o_list_view.table.table-condensed.table-striped.o_list_view_ungrouped .o_data_row input[type=checkbox]').click(); + + $second_modal.find('.o_select_button').click(); + + $modal = $('.modal-dialog.modal-lg'); + + assert.equal($modal.length, 1, + 'There should be one modal'); + + assert.equal($modal.find('.o_data_cell').text(), 'Awsome', + 'There should be one item in the list of the modal'); + + $modal.find('.btn.btn-sm.btn-primary').click(); + + form.destroy(); + }); + }); });