Leave policy bulk allocation error

App Versions

{
	"erpnext": "13.17.0",
	"frappe": "13.17.0"
}

Route

List/Leave Policy Assignment/List

Trackeback

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 68, in application
    response = frappe.api.handle()
  File "apps/frappe/frappe/api.py", line 55, in handle
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 31, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 67, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1208, in call
    return fn(*args, **newargs)
  File "apps/erpnext/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.py", line 159, in create_assignment_for_multiple_employees
    assignment.submit()
  File "apps/frappe/frappe/model/document.py", line 938, in submit
    return self._submit()
  File "apps/frappe/frappe/model/document.py", line 926, in _submit
    return self.save()
  File "apps/frappe/frappe/model/document.py", line 285, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 340, in _save
    self.run_post_save_methods()
  File "apps/frappe/frappe/model/document.py", line 1006, in run_post_save_methods
    self.run_method("on_submit")
  File "apps/frappe/frappe/model/document.py", line 867, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1160, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1143, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/document.py", line 861, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "apps/erpnext/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.py", line 22, in on_submit
    self.grant_leave_alloc_for_employee()
  File "apps/erpnext/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.py", line 61, in grant_leave_alloc_for_employee
    leave_allocations[leave_policy_detail.leave_type] = {"name": leave_allocation, "leaves": new_leaves_allocated}
UnboundLocalError: local variable 'leave_allocation' referenced before assignment

Request Data

{
	"type": "POST",
	"args": {
		"employees": "[\"PIB-HQ-10001\",\"PIB-HQ-10002\",\"PIB-HQ-10004\",\"PIB-HQ-10006\",\"PIB-HQ-10007\",\"PIB-HQ-10008\",\"PIB-HQ-10009\",\"PIB-HQ-10012\",\"PIB-HQ-10013\",\"PIB-HQ-10023\",\"PIB-HQ-10024\",\"PIB-HQ-10025\",\"PIB-HQ-10027\",\"PIB-HQ-10028\"]",
		"data": "{\"leave_policy\":\"HR-LPOL-2021-00001\",\"effective_from\":\"2022-01-01\",\"effective_to\":\"2022-12-31\",\"carry_forward\":0,\"filtered_children\":[]}"
	},
	"headers": {},
	"error_handlers": {},
	"async": false,
	"url": "/api/method/erpnext.hr.doctype.leave_policy_assignment.leave_policy_assignment.create_assignment_for_multiple_employees"
}

Response Data

{
	"exception": "UnboundLocalError: local variable 'leave_allocation' referenced before assignment"
}

Further fixes and progress might be notified here:

https://github.com/frappe/erpnext/pull/29086

Update: Fixed and merged. You shouldn’t see this error now.