Hello Odooers, Odoogig and Odoo Lovers,
In this odoo technical tutorial I would like to explain what is active_id and active_ids in odoo and what is importance active_id in odoo . how to use it in odoo development( as programmer)
- In Odoo, each record has an unique identification number which is known as id of that record
- for example you have created a fresh database and then when you create a Sale Order, so the id of that first sale order will be 1 . then you create second sale order so id of that second sale order will be 2 and so on …
- in short, each record is linked with an unique id and two records can not have same id, because its unique for each record into table of database
- Active Id in odoo is nothing but id of a current record
- for example you have created a sale order named SO029 and id of SO029 is 30 ,
So if SO029 is opened at that time in odoo active id is 30
- look at below screen to understand it better
- id can be found in URL if record is opened, for example in above image SO29 is opened so odoo will consider 30 as active id.
- if you select multiple records from the list view at that time ids of all the records are known as active_ids as you have list of ids.
- see below image here multiple sale orders are selected
- So there is a little difference between active_id and active_ids in odoo
- active_id : it represent single current record which is opened on odoo screen so the id of that record is active_id
- active_ids : it represent multiple record which can be selected through the list view of odoo and its returns list of ids/records called as as active_ids
- as a odoo developer you have to often play with ids, because from id of the record you can access all the information about that record
- So lets learn how to find active_ids and browser that active_ids into particular model
active_ids = self._context.get('active_ids')
sale_order_ids = self.env['sale.order'].browse(active_ids)
- in step 1 it will give you active_ids, now you will think in first step we got the active_ids so what is the need of step 2
- because in step 1 it will give active_ids as integers, and as a developer you can’t do anything with that
- so you need to browse that active_ids into particular model like ‘sale.order’, ‘purchase.order’ etc
- with step 2 you will get accurate results
- after step 2 you have a link to specific record, so you can access all the data of particular record
GET IN TOUCH.!
We’d Love to Hear from You! We are happy to answer any questions, you have regarding My Training.
Mail : firstname.lastname@example.org
Skype : mayur_maheshwari1
What’s app : +919924542042