[FIX] web: form: do not add display_name if in dialog
In form views, the "display_name" field is automatically added to the list of activeFields as we need its value to display in the breadcrumbs. However, this isn't necessary when there's no control panel, in particular in dialogs. Without this commit, the test "test_addremove" of addon test_apikeys didn't pass. Part of task~3179751 Part-of: odoo/odoo#114024
This commit is contained in:
@@ -136,6 +136,11 @@ export class FormController extends Component {
|
||||
);
|
||||
this.model = useState(new this.props.Model(this.env, this.modelParams, modelServices));
|
||||
|
||||
this.display = { ...this.props.display };
|
||||
if (this.env.inDialog) {
|
||||
this.display.controlPanel = false;
|
||||
}
|
||||
|
||||
onWillStart(async () => {
|
||||
await loadSubViews(
|
||||
this.archInfo.fieldNodes,
|
||||
@@ -150,7 +155,7 @@ export class FormController extends Component {
|
||||
this.archInfo,
|
||||
this.props.fields
|
||||
);
|
||||
if (this.props.display.controlPanel) {
|
||||
if (this.display.controlPanel) {
|
||||
addFieldDependencies(activeFields, fields, [
|
||||
{ name: "display_name", type: "char", readonly: true },
|
||||
]);
|
||||
@@ -167,11 +172,6 @@ export class FormController extends Component {
|
||||
|
||||
this.cpButtonsRef = useRef("cpButtons");
|
||||
|
||||
this.display = { ...this.props.display };
|
||||
if (this.env.inDialog) {
|
||||
this.display.controlPanel = false;
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!this.env.inDialog) {
|
||||
this.updateURL();
|
||||
|
||||
@@ -2951,6 +2951,33 @@ QUnit.module("Views", (hooks) => {
|
||||
assert.containsNone(target, ".o_dialog .o_form_view .o_control_panel");
|
||||
});
|
||||
|
||||
QUnit.test("form views in dialogs do not add display_name field", async function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
serverData.views = {
|
||||
"partner,false,form": `<form><field name="foo"/></form>`,
|
||||
};
|
||||
serverData.actions = {
|
||||
1: {
|
||||
id: 1,
|
||||
name: "Partner",
|
||||
res_model: "partner",
|
||||
type: "ir.actions.act_window",
|
||||
views: [[false, "form"]],
|
||||
target: "new",
|
||||
},
|
||||
};
|
||||
const mockRPC = function (route, args) {
|
||||
if (args.method === "onchange2") {
|
||||
assert.deepEqual(args.args[3], { foo: {} });
|
||||
}
|
||||
}
|
||||
const webClient = await createWebClient({ serverData, mockRPC });
|
||||
await doAction(webClient, 1);
|
||||
assert.containsOnce(target, ".o_dialog .o_form_view");
|
||||
assert.containsNone(target, ".o_dialog .o_form_view .o_control_panel");
|
||||
});
|
||||
|
||||
QUnit.test("form views in dialogs closes on save", async function (assert) {
|
||||
serverData.models.partner.records[0].foo = undefined;
|
||||
delete serverData.models.partner.fields.foo.default;
|
||||
|
||||
Reference in New Issue
Block a user