[FIX] web: fix issue with combination of o2m, m2m, and m2o

Consider this: a form view with a one2many list view. In the one2many
list view, there is a many2one field.  When opening the manyone in a
modal form view, there is a many2many field.  In that situation,
clicking on 'Add a new record' on the many2many field had the
unfortunate effect of interfering with the one2many field in the main
form view, which caused a crash or the modal form view to close
unexpectedly.

The issue is that an event was simply not properly stopped at the proper
location.  This is usually not a big deal, but, as described above, it can be
a problem in some cases.
This commit is contained in:
Géry Debongnie
2017-11-15 13:48:49 +01:00
parent 6d616c566f
commit 6158c5ce04
2 changed files with 64 additions and 1 deletions
@@ -1191,9 +1191,13 @@ var FieldMany2Many = FieldX2Many.extend({
*
* @override
* @private
* @param {OdooEvent|MouseEvent} ev this event comes either from the 'Add
* record' link in the list editable renderer, or from the 'Create' button
* in the kanban view
*/
_onAddRecord: function () {
_onAddRecord: function (ev) {
var self = this;
ev.stopPropagation();
var domain = this.record.getDomain({fieldName: this.name});
@@ -5158,6 +5158,65 @@ QUnit.module('relational_fields', {
form.destroy();
});
QUnit.test('many2many list in a one2many opened by a many2one', function (assert) {
assert.expect(1);
this.data.turtle.records[1].turtle_trululu = 2;
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<field name="turtles">' +
'<tree editable="bottom">' +
'<field name="turtle_trululu"/>' +
'</tree>' +
'</field>' +
'</form>',
res_id: 1,
archs: {
"partner,false,form": '<form string="P">' +
'<field name="timmy"/>' +
'</form>',
"partner_type,false,list": '<tree editable="bottom">' +
'<field name="display_name"/>' +
'</tree>',
"partner_type,false,search": '<search>' +
'</search>',
},
viewOptions: {
mode: 'edit',
},
mockRPC: function (route, args) {
if (route === '/web/dataset/call_kw/partner/get_formview_id') {
return $.when(false);
}
if (args.method === 'write') {
assert.deepEqual(args.args[1].timmy, [[6, false, [12]]],
'should properly write ids')
}
return this._super.apply(this, arguments);
},
});
// edit the first partner in the one2many partner form view
form.$('.o_data_row:first td.o_data_cell').click();
// open form view for many2one
form.$('.o_external_button').click();
// click on add, to add a new partner in the m2m
$('.modal .o_field_x2many_list_row_add a').click();
// select the partner_type 'gold' (this closes the 2nd modal)
$('.modal td:contains(gold)').click();
// confirm the changes in the modal
$('.modal .modal-footer .btn-primary').click();
form.$buttons.find('.o_form_button_save').click();
form.destroy();
});
QUnit.test('one2many (who contains display_name) with tree view and without form view', function (assert) {
assert.expect(1);