ERPNext Conference 2019* ERPNext.com Blog

HR Module error logs seem to be a bug?


#1

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


#2

I am getting the same thing, Fresh v12 install.


#3

Same here. I am getting this error.


#4

“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

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 https://github.com/frappe/erpnext/commit/314647572cc0824dddc34d3057f2e321fa3d9176


#5

I have added a fix for the same in this PR: https://github.com/frappe/erpnext/pull/18853.


Local variable 'expire_allocation' referenced before assignment (ERPNext: v12.0.8)