微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

类型错误:'bool' 对象在 Python3、odoo 中不可下标

如何解决类型错误:'bool' 对象在 Python3、odoo 中不可下标

我不知道我的问题出在哪里。因为年是字符字段必须是字符串而不是布尔值。
我真的感到很沮丧。我该怎么做才能解决这个问题?
任何形式的帮助将不胜感激!
请给我一些建议。谢谢!

这是我的代码

class HreDetailList(models.EcoModel):

_name = "hre.detail.list"

def _compute_holiday_flag(self):

    for record in self:
        record.work_on_holiday = False
        Now_year = int(record.years[:4])
        next_year = Now_year + 1
        holiday_obj = self.env['hra.holiday']
        holiday_data = holiday_obj.search([('holi_yy','ilike',next_year),('holi_name','=','Xmas')])

        change_obj = self.env['hre.changedtl']
        change_data = change_obj.search([('hre_empbas_id.emp_no',record.emp_no),('trans_flag',True),('lt_startdate','=like',record.years[:4] + '%')])

        for change_datadtl in change_data:
            if change_datadtl.chg_kind == '6M' or change_datadtl.chg_kind == '6N' or change_datadtl.chg_kind == '6L':
                if holiday_data.holi_date >= change_datadtl.lt_startdate and holiday_data.holi_date <= change_datadtl.lt_enddate:
                    record.work_on_holiday = True
                    break
                else:
                    record.work_on_holiday = False

years = fields.Char(string='Year',size=7,required=True)
work_on_holiday = fields.Boolean(compute=_compute_holiday_flag,string='Work on holiday')

我收到以下错误:TypeError: 'bool' object is not subscriptable:

odoo Server Error
Traceback (most recent call last):
  File "/vagrant/odoo/odoo/addons/base/models/ir_http.py",line 237,in _dispatch
    result = request.dispatch()
  File "/vagrant/odoo/odoo/http.py",line 682,in dispatch
    result = self._call_function(**self.params)
  File "/vagrant/odoo/odoo/http.py",line 358,in _call_function
    return checked_call(self.db,*args,**kwargs)
  File "/vagrant/odoo/odoo/service/model.py",line 94,in wrapper
    return f(dbname,**kwargs)
  File "/vagrant/odoo/odoo/http.py",line 346,in checked_call
    result = self.endpoint(*a,**kw)
  File "/vagrant/odoo/odoo/http.py",line 911,in __call__
    return self.method(*args,line 530,in response_wrap
    response = f(*args,**kw)
  File "/vagrant/odoo/addons/web/controllers/main.py",line 1359,in call_kw
    return self._call_kw(model,method,args,kwargs)
  File "/vagrant/odoo/addons/web/controllers/main.py",line 1351,in _call_kw
    return call_kw(request.env[model],kwargs)
  File "/vagrant/odoo/odoo/api.py",line 396,in call_kw
    result = _call_kw_multi(method,model,line 383,in _call_kw_multi
    result = method(recs,**kwargs)
  File "/vagrant/odoo/odoo/models.py",line 6165,in onchange
    value = record[name]
  File "/vagrant/odoo/odoo/models.py",line 5640,in __getitem__
    return self._fields[key].__get__(self,type(self))
  File "/vagrant/odoo/odoo/fields.py",line 972,in __get__
    self.compute_value(recs)
  File "/vagrant/odoo/odoo/fields.py",line 1111,in compute_value
    records._compute_field_value(self)
  File "/vagrant/odoo/odoo/models.py",line 4037,in _compute_field_value
    field.compute(self)
  File "/vagrant/odoo/addons/hre_formwork/models/hre_formwork.py",line 3887,in_compute_holiday_flag
    Now_year = int(record.years[:4])
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/vagrant/odoo/odoo/http.py",line 638,in _handle_exception
    return super(JsonRequest,self)._handle_exception(exception)
  File "/vagrant/odoo/odoo/http.py",line 314,in _handle_exception
    raise exception.with_traceback(None) from new_cause
TypeError: 'bool' object is not subscriptable

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。