Reputation: 55
I added a custom field res.patner
, this field in Char data type, now I want to add it on account.move
by the code below.
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)
But when I try to open up an invoice i get:
Traceback (most recent call last):
File "C:\Program Files\Odoo\15\server\odoo\addons\base\models\ir_http.py", line 237, in _dispatch
result = request.dispatch()
File "C:\Program Files\Odoo\15\server\odoo\http.py", line 688, in dispatch
result = self._call_function(**self.params)
File "C:\Program Files\Odoo\15\server\odoo\http.py", line 360, in _call_function
return checked_call(self.db, *args, **kwargs)
File "C:\Program Files\Odoo\15\server\odoo\service\model.py", line 94, in wrapper
return f(dbname, *args, **kwargs)
File "C:\Program Files\Odoo\15\server\odoo\http.py", line 349, in checked_call
result = self.endpoint(*a, **kw)
File "C:\Program Files\Odoo\15\server\odoo\http.py", line 917, in __call__
return self.method(*args, **kw)
File "C:\Program Files\Odoo\15\server\odoo\http.py", line 536, in response_wrap
response = f(*args, **kw)
File "C:\Program Files\Odoo\15\server\odoo\addons\web\controllers\main.py", line 1348, in call_kw
return self._call_kw(model, method, args, kwargs)
File "C:\Program Files\Odoo\15\server\odoo\addons\web\controllers\main.py", line 1340, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "C:\Program Files\Odoo\15\server\odoo\api.py", line 464, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "C:\Program Files\Odoo\15\server\odoo\api.py", line 451, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "C:\Program Files\Odoo\15\server\odoo\models.py", line 3227, in read
return self._read_format(fnames=fields, load=load)
File "C:\Program Files\Odoo\15\server\odoo\models.py", line 3247, in _read_format
vals[name] = convert(record[name], record, use_name_get)
File "C:\Program Files\Odoo\15\server\odoo\fields.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 Files\Odoo\15\server\odoo\http.py", line 644, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "C:\Program Files\Odoo\15\server\odoo\http.py", line 302, in _handle_exception
raise exception.with_traceback(None) from new_cause
AttributeError: '_unknown' object has no attribute 'id'
Upvotes: 1
Views: 12506
Reputation: 26678
The first parameter (partner_id.member_medical_aid_number
) will be used as the comodel_name
and when Odoo will try to set up the field, it will check if the comodel name is loaded and if not it will set it to _unknown
You should see the following warning in the log:
Field account.move.patient_medical_aid_number_id with unknown comodel_name 'partner_id.member_medical_aid_number'
If you want to use a related field, set the related attribute and use the same field type
Example:
patient_medical_aid_number_id = fields.Char(related='partner_id.member_medical_aid_number', string='Patient Medical Aid Number', readonly=True)
Upvotes: 5