Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
7995 Näkymät

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?

Avatar
Hylkää
Paras vastaus

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.

Avatar
Hylkää
Tekijä

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.

Tekijä

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.

Tekijä

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

Tekijä Paras vastaus

Hi, Ben.

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

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
6
jouluk. 22
9655
2
heinäk. 21
9937
1
maalisk. 20
13591
4
jouluk. 23
24213
0
heinäk. 25
11133