Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
1872 Vistas

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
Descartar
Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
5
ene 20
4305
3
jul 25
22052
0
sept 23
144
2
ene 24
16173
3
dic 17
11726