How we can inherit BaseModel class in odoo

☆樱花仙子☆ 提交于 2019-12-11 04:25:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!