给所有的model都添加一个方法, 即所有的model都能调用【类似于create、write、unlink、read】.
方式一:
from odoo import api, fields, models, tools
def common_model_func(self,content):
print ('teststtg')
print ('content',content)
return True
models.BaseModel.common_model_func = common_model_func # 将此方法传递给BaseModel
然后在其他模型可以调用:self.common_model_func('demo')
使用到的案例
from odoo import api, fields, models, tools
fields_view_get_origin = models.BaseModel.fields_view_get
@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
result = fields_view_get_origin(self, view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
view_get_approval_flow(self, view_type, result)
return result
models.BaseModel.fields_view_get = fields_view_get
心有猛虎,细嗅蔷薇