Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
1337 มุมมอง

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)

Explanation:

  • _inherit = 'base': The base model is the root for all Odoo models. Adding a field here makes it available across all models (e.g., res.partner, sale.order, account.move, etc.).
  • copy=False: Prevents duplication of the field’s value when a record is duplicated.
  • index=True: Creates a database index for faster lookups.

This is the cleanest and recommended approach, since it doesn’t require manually modifying every individual model.


Hope it helps

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi Reinaldo Menendez

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.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
4
ก.ย. 25
6362
0
ส.ค. 25
630
4
พ.ค. 25
3092
2
พ.ค. 25
6515
1
มี.ค. 25
2065