Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Delegation in odoo9

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 330
    Comment on it

    Delegation is most important for odoo module, it is the third inheritance mechanism which provides more flexibility (it can be altered at runtime) but less power: using the _inherits a model delegates the lookup of any field not found on the current model to "children" models. The delegation performes reference fields automatically set up on the parent model.
    For example code is below.

    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')
            record = env['delegation.parent'].create({
                'child0_id': env['delegation.child0'].create({'field_0': 0}).id,
                'child1_id': env['delegation.child1'].create({'field_1': 1}).id,
            })
            record.field_0
            record.field_1

    And output will be- 0
    1
    and it's possible to write directly on the delegated field:

      record.write({'field_1': 4})
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: