Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
4347 Vistas

I have a tree/list view and I want to customize what form is opened when clicking on a record in the list. The record's each have a related record and each one may be from a different model. I know I can find and return the corresponding views dynamically through python but I am unsure of how to link this to the xml.


I have record 1 which has the fields res_model=mrp.production and res_id=500.

I have record 2 which has the fields res_model=stock.picking and res_id=125.


Both record 1 and 2 appear in my list view but I would like it to open the default form of their respective res_model when I click on them in the list view.

Avatar
Descartar
Autor Mejor respuesta

I ended up creating a button in the list view that ran the following action.

def action_open_record(self):
        """
            Return the form view for the related record.
        """
        self.ensure_one()
        return {
            "type": "ir.actions.act_window",
            "res_model": self.res_model,
            "view_type": "form",
            "view_mode": "form",
            "res_id": self.res_id,
            "target": "current",
        }

This will open the form view for the related record no matter what model it is from, while it isn't as clean as opening the form directly from the list view it is a little bit more dynamic and can easily be added to multiple views.
Avatar
Descartar
Mejor respuesta

Hello,

it may not be the best solution but I will create a 3rd field which would correspond to the reconstituted url. Then I would put the URL field in the list as a widget: 

<field name = "file_path" widget = "url" />

Hope this can be useful to you

Avatar
Descartar
Autor

Thanks for the answer Christophe! This is an interesting approach and I actually ended up going with something similar to this but as a button instead of a field. I will put the code in an answer in case anyone is interested.

Mejor respuesta

HI, you can follow following tutorial for this:

https://youtu.be/kwkddYoFQCE

Hope it helps,

Thanks

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
0
ene 21
2263
0
ene 23
1914
1
ago 19
4189
1
dic 22
5143
2
mar 21
3570