Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
11692 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Penulis

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.

Penulis Jawaban Terbai

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
Buang
Jawaban Terbai

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
Buang
Penulis

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

Penulis

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

Penulis

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

Post Terkait Replies Tampilan Aktivitas
0
Mar 15
4388
0
Jul 25
11084
1
Jun 22
17029
1
Mar 15
12062
0
Mar 15
4019