Odoo AttributeError: '_unknown' object has no attribute 'id'

This error typically arises when working with relationship fields, such as Many2one, One2many, and Many2many. Although it won’t block you from updating your module, it silently pop's up when you open a specific view, hinting that the model you’re trying to display is misconfigured.
I’ll quickly cover the most common causes of this error and the solutions that have proven effective across multiple Odoo versions, from Odoo 14 to Odoo 18.
Possibility 1: Incomplete Relationship Field Definitions
Forgetting to specify the target model for your relation fields as shown below. will result into the attibute.
product_id = fields.Many2one(string='Product')
product_id = fields.One2many(string='Product')
product_id = fields.Many2many(string='Product')
Without the target model defined, Odoo doesn’t know which object these fields should reference, much like giving someone directions without mentioning the destination.
The Fix
Therefore just specifying the model they are point to, as shown below:
product_id = fields.Many2one('product.product', string='Product')
product_id = fields.One2many('product.product', 'product_one_id', string='Product')
product_id = fields.Many2many('product.product', string='Product')
And for One2many fields, don’t forget to create the corresponding Many2one field in the related model. In this case, add something like:
product_one_id = fields.Many2one('custom.model', string='Product')
Possibility 2: Missing Module Dependencies in the Manifest
Another scenario that has tripped me up is when a relation field(as shown above) is defined without including the originating module as a dependency in the manifest file.
If your relation field references a model from another module, and that module isn’t listed in your manifest’s 'depends'
section, Odoo can’t resolve the reference, resulting in the same AttributeError.
The Fix:
Ensure that you declare all relevant modules in your manifest file. For example:
'depends': ['base', 'product'],
Since our relation fields in this example are linked to the product model, adding 'product'
as a dependency guarantees that Odoo loads the correct model definitions before your module is activated.
If all above mentioned solutions could not resolve your problem. Feel free to start the conversation in below section. would love to help you out. Until Again Happy Coding without burnout.