Skip to content

Commit ccb3e06

Browse files
committed
[IMP] web_timeline - set m2m group value as default when creating record
When creating a new record from a m2m group row, pre-fill the m2m field with the group's value using the [(6, 0, [id])] command format.
1 parent 7f46da1 commit ccb3e06

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

web_timeline/static/src/views/timeline/timeline_controller.esm.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,20 @@ export class TimelineController extends Component {
306306
const groupPathSegments = JSON.parse(item.group);
307307
if (Array.isArray(groupPathSegments)) {
308308
groupPathSegments.forEach((segment) => {
309-
// Do not set m2m fields as default context
309+
// Set m2m fields using command format [(6, 0, [id])]
310310
if (
311311
this.model.fields[segment.field] &&
312312
this.model.fields[segment.field].type === "many2many"
313313
) {
314+
if (
315+
segment.value !== false &&
316+
segment.value !== null &&
317+
segment.value !== undefined
318+
) {
319+
context[`default_${segment.field}`] = [
320+
[6, 0, [segment.value]],
321+
];
322+
}
314323
return;
315324
}
316325
if (

web_timeline/static/src/views/timeline/timeline_renderer.esm.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,11 @@ export class TimelineRenderer extends Component {
393393
if (m2mNameCache[cacheKey]) {
394394
return m2mNameCache[cacheKey];
395395
}
396-
const names = await this.orm.call(model, "name_get", [ids]);
397-
const result = names.map((name) => ({id: name[0], content: name[1]}));
396+
const names = await this.orm.read(model, ids, ["display_name"]);
397+
const result = names.map((name) => ({
398+
id: name.id,
399+
content: name.display_name,
400+
}));
398401
m2mNameCache[cacheKey] = result;
399402
return result;
400403
};

0 commit comments

Comments
 (0)