[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
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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: '<form>' +
|
||||
'<field name="name"/>' +
|
||||
'<field name="partner" widget="one2many_list" >' +
|
||||
'<tree editable="top">' +
|
||||
'<field name="display_name"/>' +
|
||||
'<field name="instrument"/>' +
|
||||
'</tree>' +
|
||||
'</field>' +
|
||||
'</form>',
|
||||
res_id: 1,
|
||||
archs: {
|
||||
'partner,false,form': '<form>' +
|
||||
'<field name="name"/>' +
|
||||
'<field name="instrument" widget="one2many_list" mode="tree"/>' +
|
||||
'</form>',
|
||||
|
||||
'instrument,false,form': '<form>'+
|
||||
'<field name="name"/>'+
|
||||
'<field name="badassery">' +
|
||||
'<tree>'+
|
||||
'<field name="level"/>'+
|
||||
'</tree>' +
|
||||
'</field>' +
|
||||
'</form>',
|
||||
|
||||
'badassery,false,list': '<tree>'+
|
||||
'<field name="level"/>'+
|
||||
'</tree>',
|
||||
|
||||
'badassery,false,search': '<search>'+
|
||||
'<field name="level"/>'+
|
||||
'</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();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user