HR Module error logs seem to be a bug?

Hi,

Is this a bug - on a fresh install on erpnext v12 im getting error logs

‘erpnext.hr.doctype.leave_ledger_entry.leave_ledger_entry.process_expired_allocation’

{‘event’: u’daily_long’, ‘retry’: 0, ‘log’: <function log at 0x7f8183b146e0>, ‘site’: u’erp.aptronics.co.za’, ‘job_name’: u’erpnext.hr.doctype.leave_ledger_entry.leave_ledger_entry.process_expired_allocation’, ‘method_name’: u’erpnext.hr.doctype.leave_ledger_entry.leave_ledger_entry.process_expired_allocation’, ‘method’: <function process_expired_allocation at 0x7f81838a4488>, ‘user’: u’Administrator’, ‘kwargs’: {}, ‘is_async’: True}
Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/background_jobs.py”, line 99, in execute_job
method(**kwargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/leave_ledger_entry/leave_ledger_entry.py”, line 119, in process_expired_allocation
if expire_allocation:
UnboundLocalError: local variable ‘expire_allocation’ referenced before assignment

Am I missing a tick box or config somewhere?

Kind regards
Hemant

1 Like

I am getting the same thing, Fresh v12 install.

Same here. I am getting this error.

“Am I missing a tick box or config somewhere?”

No it seems the error occurs since expire_allocation is not assigned on line # 107 since that code is ‘out of scope’ of the code that begins on line # 98 ‘if leave_type_records:’

What you could try: Move line #s 119 and 120 within the scope by indenting them so that they will be assigned
https://github.com/frappe/erpnext/blob/develop/erpnext/hr/doctype/leave_ledger_entry/leave_ledger_entry.py#L119

like this:

		expire_allocation = frappe.get_all("Leave Ledger Entry",
			fields=['leaves', 'to_date', 'employee', 'leave_type', 'is_carry_forward', 'transaction_name as name', 'transaction_type'],
			filters={
				'to_date': ("<", today()),
				'transaction_type': 'Leave Allocation',
				'transaction_name': ('not in', expired_allocation)
			},
			or_filters={
				'is_carry_forward': 0,
				'leave_type': ('in', leave_type)
			})

       	if expire_allocation:
        	create_expiry_ledger_entry(expire_allocation)

Is that the case of what do you suggest @mangesh_khairnar? I see this commit to 12.0.8 a few weeks ago fix: check for old unexpired allocation · frappe/erpnext@3146475 · GitHub

I have added a fix for the same in this PR: fix: process allocation expiry by Mangesh-Khairnar · Pull Request #18853 · frappe/erpnext · GitHub.