diff --git a/frappe/tests/test_naming.py b/frappe/tests/test_naming.py index 33974e5d27..e217f24154 100644 --- a/frappe/tests/test_naming.py +++ b/frappe/tests/test_naming.py @@ -4,11 +4,11 @@ import unittest import frappe +from frappe.core.doctype.doctype.test_doctype import new_doctype from frappe.model.naming import ( append_number_if_name_exists, determine_consecutive_week_number, getseries, - parse_naming_series, revert_series_if_last, ) from frappe.utils import now_datetime @@ -51,6 +51,40 @@ class TestNaming(unittest.TestCase): self.assertEqual(country.name, original_name) self.assertEqual(country.name, country.country_name) + def test_child_table_naming(self): + child_dt_with_naming = new_doctype( + "childtable_with_autonaming", istable=1, autoname="field:some_fieldname" + ).insert() + dt_with_child_autoname = new_doctype( + "dt_with_childtable_naming", + fields=[ + { + "label": "table with naming", + "fieldname": "table_with_naming", + "options": "childtable_with_autonaming", + "fieldtype": "Table", + } + ], + ).insert() + + name = frappe.generate_hash(length=10) + + doc = frappe.new_doc("dt_with_childtable_naming") + doc.append("table_with_naming", {"some_fieldname": name}) + doc.save() + self.assertEqual(doc.table_with_naming[0].name, name) + + # change autoname field + doc.table_with_naming[0].some_fieldname = "Something else" + doc.save() + + self.assertEqual(doc.table_with_naming[0].name, name) + self.assertEqual(doc.table_with_naming[0].some_fieldname, name) + + doc.delete() + dt_with_child_autoname.delete() + child_dt_with_naming.delete() + def test_format_autoname(self): """ Test if braced params are replaced in format autoname