[FIX] web: quick edit when add a line on m2m
Before this commit, clicking on the "add a line" button on a many2many list field directly opened the dialog without switching the form into edit mode. This is incorrect, the form needs to switch into edit mode otherwise the selected records are saved and cannot be discarded. closes odoo/odoo#67919 X-original-commit: 3608e724c6099f0eff5f14cbd844e0d7507d0d1d Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -2218,6 +2218,19 @@ var FieldMany2Many = FieldX2Many.extend({
|
||||
renderingContext.noCreate = !this.canLink;
|
||||
return renderingContext;
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @override
|
||||
* @param {Object} extraInfo
|
||||
* @param {string} [extraInfo.type]
|
||||
*/
|
||||
_quickEdit: function (extraInfo) {
|
||||
if (extraInfo.type === 'add') {
|
||||
this.onAddRecordOpenDialog();
|
||||
} else {
|
||||
this._super(...arguments);
|
||||
}
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Handlers
|
||||
@@ -2234,7 +2247,16 @@ var FieldMany2Many = FieldX2Many.extend({
|
||||
*/
|
||||
_onAddRecord: function (ev) {
|
||||
ev.stopPropagation();
|
||||
this.onAddRecordOpenDialog();
|
||||
|
||||
if (this._canQuickEdit && this.isReadonly) {
|
||||
this.trigger_up('quick_edit', {
|
||||
fieldName: this.name,
|
||||
target: this.el,
|
||||
extraInfo: { type: 'add' },
|
||||
});
|
||||
} else {
|
||||
this.onAddRecordOpenDialog();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -10777,6 +10777,50 @@ QUnit.module('Views', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('Quick Edition: Many2Many', async function (assert) {
|
||||
assert.expect(6);
|
||||
|
||||
const form = await createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: `
|
||||
<form>
|
||||
<field name="timmy">
|
||||
<tree>
|
||||
<field name="display_name"/>
|
||||
</tree>
|
||||
<form>
|
||||
<field name="display_name"/>
|
||||
</form>
|
||||
</field>
|
||||
</form>`,
|
||||
archs: {
|
||||
'partner_type,false,list': '<tree><field name="display_name"/></tree>',
|
||||
'partner_type,false,search': '<search><field name="display_name"/></search>',
|
||||
},
|
||||
res_id: 1,
|
||||
});
|
||||
|
||||
assert.containsOnce(form, '.o_form_view.o_form_readonly');
|
||||
assert.containsOnce(form, '.o_field_x2many_list_row_add',
|
||||
'create line should be displayed');
|
||||
|
||||
await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a'));
|
||||
await testUtils.nextTick(); // wait for quick edit
|
||||
|
||||
assert.containsOnce(form, '.o_form_view.o_form_editable',
|
||||
'should switch into edit mode');
|
||||
assert.containsOnce(document.body, '.modal',
|
||||
'should display a dialog');
|
||||
|
||||
assert.containsNone(form, '.o_field_many2many[name="timmy"] .o_data_row');
|
||||
await testUtils.dom.click($('.modal .o_list_view .o_data_row')[0]);
|
||||
assert.containsOnce(form, '.o_field_many2many[name="timmy"] .o_data_row');
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('Quick Edition: Many2Many checkbox', async function (assert) {
|
||||
assert.expect(7);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user