如何使用继承

时间:2017-12-27 09:31:50

标签: openerp odoo-9

环境: - Odoo 9,Python 2.7

模块A

from openerp import models, fields, api, _, exceptions

class Games(models.Model):
    _name = 'moduleA.games'

    game = fields.Selection([
       ('cricket', 'Cricket'),
       ('hockey', 'Hockey'),
       ('golf', 'Golf')], 
       string='Game', default='cricket', required=True
    )

模块B

from openerp import models, fields, api, _, exceptions

class ExtraGames(models.Model):
    _inherit = 'moduleA.games'

    def __init__(self, pool, cr):
        res = super(ExtraGames,self)._columns # res = {}
        super(ExtraGames,self)._columns['game'].selection.append(
            ('chess', 'Chess')
        )

现在使用该代码,我想在已经定义的游戏列表中添加一个游戏国际象棋,但它不起作用。实际上我得到了空字典({})作为超级(ExtraGames,self)._列的结果,因为它给出了 KeyError'游戏'

我们怎么做?

1 个答案:

答案 0 :(得分:3)

您可以使用selection_add

from openerp import fields, models

class ExtraGames(models.Model):
    _inherit = 'moduleA.games'

    game = fields.Selection(
        selection_add=[('chess', 'Chess')],
    )