Search code examples
odooodoo-14

Get the id of the current view in Odoo


Suppose we have a model named 'repertoire' with a field Many2many 'documents_id' enter image description here

and i have a button in the many2many tree view ,in that button i want to get the id of the 'repertoire' i'm in is there any solution for this


Solution

  • I found the answer ,we can pass a context to the many2many field ,for example :

    <field name="app_ids" string="Apps" context="{'current_instance_id': id}">
                      <tree editable="false" create="false" delete="true">
                        <field name="name"/>
                          <button type="object" name="updating_module" icon="fa-refresh"/>
    
                      </tree>
                    </field>
    

    on my function i can retrieve it :

    def updating_module(self):
        instance_id = self.env.context.get('current_instance_id')