属性错误:'_unknown'对象没有属性'id' - 在 Odoo 15 中



我添加了一个自定义字段res.patner,该字段为Char数据类型,现在我想通过下面的代码将其添加到account.move上。

class InvoicingMove(models.Model):
    _inherit = 'account.move'
    
    patient_medical_aid_number_id = fields.Many2one('partner_id.member_medical_aid_number', string='Patient Medical Aid Number', readonly=True)

但是当我试图打开发票时,我得到:

Traceback (most recent call last):
  File "C:Program FilesOdoo15serverodooaddonsbasemodelsir_http.py", line 237, in _dispatch
    result = request.dispatch()
  File "C:Program FilesOdoo15serverodoohttp.py", line 688, in dispatch
    result = self._call_function(**self.params)
  File "C:Program FilesOdoo15serverodoohttp.py", line 360, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "C:Program FilesOdoo15serverodooservicemodel.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "C:Program FilesOdoo15serverodoohttp.py", line 349, in checked_call
    result = self.endpoint(*a, **kw)
  File "C:Program FilesOdoo15serverodoohttp.py", line 917, in __call__
    return self.method(*args, **kw)
  File "C:Program FilesOdoo15serverodoohttp.py", line 536, in response_wrap
    response = f(*args, **kw)
  File "C:Program FilesOdoo15serverodooaddonswebcontrollersmain.py", line 1348, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "C:Program FilesOdoo15serverodooaddonswebcontrollersmain.py", line 1340, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "C:Program FilesOdoo15serverodooapi.py", line 464, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "C:Program FilesOdoo15serverodooapi.py", line 451, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "C:Program FilesOdoo15serverodoomodels.py", line 3227, in read
    return self._read_format(fnames=fields, load=load)
  File "C:Program FilesOdoo15serverodoomodels.py", line 3247, in _read_format
    vals[name] = convert(record[name], record, use_name_get)
  File "C:Program FilesOdoo15serverodoofields.py", line 2813, in convert_to_read
    return value.id
Exception
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "C:Program FilesOdoo15serverodoohttp.py", line 644, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "C:Program FilesOdoo15serverodoohttp.py", line 302, in _handle_exception
    raise exception.with_traceback(None) from new_cause
AttributeError: '_unknown' object has no attribute 'id'

第一个参数(partner_id.member_medical_aid_number)将用作comodel_name,当Odoo将尝试设置该字段时,它将检查是否加载了模型名称,如果没有,则将其设置为_unknown

您应该在日志中看到以下警告:

account.move

字段。Patient_medical_aid_number_id with unknown comodel_name 'partner_id.member_medical_aid_number'

如果要使用相关字段,请设置相关属性并使用相同的字段类型

例子:

patient_medical_aid_number_id = fields.Char(related='partner_id.member_medical_aid_number', string='Patient Medical Aid Number', readonly=True)

相关内容

  • 没有找到相关文章

最新更新