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
    • 203
    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..

    1. class Event(models.Model):
    2. # Private attributes
    3. _name = 'event.event'
    4. _description = 'Event'
    5.  
    6. # Default methods
    7. def _default_name(self):
    8. ...
    9.  
    10. # Fields declaration
    11. name = fields.Char(string='Name', default=_default_name)
    12. seats_reserved = fields.Integer(oldname='register_current', string='Reserved Seats',
    13. store=True, readonly=True, compute='_compute_seats')
    14. seats_available = fields.Integer(oldname='register_avail', string='Available Seats',
    15. store=True, readonly=True, compute='_compute_seats')
    16. price = fields.Integer(string='Price')
    17.  
    18. # compute and search fields, in the same order that fields declaration
    19. @api.multi
    20. @api.depends('seats_max', 'registration_ids.state', 'registration_ids.nb_register')
    21. def _compute_seats(self):
    22. ...
    23.  
    24. # Constraints and onchanges
    25. @api.constrains('seats_max', 'seats_available')
    26. def _check_seats_limit(self):
    27. ...
    28.  
    29. @api.onchange('date_begin')
    30. def _onchange_date_begin(self):
    31. ...
    32.  
    33. # CRUD methods
    34. def create(self):
    35. ...
    36.  
    37. # Action methods
    38. @api.multi
    39. def action_validate(self):
    40. self.ensure_one()
    41. ...
    42.  
    43. # Business methods
    44. def mail_user_confirm(self):
    45. ...

    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
Reset Password
Fill out the form below and reset your password: