Oop openERP中的继承(odoo)
我是openERP的新手,有一次面试。请解释openERP中不同类型继承的概念,我认为总共有3种类型。请从面试的角度用非常简单的方式解释。Oop openERP中的继承(odoo),oop,openerp,odoo,openerp-7,openerp-8,Oop,Openerp,Odoo,Openerp 7,Openerp 8,我是openERP的新手,有一次面试。请解释openERP中不同类型继承的概念,我认为总共有3种类型。请从面试的角度用非常简单的方式解释。 附言:我熟悉简单继承的概念。继承: def existing(self, cr, uid, ids, x, y, z, context=None): parent_res = super(AccountInvoice, self).existing(cr, uid, ids, x, y, z, context=context) # my st
附言:我熟悉简单继承的概念。
继承:
def existing(self, cr, uid, ids, x, y, z, context=None):
parent_res = super(AccountInvoice, self).existing(cr, uid, ids, x, y, z, context=context)
# my stuff
return parent_res_plus_my_stuff
继承机制用于创建可重用的思想。可重用意味着在任何面向对象编程中重用父类的代码
优势:
def existing(self, cr, uid, ids, x, y, z, context=None):
parent_res = super(AccountInvoice, self).existing(cr, uid, ids, x, y, z, context=context)
# my stuff
return parent_res_plus_my_stuff
def existing(self, cr, uid, ids, x, y, z, context=None):
parent_res = super(AccountInvoice, self).existing(cr, uid, ids, x, y, z, context=context)
# my stuff
return parent_res_plus_my_stuff
def existing(self, cr, uid, ids, x, y, z, context=None):
parent_res = super(AccountInvoice, self).existing(cr, uid, ids, x, y, z, context=context)
# my stuff
return parent_res_plus_my_stuff
它允许通过继承从orm.Model派生的类(比如添加图形支持的geomedel),向模型添加特定的“通用”行为
class Myclass(GeoModel, AUtilsClass):
使用_inherit:-
主要目标是添加新行为/扩展现有模型。例如,您希望向发票添加新字段并添加新方法
class AccountInvoice(orm.Model):
_inherit = "account.invoice"
_column = {'my_field': fields.char('My new field')}
def a_new_func(self, cr, uid, ids, x, y, context=None):
# my stuff
return something
覆盖现有方法:
def existing(self, cr, uid, ids, x, y, z, context=None):
parent_res = super(AccountInvoice, self).existing(cr, uid, ids, x, y, z, context=context)
# my stuff
return parent_res_plus_my_stuff
2.多态方式:-
使用\u继承:-
当使用_inherits时,您将以数据库方式执行一种多态模型
例如,product.product
继承product.template
或res.users
继承res.partner
。这意味着我们创建一个模型,该模型获取模型的专有技术,但在新的数据库表中添加传统数据/列。因此,当您创建一个用户时,所有合作伙伴数据都存储在res\u partner
表中(并且创建了一个合作伙伴),所有与用户相关的信息都存储在res\u users
表中
为此,我们使用一个dict:_inherits={'res.partner':'partner_id'}
键对应于基本模型,外键的值对应于基本模型
与通过XML一样,您可以继承Odoo视图(如表单视图、树视图、搜索视图等),也可以从视图中更改行为
要点:
def existing(self, cr, uid, ids, x, y, z, context=None):
parent_res = super(AccountInvoice, self).existing(cr, uid, ids, x, y, z, context=context)
# my stuff
return parent_res_plus_my_stuff
上述两种方法可以应用于Odoo服务器端,您可以更改现有视图的行为,或者您可以在Odoo视图中更改的任何其他内容对客户端的影响
我希望这会对您有所帮助。:)您错过了odoo文档中提到的第三个。它不是真正的继承,而是通过组合_inherit和_name来建模属性的副本。也许你也应该提一下?:-)我们可以同时使用_inherit和_inherit吗@DASADIYACHAITANYANo两者都有不同的用法,根据我们的用法,我们可以选择“继承”或“继承”