跳至內容
選單
此問題已被標幟
3 回覆
4101 瀏覽次數

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.

頭像
捨棄
作者 最佳答案

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.
頭像
捨棄
最佳答案

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

頭像
捨棄
作者

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.

最佳答案

HI, you can follow following tutorial for this:

https://youtu.be/kwkddYoFQCE

Hope it helps,

Thanks

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
0
1月 21
2060
0
1月 23
1661
1
8月 19
3989
1
12月 22
4931
2
3月 21
3371