Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to declare model attribute in Odoo

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 193
    Comment on it

    In a Model attribute order should follow the series given below.
    Private attributes (_name, _description, _inherit, ...)
    1. Default method and _default_get
    2. Field declarations
    3. Compute and search methods in the same order as field declaration
    4. Constrains methods (@api.constrains) and onchange methods (@api.onchange)
    5. CRUD methods (ORM overrides)
    6. Action methods
    7. And finally, other business methods.
    For example you can see below code..

    class Event(models.Model):
        # Private attributes
        _name = 'event.event'
        _description = 'Event'
    
        # Default methods
        def _default_name(self):
            ...
    
        # Fields declaration
        name = fields.Char(string='Name', default=_default_name)
        seats_reserved = fields.Integer(oldname='register_current', string='Reserved Seats',
            store=True, readonly=True, compute='_compute_seats')
        seats_available = fields.Integer(oldname='register_avail', string='Available Seats',
            store=True, readonly=True, compute='_compute_seats')
        price = fields.Integer(string='Price')
    
        # compute and search fields, in the same order that fields declaration
        @api.multi
        @api.depends('seats_max', 'registration_ids.state', 'registration_ids.nb_register')
        def _compute_seats(self):
            ...
    
        # Constraints and onchanges
        @api.constrains('seats_max', 'seats_available')
        def _check_seats_limit(self):
            ...
    
        @api.onchange('date_begin')
        def _onchange_date_begin(self):
            ...
    
        # CRUD methods
        def create(self):
            ...
    
        # Action methods
        @api.multi
        def action_validate(self):
            self.ensure_one()
            ...
    
        # Business methods
        def mail_user_confirm(self):
            ...
    

    Note-Private attributes (_name, _description, _inherit, ) is used to declare model.

 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: