test: rename autoincrement document

This commit is contained in:
Faris Ansari 2024-11-30 16:49:04 +05:30
parent 188f9f9650
commit 3b014a2548
2 changed files with 45 additions and 2 deletions

View file

@ -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,
*,

View file

@ -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))