odoo报错TypeError: unsupported operand type(s) for +: ‘NoneType‘ and ‘str‘(已解决)

RPC_ERROR
Odoo Server Error
Traceback (most recent call last):
  File "D:\odoo17\odoo17\odoo\http.py", line 1732, in _serve_db
    return service_model.retrying(self._serve_ir_http, self.env)
  File "D:\odoo17\odoo17\odoo\service\model.py", line 133, in retrying
    result = func()
  File "D:\odoo17\odoo17\odoo\http.py", line 1759, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
  File "D:\odoo17\odoo17\odoo\http.py", line 1960, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
  File "D:\odoo17\odoo17\odoo\addons\website\models\ir_http.py", line 235, in _dispatch
    response = super()._dispatch(endpoint)
  File "D:\odoo17\odoo17\odoo\addons\base\models\ir_http.py", line 207, in _dispatch
    result = endpoint(**request.params)
  File "D:\odoo17\odoo17\odoo\http.py", line 722, in route_wrapper
    result = endpoint(self, *args, **params_ok)
  File "D:\odoo17\odoo17\odoo\addons\web\controllers\dataset.py", line 24, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "D:\odoo17\odoo17\odoo\addons\web\controllers\dataset.py", line 20, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "D:\odoo17\odoo17\odoo\api.py", line 462, in call_kw
    result = _call_kw_model(method, model, args, kwargs)
  File "D:\odoo17\odoo17\odoo\api.py", line 435, in _call_kw_model
    result = method(recs, *args, **kwargs)
  File "D:\odoo17\odoo17\odoo\addons\web_studio\models\ir_ui_view.py", line 53, in get_views
    return super().get_views(views, options)
  File "D:\odoo17\odoo17\odoo\addons\base\models\ir_ui_view.py", line 2435, in get_views
    result['views'] = {
  File "D:\odoo17\odoo17\odoo\addons\base\models\ir_ui_view.py", line 2436, in <dictcomp>
    v_type: self.get_view(
  File "D:\odoo17\odoo17\odoo\addons\base\models\ir_ui_view.py", line 2621, in get_view
    result = dict(self._get_view_cache(view_id, view_type, **options))
  File "D:\odoo17\odoo17\odoo\addons\base\models\ir_ui_view.py", line 2577, in _get_view_cache
    arch, view = self._get_view(view_id, view_type, **options)
  File "D:\odoo17\odoo17\odoo\addons\base\models\ir_ui_view.py", line 2524, in _get_view
    arch = view._get_combined_arch()
  File "D:\odoo17\odoo17\odoo\addons\website\models\ir_ui_view.py", line 499, in _get_combined_arch
    root = super(View, self)._get_combined_arch()
  File "D:\odoo17\odoo17\odoo\addons\base\models\ir_ui_view.py", line 947, in _get_combined_arch
    arch = root.with_prefetch(tree_views._prefetch_ids)._combine(hierarchy)
  File "D:\odoo17\odoo17\odoo\addons\base\models\ir_ui_view.py", line 865, in _combine
    combined_arch = etree.fromstring(self.arch)
  File "D:\odoo17\odoo17\odoo\fields.py", line 1205, in __get__
    self.compute_value(recs)
  File "D:\odoo17\odoo17\odoo\fields.py", line 1387, in compute_value
    records._compute_field_value(self)
  File "D:\odoo17\odoo17\odoo\models.py", line 4848, in _compute_field_value
    fields.determine(field.compute, self)
  File "D:\odoo17\odoo17\odoo\fields.py", line 101, in determine
    return needle(*args)
  File "D:\odoo17\odoo17\odoo\addons\base\models\ir_ui_view.py", line 245, in _compute_arch
    arch_fs = get_view_arch_from_file(fullpath, xml_id)
  File "D:\odoo17\odoo17\odoo\addons\base\models\ir_ui_view.py", line 121, in get_view_arch_from_file
    return field_arch.text + inner
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

The above server error caused the following client error:
OwlError: An error occured in the owl lifecycle (see this Error's "cause" property)
    at handleError (http://localhost:9099/web/assets/60d367e/web.assets_web.min.js:916:101)
    at App.handleError (http://localhost:9099/web/assets/60d367e/web.assets_web.min.js:1543:29)
    at ComponentNode.initiateRender (http://localhost:9099/web/assets/60d367e/web.assets_web.min.js:1006:19)

Caused by: RPC_ERROR: Odoo Server Error
    at makeErrorFromResponse (http://localhost:9099/web/assets/60d367e/web.assets_web.min.js:2867:163)
    at XMLHttpRequest.<anonymous> (http://localhost:9099/web/assets/60d367e/web.assets_web.min.js:2871:13)

可以看到运行出现上述错误,这个错误的出现是由于视图文件中的一些问题导致的。你可以检查视图文件的内容,特别是在get_view_arch_from_file函数中,看看是否有未定义的变量或者NoneType的值导致了这个错误。题主的情况是自己在处理另一个模块,这个模块莫名其妙受到影响,最后发现是odoo的ir_ui_view文件出现问题。

可以看到,在get_view_arch_from_file函数中,已经对field_arch.text进行了None检查。因此,可能的错误原因并不在这里。根据错误信息,问题可能出现在field_arch.text + inner这一行。这表明field_arch.text可能为None,导致无法与字符串inner进行连接。

为了解决这个问题,可以在连接field_arch.textinner之前,先检查field_arch.text是否为None。如果为None,可以将其替换为空字符串。这样可以避免出现TypeError。

if field_arch is not None:
    _fix_multiple_roots(field_arch)
    inner = ''.join(
        etree.tostring(child, encoding='unicode')
        for child in field_arch.iterchildren()
    )
    field_text = field_arch.text if field_arch.text is not None else ''
    return field_text + inner

如此便可解决!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

odoo实施

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值