【问题标题】:error when i try to load the dashboard ( OpenHRMS odoo 13 CE)当我尝试加载仪表板时出错(OpenHRMS odoo 13 CE)
【发布时间】:2021-08-06 11:36:07
【问题描述】:
我在使用 Odoo 13 CE 的 OpenHRMS 模块时遇到问题,当我尝试加载仪表板时,出现此错误
list([d for d in month_join if d['l_month'] == month_emp[1].split('
')[:1][0].strip()[:3]])[0][IndexError: list index out of range
这两行代码是问题所在,但我不知道是怎么回事:
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']
请帮忙
【问题讨论】:
标签:
python
python-3.x
odoo
odoo-12
odoo-13
【解决方案1】:
我已经为我修好了:
@api.model
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])
month_join_filter = filter(lambda d: d['l_month'] == month_emp[1].split(' ')[:1][0].strip()[:3], month_join)
match_join = 0
if len(tuple(month_join_filter)) > 0:
match_join = list(month_join_filter)[0]['count']
month_resign_filter = filter(lambda d: d['l_month'] == month_emp[1].split(' ')[:1][0].strip()[:3], month_resign)
match_resign = 0
if len(tuple(month_resign_filter)) > 0:
match_resign = list(month_resign_filter)[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