[FIX] web: changing the priority of a new record in kanban
Have a grouped kanban which display a priority field widget. Quick create a record. Click on any priority widget to change the priority. Before this commit, the model was still considered in edition, preventing any change in other record. Hence, the priorities did not change (at least, there was no write operation) when clicked on. After this commit, this flow works as expected. closes odoo/odoo#99199 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -120,10 +120,6 @@ export class Field extends Component {
|
||||
|
||||
const modifiers = fieldInfo.modifiers || {};
|
||||
const readonlyFromModifiers = evalDomain(modifiers.readonly, evalContext);
|
||||
const readonlyFromRecord = !record.isInEdition;
|
||||
const readonlyFromViewMode = record.model.root
|
||||
? !record.model.root.isInEdition
|
||||
: readonlyFromRecord;
|
||||
|
||||
// Decoration props
|
||||
const decorationMap = {};
|
||||
@@ -159,15 +155,18 @@ export class Field extends Component {
|
||||
if (record.selected && record.model.multiEdit) {
|
||||
return;
|
||||
}
|
||||
const rootRecord =
|
||||
record.model.root instanceof record.constructor && record.model.root;
|
||||
const isInEdition = rootRecord ? rootRecord.isInEdition : record.isInEdition;
|
||||
// We save only if we're on view mode readonly and no readonly field modifier
|
||||
if (readonlyFromViewMode && !readonlyFromModifiers) {
|
||||
if (!isInEdition && !readonlyFromModifiers) {
|
||||
// TODO: maybe move this in the model
|
||||
return record.save();
|
||||
}
|
||||
},
|
||||
value: this.props.record.data[this.props.name],
|
||||
decorations: decorationMap,
|
||||
readonly: readonlyFromRecord || readonlyFromModifiers || false,
|
||||
readonly: !record.isInEdition || readonlyFromModifiers || false,
|
||||
...propsFromAttrs,
|
||||
...props,
|
||||
type: field.type,
|
||||
|
||||
@@ -1395,10 +1395,6 @@ class DynamicList extends DataPoint {
|
||||
// Getters
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
get isInEdition() {
|
||||
return !!this.editedRecord;
|
||||
}
|
||||
|
||||
get currentParams() {
|
||||
return JSON.stringify([this.domain, this.groupBy]);
|
||||
}
|
||||
@@ -1790,7 +1786,8 @@ export class DynamicRecordList extends DynamicList {
|
||||
}
|
||||
await this.model.keepLast.add(this.model.mutex.exec(() => newRecord.load()));
|
||||
this.editedRecord = newRecord;
|
||||
this.onCreateRecord(newRecord);
|
||||
this.onRemoveNewRecord = await this.onCreateRecord(newRecord);
|
||||
|
||||
return this.addRecord(newRecord, atFirstPosition ? 0 : this.count);
|
||||
}
|
||||
|
||||
@@ -1889,7 +1886,12 @@ export class DynamicRecordList extends DynamicList {
|
||||
this.count--;
|
||||
if (this.editedRecord === record) {
|
||||
this.editedRecord = null;
|
||||
if (this.onRemoveNewRecord) {
|
||||
this.onRemoveNewRecord(record);
|
||||
this.onRemoveNewRecord = null;
|
||||
}
|
||||
}
|
||||
|
||||
this.model.notify();
|
||||
return record;
|
||||
}
|
||||
@@ -2001,6 +2003,12 @@ export class DynamicGroupList extends DynamicList {
|
||||
}
|
||||
}
|
||||
this.editedRecord = record;
|
||||
const onRemoveRecord = (record) => {
|
||||
if (this.editedRecord === record) {
|
||||
this.editedRecord = null;
|
||||
}
|
||||
};
|
||||
return onRemoveRecord;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -316,6 +316,50 @@ QUnit.module("Fields", (hooks) => {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("PriorityField can write after adding a record -- kanban", async function (assert) {
|
||||
serverData.models.partner.fields.selection.selection = [
|
||||
["0", 0],
|
||||
["1", 1],
|
||||
];
|
||||
serverData.models.partner.records[0].selection = "0";
|
||||
|
||||
serverData.views = {
|
||||
"partner,myquickview,form": `<form><field name="display_name" /></form>`,
|
||||
};
|
||||
await makeView({
|
||||
type: "kanban",
|
||||
resModel: "partner",
|
||||
serverData,
|
||||
domain: [["id", "=", 1]],
|
||||
groupBy: ["foo"],
|
||||
arch: `
|
||||
<kanban on_create="quick_create" quick_create_view="myquickview">
|
||||
<templates>
|
||||
<t t-name="kanban-box">
|
||||
<div class="oe_kanban_card oe_kanban_global_click">
|
||||
<field name="selection" widget="priority"/>
|
||||
</div>
|
||||
</t>
|
||||
</templates>
|
||||
</kanban>`,
|
||||
mockRPC(route, args) {
|
||||
if (args.method === "write") {
|
||||
assert.step(`write ${JSON.stringify(args.args)}`);
|
||||
}
|
||||
},
|
||||
});
|
||||
assert.containsNone(target, ".o_kanban_record .fa-star");
|
||||
await click(target.querySelector(".o_priority a.o_priority_star.fa-star-o"), null, true);
|
||||
assert.verifySteps(['write [[1],{"selection":"1"}]']);
|
||||
assert.containsOnce(target, ".o_kanban_record .fa-star");
|
||||
|
||||
await click(target, ".o-kanban-button-new");
|
||||
await click(target, ".o_kanban_quick_create .o_kanban_add");
|
||||
await click(target.querySelector(".o_priority a.o_priority_star.fa-star-o"), null, true);
|
||||
assert.verifySteps(['write [[6],{"selection":"1"}]']);
|
||||
assert.containsN(target, ".o_kanban_record .fa-star", 2);
|
||||
});
|
||||
|
||||
QUnit.test("PriorityField in editable list view", async function (assert) {
|
||||
await makeView({
|
||||
type: "list",
|
||||
@@ -457,7 +501,7 @@ QUnit.module("Fields", (hooks) => {
|
||||
);
|
||||
|
||||
// Click on second star in edit mode
|
||||
let stars = target.querySelectorAll(".o_priority a.o_priority_star.fa-star-o");
|
||||
const stars = target.querySelectorAll(".o_priority a.o_priority_star.fa-star-o");
|
||||
await click(stars[stars.length - 1]);
|
||||
|
||||
let rows = target.querySelectorAll(".o_data_row");
|
||||
|
||||
Reference in New Issue
Block a user