[FIX] project,web: fix readonly in list view cells
This commit changes how automatic readonly props are applied to list fields so that it doesn't override the getFieldProps method It also fixes the method 'getCellReadonly' in ProjectTaskListRenderer, which was renamed to 'isCellReadonly' in the framework but not in the custom renderer. Task-3340379 closes odoo/odoo#123026 X-original-commit: da3b2421b3f851629d5d287223b7ef581a30a5ab Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com> Signed-off-by: Larcin Vincent (vila) <vila@odoo.com> Co-authored-by: Vincent Larcin <vila@odoo.com>
This commit is contained in:
committed by
Vincent Larcin
co-authored by
Vincent Larcin
parent
91af1abbd5
commit
52b483e6f8
@@ -90,6 +90,7 @@
|
||||
],
|
||||
'web.assets_tests': [
|
||||
'project/static/tests/tours/**/*',
|
||||
'project/static/tests/views/**/*',
|
||||
],
|
||||
'project.webclient': [
|
||||
('include', 'web._assets_helpers'),
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ListRenderer } from "@web/views/list/list_renderer";
|
||||
import { getRawValue } from "@web/views/kanban/kanban_record";
|
||||
|
||||
export class ProjectTaskListRenderer extends ListRenderer {
|
||||
getCellReadonly(column, record) {
|
||||
isCellReadonly(column, record) {
|
||||
let readonly = false;
|
||||
const selection = this.props.list.selection;
|
||||
if (column.name === "stage_id" && selection.length) {
|
||||
@@ -13,6 +13,6 @@ export class ProjectTaskListRenderer extends ListRenderer {
|
||||
(task) => getRawValue(task, "project_id") !== projectId
|
||||
);
|
||||
}
|
||||
return readonly || super.getCellReadonly(column, record);
|
||||
return readonly || super.isCellReadonly(column, record);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { click, getFixture } from "@web/../tests/helpers/utils";
|
||||
import { makeView, setupViewRegistries } from "@web/../tests/views/helpers";
|
||||
|
||||
QUnit.module("Project Task List View", (hooks) => {
|
||||
QUnit.test("cannot edit stage_id with different projects", async function (assert) {
|
||||
const target = getFixture();
|
||||
setupViewRegistries();
|
||||
await makeView({
|
||||
type: "list",
|
||||
resModel: "project.task",
|
||||
arch: `
|
||||
<tree multi_edit="1" js_class="project_task_list">
|
||||
<field name="project_id"/>
|
||||
<field name="stage_id"/>
|
||||
</tree>
|
||||
`,
|
||||
serverData: {
|
||||
models: {
|
||||
"project.task": {
|
||||
fields: {
|
||||
project_id: {
|
||||
string: "Project",
|
||||
type: "many2one",
|
||||
relation: "project.project",
|
||||
},
|
||||
stage_id: {
|
||||
string: "Stage",
|
||||
type: "many2one",
|
||||
relation: "project.task.type",
|
||||
}
|
||||
},
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
project_id: 1,
|
||||
stage_id: 1,
|
||||
}, {
|
||||
id: 2,
|
||||
project_id: 2,
|
||||
stage_id: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
"project.project": {
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
}, {
|
||||
id: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
"project.task.type": {
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
}, {
|
||||
id: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
const [firstRow, secondRow] = target.querySelectorAll(".o_data_row");
|
||||
await click(firstRow.querySelector(".o_data_row .o_list_record_selector input"));
|
||||
assert.containsNone(firstRow, ".o_readonly_modifier", "None of the fields should be readonly");
|
||||
assert.containsNone(secondRow, ".o_readonly_modifier", "None of the fields should be readonly");
|
||||
|
||||
await click(secondRow.querySelector(".o_data_row .o_list_record_selector input"));
|
||||
assert.containsOnce(firstRow, ".o_readonly_modifier");
|
||||
assert.hasClass(firstRow.querySelectorAll(".o_data_cell")[1], "o_readonly_modifier", "The stage_id should be readonly");
|
||||
assert.containsOnce(secondRow, ".o_readonly_modifier");
|
||||
assert.hasClass(secondRow.querySelectorAll(".o_data_cell")[1], "o_readonly_modifier", "The stage_id should be readonly");
|
||||
});
|
||||
});
|
||||
@@ -258,7 +258,7 @@ export class ListRenderer extends Component {
|
||||
}
|
||||
|
||||
getFieldProps(record, column) {
|
||||
if (this.isCellReadonly(column, record)) {
|
||||
if (this.isCellReadonly(column, record) || (this.props.activeActions?.edit === false && !record.isNew)) {
|
||||
return {
|
||||
readonly: true,
|
||||
};
|
||||
|
||||
@@ -237,7 +237,7 @@
|
||||
t-on-click="(ev) => this.onCellClicked(record, column, ev)" tabindex="-1">
|
||||
<t t-if="!isInvisible">
|
||||
<t t-if="canUseFormatter(column, record)" t-out="getFormattedValue(column, record)"/>
|
||||
<Field t-else="" name="column.name" record="record" type="column.widget" class="getFieldClass(column)" fieldInfo="column" t-props="getFieldProps(record, column)" readonly="props.activeActions?.edit === false and !record.isNew"/>
|
||||
<Field t-else="" name="column.name" record="record" type="column.widget" class="getFieldClass(column)" fieldInfo="column" t-props="getFieldProps(record, column)"/>
|
||||
</t>
|
||||
</td>
|
||||
</t>
|
||||
|
||||
Reference in New Issue
Block a user