I want to add a field, for example, 'external_id' = fields.Char() to all the odoo models.
How can I achieve this?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
I want to add a field, for example, 'external_id' = fields.Char() to all the odoo models.
How can I achieve this?
Hi,
You can achieve this by extending the base model, since every Odoo model ultimately inherits from it.
This way, your new field will automatically be added to all models in the system.
Example:
addons/external_id_field/models/base.py
from odoo import models, fields
class BaseModel(models.AbstractModel):
_inherit = 'base'
external_id = fields.Char("External ID", copy=False, index=True)
This is the cleanest and recommended approach, since it doesn’t require manually modifying every individual model.
Hope it helps
You need add external_id field in all models
so you need to override _inherit = "ir.model" models then add
example:
class IrModel(models.Model):
_inherit = 'ir.model'
'external_id' = fields.Char()
Thanks.
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
4
thg 9 25
|
6350 | ||
|
0
thg 8 25
|
628 | ||
|
4
thg 5 25
|
3087 | ||
|
2
thg 5 25
|
6513 | ||
|
1
thg 3 25
|
2060 |