Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
2026 Vues

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
Ignorer
Meilleure réponse

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
Ignorer
Publications associées Réponses Vues Activité
5
janv. 20
4489
3
juil. 25
22271
0
sept. 23
144
2
janv. 24
16399
3
déc. 17
11990