Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
3 Risposte
11747 Visualizzazioni

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?

Avatar
Abbandona
Risposta migliore

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"/>
 

Avatar
Abbandona
Autore

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.

Autore Risposta migliore

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.

Avatar
Abbandona
Risposta migliore

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.

Avatar
Abbandona
Autore

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

Autore

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

Autore

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

Post correlati Risposte Visualizzazioni Attività
0
mar 15
4404
0
lug 25
11126
1
giu 22
17073
1
mar 15
12114
0
mar 15
4036