feat: redirect to new form if it has been renamed

This commit is contained in:
barredterra 2024-09-27 18:30:35 +02:00
parent b9e204bbbf
commit 49c66c4d9f
2 changed files with 17 additions and 0 deletions

View file

@ -229,6 +229,15 @@ def rename_doc(
indicator="green",
)
# let people watching the old form know that it has been renamed
frappe.publish_realtime(
event="doc_rename",
message={"doctype": doctype, "old": old, "new": new},
doctype=doctype,
docname=old,
after_commit=True,
)
return new

View file

@ -333,6 +333,14 @@ frappe.ui.form.Form = class FrappeForm {
$(document).on("rename", (ev, dt, old_name, new_name) => {
if (dt == this.doctype) this.rename_notify(dt, old_name, new_name);
});
frappe.realtime.on("doc_rename", (data) => {
// the current form has been renamed by some backend process
if (data.doctype == this.doctype && data.old == this.docname) {
// the current form does not exist anymore, route to the new one
frappe.set_route("Form", this.doctype, data.new);
}
});
}
setup_file_drop() {