如何在odoo中继承或取消@classmethod

时间:2017-08-24 06:10:08

标签: openerp odoo-9 odoo-10

我想继承class BaseModel(object)

@classmethod

如何继承或覆盖自定义模块中的{{1}}?

1 个答案:

答案 0 :(得分:1)

我今天刚刚遇到这个问题:)

您可以通过几种方式扩展它。这取决于您是否真的需要扩展BaseModel,或者如果您需要扩展BaseModel的特定子类。

子类

对于任何子类,您可以像通常那样继承它:

from odoo import api, fields, models

class User(models.Model):
    _inherit = 'res.users'

    @classmethod
    def check(cls, db, uid, passwd):
        return super(User, cls).check(db, uid, passwd)

直接扩展BaseModel

BaseModel本身的情况下,你需要修补补丁:

from odoo import models

def my_build_model(cls, pool, cr):
    # Make any changes I would like...

    # This the way of calling super(...) for a monkey-patch
    return models.BaseModel._build_model(pool, cr)

models.BaseModel._build_model = my_build_model