diff --git a/frappe/__init__.py b/frappe/__init__.py index de0604c508..001fb92406 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -1481,8 +1481,8 @@ def reload_doc( @whitelist(methods=["POST", "PUT"]) def rename_doc( doctype: str, - old: str, - new: str, + old: str | int, + new: str | int, force: bool = False, merge: bool = False, *, diff --git a/frappe/tests/test_rename_doc.py b/frappe/tests/test_rename_doc.py index a72525187b..2e9ff0b692 100644 --- a/frappe/tests/test_rename_doc.py +++ b/frappe/tests/test_rename_doc.py @@ -279,3 +279,46 @@ class TestRenameDoc(IntegrationTestCase): self.assertEqual(len(parent_a_instance.test_table), 1) self.assertEqual(len(parent_b_instance.test_table), 1) + + def test_rename_autoincrement_doc(self): + if not frappe.db.exists("DocType", "Autoincrement DocType"): + new_doctype( + "Autoincrement DocType", + naming_rule="Autoincrement", + autoname="autoincrement", + fields=[ + { + "label": "First Name", + "fieldname": "first_name", + "fieldtype": "Data", + } + ], + ).insert() + + if not frappe.db.exists("DocType", "Autoincrement Linked DocType"): + new_doctype( + "Autoincrement Linked DocType", + fields=[ + { + "label": "Autoincrement DocType", + "fieldname": "autoincrement_doctype", + "fieldtype": "Link", + "options": "Autoincrement DocType", + } + ], + ).insert() + + # create records + mary = frappe.new_doc("Autoincrement DocType", first_name="Mary").insert() + marilyn = frappe.new_doc("Autoincrement DocType", first_name="Marilyn").insert() + linked_with_marilyn = frappe.new_doc( + "Autoincrement Linked DocType", autoincrement_doctype=marilyn.name + ).insert() + self.assertEqual(marilyn.name, linked_with_marilyn.autoincrement_doctype) + + # rename marilyn to mary + frappe.rename_doc("Autoincrement DocType", marilyn.name, mary.name, merge=True) + linked_with_marilyn.reload() + + self.assertTrue(frappe.db.exists("Autoincrement DocType", marilyn.name) is None) + self.assertEqual(linked_with_marilyn.autoincrement_doctype, frappe.utils.cstr(mary.name)) \ No newline at end of file