本文介绍了如何在odoo v9中覆盖BaseModel(openerp / models.py)的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想从文件openerp / models.py(line no 1365)中覆盖一个名为'user_has_groups'的函数。我尝试了这篇文章和这个问题 from openerp.models import BaseModel def my_user_has_groups(self,cr,uid,groups,context = None): #my code BaseModel.user_has_groups = my_user_has_groups 但它会导致以下错误。 p> TypeError:my_user_has_groups()至少需要4个参数(给出2个) 并且我尝试了这一行 BaseModel.user_has_groups = lambda cr,uid,groups,context:my_user_has_groups(cr,uid,groups,context) 它会导致以下错误: QWebException :< lambda>()为关键字参数'groups'获得了多个值 from 这篇文章。但它不起作用。 我怎么能做到这一点?请赐教。解决方案我用另一种方式解决了这个问题,在下面给出 来自openerp导入模型,api class BaseModelExtend(models.AbstractModel): _name ='basemodel.extend' def _register_hook(self,cr): @ api.cr_uid_context def user_has_groups(self,cr,uid,groups,context = None): #My code models .BaseModel.user_has_groups = user_has_groups return super(BaseModelExtend,self)._ register_hook(cr) I want to override a function called 'user_has_groups' in the class from the file openerp/models.py (line no 1365)I tried the code from this post and this questionfrom openerp.models import BaseModeldef my_user_has_groups(self, cr, uid, groups, context=None): #my codeBaseModel.user_has_groups = my_user_has_groupsBut it results the following error.TypeError: my_user_has_groups() takes at least 4 arguments (2 given)and also i tried this lineBaseModel.user_has_groups = lambda cr, uid, groups, context: my_user_has_groups(cr, uid, groups, context)It results the following errorQWebException: <lambda>() got multiple values for keyword argument 'groups'I also tried the code from this post. But it doesn't work.How I can achieve this? Please enlighten me. 解决方案 I solved this in another way around, which is given belowfrom openerp import models, apiclass BaseModelExtend(models.AbstractModel): _name = 'basemodel.extend' def _register_hook(self, cr): @api.cr_uid_context def user_has_groups(self, cr, uid, groups, context=None): #My code models.BaseModel.user_has_groups = user_has_groups return super(BaseModelExtend, self)._register_hook(cr) 这篇关于如何在odoo v9中覆盖BaseModel(openerp / models.py)的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-24 14:46