[ADD] web: Allow to add multiple records in m2m_tags widget.
Before this commit when user want to add multiple record at that time they only allow to add one record at a time. After this commit user can add multiple record from search more wizard. Added function _getSearchCreatePopupOptions so that it can be overridden in FieldMany2ManyTags, options for FieldMany2ManyTags will differ, like FieldMany2ManyTags SearchCreateDailog should have multi record selection, Many2ManyTags' SelectCreateDialog should display record other than selected This commit is related to task id: 1945912 closes odoo/odoo#32453 Signed-off-by: VincentSchippefilt <VincentSchippefilt@users.noreply.github.com> Co-authored-by: Mohammed Shekha <msh@openerp.com>
This commit is contained in:
committed by
Vincent Schippefilt
co-authored by
Mohammed Shekha
parent
199bb65b42
commit
4107dc11de
@@ -376,6 +376,29 @@ var FieldMany2One = AbstractField.extend({
|
||||
_getDisplayName: function (value) {
|
||||
return value.split('\n')[0];
|
||||
},
|
||||
/**
|
||||
* Prepares and returns options for SelectCreateDialog
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_getSearchCreatePopupOptions: function(view, ids, context, dynamicFilters) {
|
||||
var self = this;
|
||||
return {
|
||||
res_model: this.field.relation,
|
||||
domain: this.record.getDomain({fieldName: this.name}),
|
||||
context: _.extend({}, this.record.getContext(this.recordParams), context || {}),
|
||||
dynamicFilters: dynamicFilters || [],
|
||||
title: (view === 'search' ? _t("Search: ") : _t("Create: ")) + this.string,
|
||||
initial_ids: ids,
|
||||
initial_view: view,
|
||||
disable_multiple_selection: true,
|
||||
no_create: !self.can_create,
|
||||
on_selected: function (records) {
|
||||
self.reinitialize(records[0]);
|
||||
self.activate();
|
||||
}
|
||||
};
|
||||
},
|
||||
/**
|
||||
* Listens to events 'field_changed' to keep track of the last event that
|
||||
* has been trigerred. This allows to detect that all changes have been
|
||||
@@ -613,21 +636,8 @@ var FieldMany2One = AbstractField.extend({
|
||||
*/
|
||||
_searchCreatePopup: function (view, ids, context, dynamicFilters) {
|
||||
var self = this;
|
||||
return new dialogs.SelectCreateDialog(this, _.extend({}, this.nodeOptions, {
|
||||
res_model: this.field.relation,
|
||||
domain: this.record.getDomain({fieldName: this.name}),
|
||||
context: _.extend({}, this.record.getContext(this.recordParams), context || {}),
|
||||
dynamicFilters: dynamicFilters || [],
|
||||
title: (view === 'search' ? _t("Search: ") : _t("Create: ")) + this.string,
|
||||
initial_ids: ids,
|
||||
initial_view: view,
|
||||
disable_multiple_selection: true,
|
||||
no_create: !self.can_create,
|
||||
on_selected: function (records) {
|
||||
self.reinitialize(records[0]);
|
||||
self.activate();
|
||||
}
|
||||
})).open();
|
||||
var options = this._getSearchCreatePopupOptions(view, ids, context, dynamicFilters);
|
||||
return new dialogs.SelectCreateDialog(this, _.extend({}, this.nodeOptions, options)).open();
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
@@ -2119,6 +2129,19 @@ var FieldMany2ManyTags = AbstractField.extend({
|
||||
this.many2one._getSearchBlacklist = function () {
|
||||
return self.value.res_ids;
|
||||
};
|
||||
var _getSearchCreatePopupOptions = this.many2one._getSearchCreatePopupOptions;
|
||||
this.many2one._getSearchCreatePopupOptions = function (view, ids, context, dynamicFilters) {
|
||||
var options = _getSearchCreatePopupOptions.apply(this, arguments);
|
||||
var domain = this.record.getDomain({fieldName: this.name});
|
||||
return _.extend({}, options, {
|
||||
domain: domain.concat(["!", ["id", "in", self.value.res_ids]]),
|
||||
disable_multiple_selection: false,
|
||||
on_selected: function (records) {
|
||||
self.many2one.reinitialize(records);
|
||||
self.many2one.activate();
|
||||
}
|
||||
});
|
||||
};
|
||||
return this.many2one.appendTo(this.$el);
|
||||
},
|
||||
/**
|
||||
|
||||
@@ -1022,6 +1022,85 @@ QUnit.module('fields', {}, function () {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('many2many tags widget: select multiple records', async function (assert) {
|
||||
assert.expect(5);
|
||||
for (var i = 1; i <= 10; i++) {
|
||||
this.data.partner_type.records.push({ id: 100 + i, display_name: "Partner" + i});
|
||||
}
|
||||
var form = await createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form string="Partners">' +
|
||||
'<field name="display_name"/>' +
|
||||
'<field name="timmy" widget="many2many_tags"/>' +
|
||||
'</form>',
|
||||
res_id: 1,
|
||||
archs: {
|
||||
'partner_type,false,list': '<tree><field name="display_name"/></tree>',
|
||||
'partner_type,false,search': '<search><field name="display_name"/></search>',
|
||||
},
|
||||
});
|
||||
await testUtils.form.clickEdit(form);
|
||||
await testUtils.fields.many2one.clickOpenDropdown('timmy');
|
||||
await testUtils.fields.many2one.clickItem('timmy','Search More');
|
||||
assert.ok($('.modal .o_list_view'), "should have open the modal");
|
||||
|
||||
// + 1 for the select all
|
||||
assert.containsN($(document),'.modal .o_list_view .o_list_record_selector input', this.data.partner_type.records.length + 1,
|
||||
"Should have record selector checkboxes to select multiple records");
|
||||
//multiple select tag
|
||||
await testUtils.dom.click($('.modal .o_list_view thead .o_list_record_selector input'));
|
||||
assert.ok(!$('.modal .o_select_button').prop('disabled'), "select button should be enabled");
|
||||
await testUtils.dom.click($('.o_select_button'));
|
||||
assert.containsNone($(document),'.modal .o_list_view', "should have closed the modal");
|
||||
assert.containsN(form, '.o_field_many2manytags[name="timmy"] .badge', this.data.partner_type.records.length,
|
||||
"many2many tag should now contain 12 records");
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test("many2many tags widget: select multiple records doesn't show already added tags", async function (assert) {
|
||||
assert.expect(5);
|
||||
for (var i = 1; i <= 10; i++) {
|
||||
this.data.partner_type.records.push({ id: 100 + i, display_name: "Partner" + i});
|
||||
}
|
||||
var form = await createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form string="Partners">' +
|
||||
'<field name="display_name"/>' +
|
||||
'<field name="timmy" widget="many2many_tags"/>' +
|
||||
'</form>',
|
||||
res_id: 1,
|
||||
archs: {
|
||||
'partner_type,false,list': '<tree><field name="display_name"/></tree>',
|
||||
'partner_type,false,search': '<search><field name="display_name"/></search>',
|
||||
},
|
||||
});
|
||||
await testUtils.form.clickEdit(form);
|
||||
|
||||
|
||||
await testUtils.fields.many2one.clickOpenDropdown('timmy');
|
||||
await testUtils.fields.many2one.clickItem('timmy','Partner1');
|
||||
|
||||
await testUtils.fields.many2one.clickOpenDropdown('timmy');
|
||||
await testUtils.fields.many2one.clickItem('timmy','Search More');
|
||||
assert.ok($('.modal .o_list_view'), "should have open the modal");
|
||||
|
||||
// -1 for the one that is already on the form & +1 for the select all,
|
||||
assert.containsN($(document), '.modal .o_list_view .o_list_record_selector input', this.data.partner_type.records.length - 1 + 1,
|
||||
"Should have record selector checkboxes to select multiple records");
|
||||
//multiple select tag
|
||||
await testUtils.dom.click($('.modal .o_list_view thead .o_list_record_selector input'));
|
||||
assert.ok(!$('.modal .o_select_button').prop('disabled'), "select button should be enabled");
|
||||
await testUtils.dom.click($('.o_select_button'));
|
||||
assert.containsNone($(document),'.modal .o_list_view', "should have closed the modal");
|
||||
assert.containsN(form, '.o_field_many2manytags[name="timmy"] .badge', this.data.partner_type.records.length,
|
||||
"many2many tag should now contain 12 records");
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('many2many list add *many* records, remove, re-add', async function (assert) {
|
||||
assert.expect(5);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user