[FIX] web: display_name "New" fallback should only target new record.

There is a fallback in the control panel
(https://github.com/odoo/odoo/blob/c22cb6bbadd38ecb050f6d4dc14672868beda20b/addons/web/static/src/search/control_panel/control_panel.xml#L137)
if the display_name of the record is empty.
But it is never actually used because there is another
fallback in the form_controller ("New"). This latter fallback
should only be used for new records, not for existing ones.

closes odoo/odoo#138061

Signed-off-by: Raphael Collet <rco@odoo.com>
Signed-off-by: Rémy Voet (ryv) <ryv@odoo.com>
This commit is contained in:
Rémy Voet (ryv)
2023-10-10 12:35:01 +00:00
parent 56bd53d81f
commit 0782ec07e7
2 changed files with 13 additions and 1 deletions
@@ -333,7 +333,7 @@ export class FormController extends Component {
}
displayName() {
return this.model.root.data.display_name || _t("New");
return this.model.root.data.display_name || (this.model.root.isNew && _t("New")) || "";
}
async onPagerUpdate({ offset, resIds }) {
@@ -14212,4 +14212,16 @@ QUnit.module("Views", (hooks) => {
assert.verifySteps(["web_read", "web_save"]);
}
);
QUnit.test("existing record with falsy display_name", async function (assert) {
serverData.models.partner.records[0].display_name = "";
await makeView({
type: "form",
resModel: "partner",
serverData,
arch: `<form><field name="int_field"/></form>`,
resId: 1,
});
assert.strictEqual(target.querySelector(".o_breadcrumb").innerText, "Unnamed");
});
});