Skip to Content
Menu
This question has been flagged
3 Replies
62476 Views

I'm using Odoo 11 and I have installed openHRMS module but every time when I press on the dashboard menu it appears an error on this method:

IndexError: list index out of range

Ps: i tried to install this module on bitnami VM and it works whithout any problem but when i tried to installe it on ubuntu 18.04 it shows error

Any ideas on how to fix it?

 def join_resign_trends(self):
    cr = self._cr
    month_list = []
    join_trend = []
    resign_trend = []
    for i in range(11, -1, -1):
        last_month = datetime.now() - relativedelta(months=i)
        text = format(last_month, '%B %Y')
        month_list.append(text)
    for month in month_list:
        vals = {
            'l_month': month,
            'count': 0
        }
        join_trend.append(vals)
    for month in month_list:
        vals = {
            'l_month': month,
            'count': 0
        }
        resign_trend.append(vals)
    cr.execute('''select to_char(joining_date, 'Month YYYY') as l_month, count(id) from hr_employee 
    WHERE joining_date BETWEEN CURRENT_DATE - INTERVAL '12 months'
    AND CURRENT_DATE + interval '1 month - 1 day'
    group by l_month;''')
    join_data = cr.fetchall()
    cr.execute('''select to_char(resign_date, 'Month YYYY') as l_month, count(id) from hr_employee 
    WHERE resign_date BETWEEN CURRENT_DATE - INTERVAL '12 months'
    AND CURRENT_DATE + interval '1 month - 1 day'
    group by l_month;''')
    resign_data = cr.fetchall()

    for line in join_data:
        match = list(filter(lambda d: d['l_month'].replace(' ', '') == line[0].replace(' ', ''), join_trend))
        match[0]['count'] = line[1]
    for line in resign_data:
        match = list(filter(lambda d: d['l_month'].replace(' ', '') == line[0].replace(' ', ''), resign_trend))
        match[0]['count'] = line[1]
    for join in join_trend:
        join['l_month'] = join['l_month'].split(' ')[:1][0].strip()[:3]
    for resign in resign_trend:
        resign['l_month'] = resign['l_month'].split(' ')[:1][0].strip()[:3]
    graph_result = [{
        'name': 'Join',
        'values': join_trend
    }, {
        'name': 'Resign',
        'values': resign_trend
    }]
    return graph_result

 def get_attrition_rate(self):
    month_attrition = []
    monthly_join_resign = self.join_resign_trends()
    month_join = monthly_join_resign[0]['values']
    month_resign = monthly_join_resign[1]['values']
    sql = """
    SELECT (date_trunc('month', CURRENT_DATE))::date - interval '1' month * s.a AS month_start 
    FROM generate_series(0,11,1) AS s(a);"""
    self._cr.execute(sql)
    month_start_list = self._cr.fetchall()
    for month_date in month_start_list:
        self._cr.execute("""select count(id), to_char(date '%s', 'Month YYYY') as l_month from hr_employee 
        where resign_date> date '%s' or resign_date is null and joining_date < date '%s'
        """ % (month_date[0], month_date[0], month_date[0],))
        month_emp = self._cr.fetchone()
        # month_emp = (month_emp[0], month_emp[1].split(' ')[:1][0].strip()[:3])
        match_join = list(filter(lambda d: d['l_month'] == month_emp[1].split(' ')[:1][0].strip()[:3], month_join))[0]['count']
        match_resign = list(filter(lambda d: d['l_month'] == month_emp[1].split(' ')[:1][0].strip()[:3], month_resign))[0]['count']
        month_avg = (month_emp[0]+match_join-match_resign+month_emp[0])/2
        attrition_rate = (match_resign/month_avg)*100 if month_avg != 0 else 0
        vals = {
            # 'month': month_emp[1].split(' ')[:1][0].strip()[:3] + ' ' + month_emp[1].split(' ')[-1:][0],
            'month': month_emp[1].split(' ')[:1][0].strip()[:3],
            'attrition_rate': round(float(attrition_rate), 2)
        }
        month_attrition.append(vals)
    return month_attrition

traceback

   Traceback (most recent call last):
   File "/opt/openhrms/odoo/http.py", line 651, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/openhrms/odoo/http.py", line 310, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "/opt/openhrms/odoo/tools/pycompat.py", line 87, in reraise
raise value
  File "/opt/openhrms/odoo/http.py", line 693, in dispatch
result = self._call_function(**self.params)
  File "/opt/openhrms/odoo/http.py", line 342, in _call_function
return checked_call(self.db, *args, **kwargs)
  File "/opt/openhrms/odoo/service/model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
  File "/opt/openhrms/odoo/http.py", line 335, in checked_call
result = self.endpoint(*a, **kw)
  File "/opt/openhrms/odoo/http.py", line 937, in __call__
return self.method(*args, **kw)
  File "/opt/openhrms/odoo/http.py", line 515, in response_wrap
response = f(*args, **kw)
 File "/opt/openhrms/addons/web/controllers/main.py", line 934, in call_kw
return self._call_kw(model, method, args, kwargs)
 File "/opt/openhrms/addons/web/controllers/main.py", line 926, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
 File "/opt/openhrms/odoo/api.py", line 687, in call_kw
return call_kw_model(method, model, args, kwargs)
 File "/opt/openhrms/odoo/api.py", line 672, in call_kw_model
result = method(recs, *args, **kwargs)
 File "/opt/openhrms/openhrms/hrms_dashboard/models/hrms_dashboard.py", line 384, in get_attrition_rate
monthly_join_resign = self.join_resign_trends()
 File "/opt/openhrms/openhrms/hrms_dashboard/models/hrms_dashboard.py", line 364, in join_resign_trends
match[0]['count'] = line[1]
IndexError: list index out of range
Avatar
Discard

line[1] doesn't exist as line[] is empty (or only has [0]) which gives this error.

Author

Thanks for your answer i tried to modify line[1] --> line[0] but it shows the same error

Best Answer

Hello Dhouda,

Put some print statements. May be it will help. i thing no data is coming into sql query, so it is blank list.

and it is blank list if you do list[0] even though it gives same error. So verify your code.

Avatar
Discard
Related Posts Replies Views Activity
2
Feb 24
13177
1
Dec 22
3859
2
Dec 22
12722
2
Jun 22
4683
2
Jun 22
3503