[FIX] web: grouped list multi edit with m2m
Before this commit, m2m fields were not updated when multi editing in a grouped list. Now, the fields are updated no matter how many levels of groupBys are applied to the list. Part of task 2078807 closes odoo/odoo#37589 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -3356,7 +3356,15 @@ var BasicModel = AbstractModel.extend({
|
||||
var viewType = view ? view.type : fieldInfo.viewType;
|
||||
|
||||
var toFetch = {};
|
||||
_.each(list.data, function (dataPoint) {
|
||||
|
||||
// flattens the list.data ids in a grouped case
|
||||
let dataPointIds = list.data;
|
||||
for (let i = 0; i < list.groupedBy.length; i++) {
|
||||
dataPointIds = dataPointIds.reduce((acc, groupId) =>
|
||||
acc.concat(this.localData[groupId].data), []);
|
||||
}
|
||||
|
||||
dataPointIds.forEach(function (dataPoint) {
|
||||
var record = self.localData[dataPoint];
|
||||
if (typeof record.data[fieldName] === 'string'){
|
||||
// in this case, the value is a local ID, which means that the
|
||||
|
||||
@@ -410,7 +410,7 @@ var ListController = BasicController.extend({
|
||||
if (validRecordIds.length > 0) {
|
||||
const dialogOptions = {
|
||||
confirm_callback: () => {
|
||||
this.model.saveRecords(recordId, validRecordIds, fieldName)
|
||||
this.model.saveRecords(this.handle, recordId, validRecordIds, fieldName)
|
||||
.then(async () => {
|
||||
this._updateButtons('readonly');
|
||||
const state = this.model.get(this.handle);
|
||||
|
||||
@@ -37,15 +37,16 @@ odoo.define('web.ListModel', function (require) {
|
||||
* For a list of records, performs a write with all changes and fetches
|
||||
* all data.
|
||||
*
|
||||
* @param {string} listDatapointId id of the parent list
|
||||
* @param {string} referenceRecordId the record datapoint used to
|
||||
* generate the changes to apply to recordIds
|
||||
* @param {string[]} recordIds a list of record datapoint ids
|
||||
* @param {string} fieldName the field to write
|
||||
*/
|
||||
saveRecords: function (referenceRecordId, recordIds, fieldName) {
|
||||
saveRecords: function (listDatapointId, referenceRecordId, recordIds, fieldName) {
|
||||
var self = this;
|
||||
var referenceRecord = this.localData[referenceRecordId];
|
||||
var list = this.localData[referenceRecord.parentID];
|
||||
var list = this.localData[listDatapointId];
|
||||
// generate all record values to ensure that we'll write something
|
||||
// (e.g. 2 records selected, edit a many2one in the first one, but
|
||||
// reset same value, we still want to save this value on the other
|
||||
|
||||
@@ -6042,6 +6042,38 @@ QUnit.module('Views', {
|
||||
list.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('editable list view: m2m tags in grouped list', async function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
const list = await createView({
|
||||
arch: `
|
||||
<tree editable="top" multi_edit="1">
|
||||
<field name="bar"/>
|
||||
<field name="m2m" widget="many2many_tags"/>
|
||||
</tree>`,
|
||||
data: this.data,
|
||||
groupBy: ['bar'],
|
||||
model: 'foo',
|
||||
View: ListView,
|
||||
});
|
||||
|
||||
// Opens first group
|
||||
await testUtils.dom.click(list.$('.o_group_header:first'));
|
||||
|
||||
assert.notEqual(list.$('.o_data_row:first').text(), list.$('.o_data_row:last').text(),
|
||||
"First row and last row should have different values");
|
||||
|
||||
await testUtils.dom.click(list.$('thead .o_list_record_selector:first input'));
|
||||
await testUtils.dom.click(list.$('.o_data_row:first .o_data_cell:eq(1)'));
|
||||
await testUtils.dom.click(list.$('.o_selected_row .o_field_many2manytags .o_delete:first'));
|
||||
await testUtils.dom.click($('.modal .btn-primary'));
|
||||
|
||||
assert.strictEqual(list.$('.o_data_row:first').text(), list.$('.o_data_row:last').text(),
|
||||
"All rows should have been correctly updated");
|
||||
|
||||
list.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('list grouped by date:month', async function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user