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 include a button in editable treeview cell to show an edit form on the current record?

By
Ratmil Torres
on 8/26/14, 10:31 AM 2,748 views

I have a editable tree view with 3 fields of a model. I would like to add a button to show a form to edit the rests of the fields of the model. How can I do it?

0
Ratmil Torres
On 8/26/14, 2:43 PM

Hi.

Thanks for your answer but this just shows a form with no empty values in fields and no save (nor cancel) button. I need the form to edit the current record.

Do I need to set some value in context dictionary.

0
Ben Olsen
On 8/26/14, 3:42 PM

You can add a button, as Yogesh said, but you'll want to make it type object. This will link to a function in the tree's model class, and this function can return a new view. For example, in the xml:

<button name="button_details" string="Details" type="object"/>

Then in the class definition for this model:

    @api.multi
    def button_details(self):
        view = {
            'name': _('Details'),
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'my.custom.model',
            'view_id': False,
            'type': 'ir.actions.act_window',
            'target': 'new',
            'readonly': True,
            'res_id': self.id,
        }
        return view

Make sure to replace 'my.custom.model' with the actual model you want to edit. Also, you'll need to have already definied the ir.actions.act_window and ir.ui.view records for that model, or Odoo won't know how to bring up the details. That top line there is from the new v8 api, but if you're using v7, remove it and just add the standard args to the button_details function call (cr, uid, ids, context). There are lots of examples of button functions in the code, I'm sure you can find one. The key to the button bringing up a new modal window is the line :

'target': 'new',

This will make the details edit be its own little popup window. Alternativly, you can set target to 'current' to just redirect to that page normally, but I'm going to guess in this instance you'd rather a little popup and then return to the main view.

 

EDIT: Oops, I forgot that the "'res_id': self.id," line is very important, and I think it only works with the v8 API. If you're using v7, instead of "self.id", you'll probably want the "ids" arg passed in from the function arguments. I hope that makes sense.

Hi, Ben. Thanks a lot. I haven´t test yet but that looks like the solution.

Ratmil Torres
on 8/26/14, 4:06 PM

Doesn´t this method should return something like {'domain': {'field':'domain'}, 'value' : 'field2': 'text'}?

Ratmil Torres
on 8/26/14, 4:16 PM

Well, I guess it works in v8, but in OpenERP 7 parameter 'res_id' must be something else.

Ratmil Torres
on 8/26/14, 4:30 PM
0
Yogesh
On 8/26/14, 10:35 AM

You can add a button on tree and pass action of that form in name. like :


<button name="%(action_id_of_form_you_want_to_open)d"  type="action" string="Open Form"/>
 

Hi. Thanks for your answer but this just shows a form with no empty values in fields and no save (nor cancel) button. I need the form to edit the current record. Do I need to set some value in context dictionary.

Ratmil Torres
on 8/26/14, 2:49 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/26/14, 10:31 AM
Seen: 2748 times
Last updated: 3/16/15, 8:10 AM