fix(projects): read the Timesheet label from the employee field

Timesheet was the only doctype where the {...} template on `title`
actually rendered: `title_field` was `title`, so `set_title_field()`
seeded it from `{employee_name}` on insert. A `default` renders once, so
reassigning a draft left the stored title — and every label derived from
it — on the previous employee, with no way to correct it from the form
because the field is hidden.

Point `title_field` at `employee_name` so the label reads the live field
instead of a copy that drifts. Existing rows need no backfill.
This commit is contained in:
Mihir Kandoi
2026-07-30 08:22:00 +05:30
parent f71946def7
commit 03d84430b6
2 changed files with 13 additions and 3 deletions

View File

@@ -453,6 +453,17 @@ class TestTimesheet(ERPNextTestSuite):
rate = get_timesheet_detail_rate(detail.name, timesheet.currency)
self.assertEqual(rate, detail.billing_amount)
def test_title_follows_employee(self):
first = make_employee("_test_timesheet_title_one@example.com", company="_Test Company")
second = make_employee("_test_timesheet_title_two@example.com", company="_Test Company")
timesheet = make_timesheet(first, simulate=True, do_not_submit=True)
self.assertEqual(timesheet.get_title(), frappe.db.get_value("Employee", first, "employee_name"))
timesheet.employee = second
timesheet.save()
self.assertEqual(timesheet.get_title(), frappe.db.get_value("Employee", second, "employee_name"))
@staticmethod
def _delete_if_exists(doctype, name):
if frappe.db.exists(doctype, name):

View File

@@ -49,7 +49,6 @@
"fields": [
{
"allow_on_submit": 1,
"default": "{employee_name}",
"fieldname": "title",
"fieldtype": "Data",
"hidden": 1,
@@ -315,7 +314,7 @@
"idx": 1,
"is_submittable": 1,
"links": [],
"modified": "2026-04-08 12:43:30.658074",
"modified": "2026-07-30 11:04:12.882140",
"modified_by": "Administrator",
"module": "Projects",
"name": "Timesheet",
@@ -409,5 +408,5 @@
"sort_field": "creation",
"sort_order": "ASC",
"states": [],
"title_field": "title"
"title_field": "employee_name"
}