This question has been flagged
3 Replies
3095 Views

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
Discard
Author Best Answer

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
Discard
Best Answer

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
Discard
Author

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.

Best Answer

HI, you can follow following tutorial for this:

https://youtu.be/kwkddYoFQCE

Hope it helps,

Thanks

Avatar
Discard