openERP中的继承(odoo) [英] Inheritance in openERP (odoo)

查看:71
本文介绍了openERP中的继承(odoo)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是openERP的新人,接受了采访.请解释一下openERP中不同类型的继承的想法,我认为总共有3种类型.请从访谈的角度以非常简单的方式进行解释.
附注:我熟悉简单继承的概念.

I am new in openERP and have an interview. Please explain the idea of different types of inheritance in openERP, i think it total 3 types. please explain it in very simple way from the perspective of interview.
P.S: I am familiar with the concept of simple inheritance.

推荐答案

继承:

继承机制用于创建可重用性的概念.可重用性意味着可以在任何面向对象的编程中重用父类的代码.

Inheritance mechanism is used to create idea of re usability.there re usability means that reuse the code of the parent class in any Object Oriented Programming.

优势:

  1. 减少代码冗余.
  2. 提供代码可重用性.
  3. 减小源代码的大小并提高代码的可读性.
  4. 代码易于管理,并分为父类和子类.
  5. 通过重写基类来支持代码可扩展性 子类中的功能.
  1. Reduce code redundancy.
  2. Provides code reusability.
  3. Reduces source code size and improves code readability.
  4. Code is easy to manage and divided into parent and child classes.
  5. Supports code extensibility by overriding the base class functionality within child classes.

缺点:

  1. 在继承中,基类和子类紧密耦合. 因此,如果您更改父类的代码,它将对 所有子类.

  1. In Inheritance base class and child classes are tightly coupled. Hence If you change the code of parent class, it will get affects to the all the child classes.

在类层次结构中,许多数据成员保持未使用状态,并且内存 分配给他们的资源不被利用.因此影响您的表现 程序,如果您没有正确实现继承.

In class hierarchy many data members remain unused and the memory allocated to them is not utilized. Hence affect performance of your program if you have not implemented inheritance correctly.

OpenERP中有两种继承方法.

1.使用Pythonic方式的经典方法:

它可以通过继承从orm.Model派生的类(例如geoModel来添加goegraphic支持),向Model添加特定的泛型"行为.

It allows to add specific "generic" behavior to Model by inheriting classes that derive from orm.Model like geoModel that adds goegraphic support.

 class Myclass(GeoModel, AUtilsClass):

使用_inherit:-

主要目标是添加新行为/扩展现有模型.例如,您要向发票添加新字段并添加新方法

The main objective is to add new behaviors/extend existing models. For example you want to add a new field to an invoice and add a new method

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.多态方式:-

使用_inherits:-

使用_inherits时,您将以数据库方式创建一种多态模型.

When using _inherits you will do a kind of polymorphic model in the database way.

例如product.product 继承 product.templateres.users 继承 res.partner.这意味着我们创建了一个模型,该模型获得了模型的专业知识,但在新的数据库表中添加了附加数据/列.因此,在创建用户时,所有合作伙伴数据都存储在res_partner表中(并创建了一个合作伙伴),所有与用户相关的信息都存储在res_users表中.

For example product.product inherits product.template or res.users inherits res.partner. This mean we create a model that gets the know how of a Model but adds aditional data/columns in a new database table. So when you create a user, all partner data is stored in res_partner table (and a partner is created) and all user related info is stored in res_users table.

为此,我们使用dict: _inherits = {'res.partner': 'partner_id'}键对应于基本模型,值对应于基本模型的外键.

To do this we use a dict: _inherits = {'res.partner': 'partner_id'} The key corresponds to the base model and the value to the foreign key to the base model.

与通过XML一样,您可以继承Odoo视图(例如窗体视图,树视图,搜索视图等.),也可以从视图更改行为

关键点:

以上两种方法都可以在Odoo服务器端应用,您可以更改现有视图的行为,也可以在Odoo视图中更改其他任何效果,以在客户端发挥作用.

The above two method can be apply on the Odoo server side and which you can change the behaviour of existing view or any other things you can change in Odoo views the effect with on your client side.

我希望这对您有帮助..:)

I hope this should helpful for you ..:)

这篇关于openERP中的继承(odoo)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆