[FIX] web,mail: many2many_tags_email: increase limit
A long time ago, commit [1] increased the limit of displayed badges
inside a many2many_tags widget, from 40 to 1000 (a large limit that
should never been reached with such a widget).
However, this solution was specific to the many2many_tags widget,
and didn't apply to its extensions (like the many2many_tags_email
widget). For instance, open the chatter full composer, add 40
partners in the recipients field and try to add one more: nothing
happens.
This commit sets the limit on the widget itself. That way,
extensions automatically have the same limit, and can override it
if needed.
[1] d4cf4374d1
Task : 2091027
closes odoo/odoo#49488
X-original-commit: 02e41f1131b4ea3ad977cc241a3d447c37195f6e
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -3532,5 +3532,38 @@ QUnit.test('fieldmany2many tags email (edition)', async function (assert) {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('many2many_tags_email widget can load more than 40 records', async function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
this.data.partner.fields.partner_ids = {string: "Partner", type: "many2many", relation: 'partner'};
|
||||
this.data.partner.records[0].partner_ids = [];
|
||||
for (let i = 100; i < 200; i++) {
|
||||
this.data.partner.records.push({id: i, display_name: `partner${i}`});
|
||||
this.data.partner.records[0].partner_ids.push(i);
|
||||
}
|
||||
|
||||
const form = await createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form><field name="partner_ids" widget="many2many_tags"/></form>',
|
||||
res_id: 1,
|
||||
});
|
||||
|
||||
assert.strictEqual(form.$('.o_field_widget[name="partner_ids"] .badge').length, 100);
|
||||
|
||||
await testUtils.form.clickEdit(form);
|
||||
|
||||
assert.hasClass(form.$('.o_form_view'), 'o_form_editable');
|
||||
|
||||
// add a record to the relation
|
||||
await testUtils.fields.many2one.clickOpenDropdown('partner_ids');
|
||||
await testUtils.fields.many2one.clickHighlightedItem('partner_ids');
|
||||
|
||||
assert.strictEqual(form.$('.o_field_widget[name="partner_ids"] .badge').length, 101);
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2274,6 +2274,7 @@ var FieldMany2ManyTags = AbstractField.extend({
|
||||
fieldsToFetch: {
|
||||
display_name: {type: 'char'},
|
||||
},
|
||||
limit: 1000,
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
|
||||
@@ -156,11 +156,8 @@ var FormView = BasicView.extend({
|
||||
*/
|
||||
_setSubViewLimit: function (attrs) {
|
||||
var view = attrs.views && attrs.views[attrs.mode];
|
||||
var limit = view && view.arch.attrs.limit && parseInt(view.arch.attrs.limit);
|
||||
if (!limit && attrs.widget === 'many2many_tags') {
|
||||
limit = 1000;
|
||||
}
|
||||
attrs.limit = limit || 40;
|
||||
var limit = view && view.arch.attrs.limit && parseInt(view.arch.attrs.limit, 10);
|
||||
attrs.limit = limit || attrs.Widget.prototype.limit || 40;
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -1732,6 +1732,32 @@ QUnit.module('relational_fields', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('many2many_tags loads records according to limit defined on widget prototype', async function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
const M2M_LIMIT = relationalFields.FieldMany2ManyTags.prototype.limit;
|
||||
relationalFields.FieldMany2ManyTags.prototype.limit = 30;
|
||||
this.data.partner.fields.partner_ids = {string: "Partner", type: "many2many", relation: 'partner'};
|
||||
this.data.partner.records[0].partner_ids = [];
|
||||
for (var i = 15; i < 50; i++) {
|
||||
this.data.partner.records.push({id: i, display_name: 'walter' + i});
|
||||
this.data.partner.records[0].partner_ids.push(i);
|
||||
}
|
||||
const form = await createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form><field name="partner_ids" widget="many2many_tags"/></form>',
|
||||
res_id: 1,
|
||||
});
|
||||
|
||||
assert.strictEqual(form.$('.o_field_widget[name="partner_ids"] .badge').length, 30,
|
||||
'should have rendered 30 tags even though 35 records linked');
|
||||
|
||||
relationalFields.FieldMany2ManyTags.prototype.limit = M2M_LIMIT;
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('field many2many_tags keeps focus when being edited', async function (assert) {
|
||||
assert.expect(7);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user