Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
4363 Widoki

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.

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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.
Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
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.

Najlepsza odpowiedź

HI, you can follow following tutorial for this:

https://youtu.be/kwkddYoFQCE

Hope it helps,

Thanks

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
sty 21
2269
0
sty 23
1948
1
sie 19
4190
1
gru 22
5148
2
mar 21
3578