selection_447

Some cool Odoo command that we forgot

Though I have done a lot of coding in Odoo, but after I bought the book Odoo 10 Development Essential and start reading it. It reminds me many of the command that I forgot. Here are some of them,

Save default config file

Create and save default config file ~/.odoorc using –save when starting Odoo server

Bypassing ORM security

Bypassing ORM security with auto_join=True. It allows the ORM to use SQL joins when doing searches using this relationship. If used, the access security rules will be bypassed, and the user

Hierarchic relationships

For performance consideration, we use _parent_store with parent_left and parent_right

class Tags(models.Model):
  _parent_store = True
  parent_id = fields.Many2one(
    'todo.task.tag', 'Parent Tag', ondelete='restrict')
  parent_left = fields.Integer('Parent Left', index=True)
  parent_right = fields.Integer('Parent Right', index=True)

Show Inactive Records in Tree View

Normally, tree view will show only active record. We can force it to show active also by passing {‘active_test’: False} in Action Context

Reference Fields

Normal Many2one field can only reference 1 model. But if we want to have a field that can reference to more than 1 model, we can use fields.Reference. Following example, refers_to field can refer to both user or partner.

refers_to = fields.Reference(
  [('res.user', 'User'), ('res.partner', 'Partner')],
  'Refers to',
)
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *