odoo

【odoo 10.0】模型(model)相关

2017-02-26  本文已影响299人  battle_

参考链接
https://www.odoo.com/documentation/10.0/howtos/backend.html#relations-between-models
https://www.odoo.com/documentation/10.0/howtos/backend.html#inheritance

模型关联

模型继承

模型继承
class Extension0(models.Model):
    _name = 'extension.0'
    name = fields.Char(default="A")
class Extension1(models.Model):
    _inherit = 'extension.0'
    description = fields.Char(default="Extended")
class Inheritance0(models.Model):
    _name = 'inheritance.0'
    name = fields.Char()
    def call(self):
        return self.check("model 0")
    def check(self, s):
        return "This is {} record {}".format(s, self.name)
class Inheritance1(models.Model):
    _name = 'inheritance.1'
    _inherit = 'inheritance.0'
    def call(self):
        return self.check("model 1")
class Child0(models.Model):
    _name = 'delegation.child0'
    field_0 = fields.Integer()
class Child1(models.Model):
    _name = 'delegation.child1'
    field_1 = fields.Integer()
class Delegating(models.Model):
    _name = 'delegation.parent'
    _inherits = {
        'delegation.child0': 'child0_id',
        'delegation.child1': 'child1_id',
    }
    child0_id = fields.Many2one('delegation.child0', required=True, ondelete='cascade')
    child1_id = fields.Many2one('delegation.child1', required=True, ondelete='cascade')

使用

super(TestDelegation, self).setUp()
        env = self.env
        record = env['delegation.parent'].create({
            'child0_id': env['delegation.child0'].create({'field_0': 0}).id,
        # children fields can be looked up on the parent record directly
        env = self.env
record.field_0
record.field_1
上一篇 下一篇

猜你喜欢

热点阅读