[FIX] web: x2m in x2m with different fields in different views
Use case: a x2m (ex: attribute values) displayed in a x2m (ex: attributes on product) using different fields in different views (ex: tags in product form view and list in product attribute form view). When opening the x2m record (in a wizard) then going back on the form view, the tags are empty because the `display_name` value has been lost when fetching x2m for the second time. In this case, the list `fieldsInfo` needs to be updated with the existing (default for tags) one so all the fields will be correctly loaded. Task 1916891 closes odoo/odoo#29598
This commit is contained in:
@@ -107,6 +107,21 @@ var BasicView = AbstractView.extend({
|
||||
if (_.difference(fieldViewTypes, recordViewTypes).length) {
|
||||
fieldNames.push(name);
|
||||
}
|
||||
|
||||
if (record.data[name].viewType === 'default') {
|
||||
// Use case: x2many (tags) in x2many list views
|
||||
// When opening the x2many record form view, the
|
||||
// x2many will be reloaded but it may not have
|
||||
// the same fields (ex: tags in list and list in
|
||||
// form) so we need to merge the fieldsInfo to
|
||||
// avoid losing the initial fields (display_name)
|
||||
var defaultFieldInfo = record.data[name].fieldsInfo.default;
|
||||
_.each(fieldViews, function (fieldView) {
|
||||
_.each(fieldView.fieldsInfo, function (x2mFieldInfo) {
|
||||
_.defaults(x2mFieldInfo, defaultFieldInfo);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
// Many2one: context is not the same between the different views
|
||||
|
||||
@@ -2852,7 +2852,7 @@ QUnit.module('relational_fields', {
|
||||
$modal.find('thead input[type=checkbox]').click();
|
||||
|
||||
$modal.find('.btn.btn-sm.btn-primary.o_select_button').click();
|
||||
|
||||
|
||||
pager_limit = form.$('.o_field_many2many.o_field_widget.o_field_x2many.o_field_x2many_list .o_pager_limit');
|
||||
assert.equal(pager_limit.text(), '51',
|
||||
'We should have 51 records in the m2m field');
|
||||
@@ -11801,6 +11801,53 @@ QUnit.module('relational_fields', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('widget many2many_tags in one2many with display_name', function (assert) {
|
||||
assert.expect(4);
|
||||
this.data.turtle.records[0].partner_ids = [2];
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form string="Partners">' +
|
||||
'<sheet>' +
|
||||
'<field name="turtles">' +
|
||||
'<tree>' +
|
||||
'<field name="partner_ids" widget="many2many_tags"/>' + // will use display_name
|
||||
'</tree>' +
|
||||
'<form>' +
|
||||
'<sheet>' +
|
||||
'<field name="partner_ids"/>' +
|
||||
'</sheet>' +
|
||||
'</form>' +
|
||||
'</field>' +
|
||||
'</sheet>' +
|
||||
'</form>',
|
||||
archs: {
|
||||
'partner,false,list': '<tree><field name="foo"/></tree>',
|
||||
},
|
||||
res_id: 1,
|
||||
});
|
||||
|
||||
assert.strictEqual(form.$('.o_field_one2many[name="turtles"] .o_list_view .o_field_many2manytags[name="partner_ids"]').text().replace(/\s/g, ''),
|
||||
"secondrecordaaa", "the tags should be correctly rendered");
|
||||
|
||||
// open the x2m form view
|
||||
form.$('.o_field_one2many[name="turtles"] .o_list_view td.o_data_cell:first').click();
|
||||
assert.strictEqual($('.modal .o_form_view .o_field_many2many[name="partner_ids"] .o_list_view .o_data_cell').text(),
|
||||
"blipMy little Foo Value", "the list view should be correctly rendered with foo");
|
||||
|
||||
$('.modal button.o_form_button_cancel').click();
|
||||
assert.strictEqual(form.$('.o_field_one2many[name="turtles"] .o_list_view .o_field_many2manytags[name="partner_ids"]').text().replace(/\s/g, ''),
|
||||
"secondrecordaaa", "the tags should still be correctly rendered");
|
||||
|
||||
form.$buttons.find('.o_form_button_edit').click();
|
||||
assert.strictEqual(form.$('.o_field_one2many[name="turtles"] .o_list_view .o_field_many2manytags[name="partner_ids"]').text().replace(/\s/g, ''),
|
||||
"secondrecordaaa", "the tags should still be correctly rendered");
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.module('FieldRadio');
|
||||
|
||||
QUnit.test('fieldradio widget on a many2one in a new record', function (assert) {
|
||||
|
||||
Reference in New Issue
Block a user