问题
Need to inherit BaseModel class and add a new attribute like
_auto = True
_register = False
_name = None
_columns = {}
_constraints = []
_custom = False
_defaults = {}
_rec_name = None
_parent_name = 'parent_id'
_parent_store = False
_parent_order = False
_date_name = 'date'
_order = 'id'
_sequence = None
_description = None
_needaction = False
_translate = True
Use this attribute in all models so need to be declare as a global
example :
from openerp import api, fields, models, _
class NewClass(models.Model):
_name = 'object name'
_new_attribute = 'vaule'
回答1:
from openerp import api, fields, models, _
class BaseModelExtend(models.AbstractModel):
_name = 'basemodel.extend'
models.BaseModel._navigation = 'id'
def _register_hook(self, cr):
'''
Register method in BaseModel
'''
@api.multi
def navigate_field(self):
#CODE
return True
models.BaseModel.navigate_field = navigate_field
return super(BaseModelExtend, self)._register_hook(cr)
回答2:
1- create a new python file my_basemodel.py
2- add your custom methods like this
from openerp.osv.orm import BaseModel
# built your attribute. you can refer inbuilt code to create attribute.
来源:https://stackoverflow.com/questions/44542771/how-we-can-inherit-basemodel-class-in-odoo