Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to use a button to show a form to edit data?

By
Ratmil Torres
on 8/27/14, 8:51 AM 947 views

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?

0
Ratmil Torres
On 8/28/14, 9:10 AM

Hi, Ben.

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

0
Ben Olsen
On 8/27/14, 11:23 AM

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.

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.

Ratmil Torres
on 8/27/14, 11:57 AM

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.

Ben Olsen
on 8/27/14, 1:54 PM

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.

Ratmil Torres
on 8/27/14, 2:03 PM

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

Ratmil Torres
on 8/27/14, 2:04 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 8/27/14, 8:51 AM
Seen: 947 times
Last updated: 3/16/15, 8:10 AM