Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
4366 Vizualizări

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.

Imagine profil
Abandonează
Autor Cel mai bun răspuns

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.
Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
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.

Cel mai bun răspuns

HI, you can follow following tutorial for this:

https://youtu.be/kwkddYoFQCE

Hope it helps,

Thanks

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
0
ian. 21
2269
0
ian. 23
1948
1
aug. 19
4191
1
dec. 22
5149
2
mar. 21
3580