Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
7988 Lượt xem

I have inserted a button as a cell in a tree view for my model. When the button is clicked it is suppose to pop up a form to edit the current record, the record is in the same row where the button is.

This is the code to handle the clicking of the button:

-----------------------------

def open_details(self, cr, uid, ids, context=None):
        view = {
            'name': _('Details'),
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'my.model',
            'view_id': False,
            'type': 'ir.actions.act_window',
            'target': 'new',
            'readonly': True,
            'res_id': ids[0],
        }
        return view

--------------------------------

It is not working. The form is shown but no data is loaded, and there isn´t either save or cancel button.

What is wrong in this code?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hey Ratmil, looks like I wasn't careful enough when copy-and-pasting my previous answer. Note that one of the options in that view you're creating is:

'readonly': True,

Obviously if the form is readonly it won't have save/cancel buttons. Sorry about that.

As for the data not loading, the rest of it looks right to me. Maybe the "ids" arg isn't getting passed in? Right before the "view = {" line, I'd put in a "print(ids)" and check the output when you load that page. If "ids" isn't getting passed in correctly, that's definitely a problem. And are you sure you're replacing "my.model" with the actual model name that you want to edit? Let us know what the output of print(ids) is and maybe we can help from there.

Ảnh đại diện
Huỷ bỏ
Tác giả

Hi, Ben. Thanks again for your response. I printed the ids var and I got [86]. In any case, a list with one item that is the id of record to edit. I set readonly to false ('readonly':False) and same result came out. Yes, by 'my.model' I mean the full name of my model. Actually I get the right form. The only problem is that field values are not loaded. And there are no save nor cancel button.

Well that's very curious. That is a good value for ids, so "'res_id': ids[0]" should work. I'm doing this exact thing in one of my modules and it works fine. Sorry I can't be more help.

Tác giả

Hi, Ben. Well, I was defining my own view for editing the module. So, I removed this view definition and let OpenERP create the form view it self. And now data is loaded correctly. The only issue is that save button is not showing. Thank you very much for your help.

Tác giả

Anyway, your solution is perfect, but I guess I just have a different problem in my code. Thanks again.

Tác giả Câu trả lời hay nhất

Hi, Ben.

It all works fine except for the missing "save" and "discard" buttons.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
6
thg 12 22
9640
2
thg 7 21
9927
1
thg 3 20
13576
4
thg 12 23
24213
0
thg 7 25
11122