Skip to Content
Menu
This question has been flagged
1 Reply
1861 Views

Hi, i need to ask a question. We have a one2many field with name 'line_ids' in this form view.


When i click any record in this one2many field this form view appear. I need the access 'id' of record which i clicked in one2many field. I thought it will be in the context but apparently its not. active id and other params is related with main form view.

Any idea how can i get the id ?

Avatar
Discard
Best Answer

Hi,

Use default_ context or pass the ID manually:

Access the One2many line's id directly in the form view:

When a record is opened in its form view , the record is passed by its own id , so you can access self.id directly in Python code (in the model or a form method).


@api.model

def some_method(self):

    _logger.info("This record ID: %s", self.id


So in any method (eg, @api.onchange , @api.model , etc.) within the child model , self.id is the correct ID of the record being edited or viewed.


i hope it is use full

Avatar
Discard
Related Posts Replies Views Activity
5
Jan 20
4298
3
Jul 25
22033
0
Sep 23
144
2
Jan 24
16170
3
Dec 17
11718