コンテンツへスキップ
メニュー
この質問にフラグが付けられました
3 返信
11713 ビュー

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?

アバター
破棄
最善の回答

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.

著作者 最善の回答

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.

アバター
破棄
最善の回答

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.

著作者

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

著作者

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

関連投稿 返信 ビュー 活動
0
3月 15
4394
0
7月 25
11104
1
6月 22
17051
1
3月 15
12087
0
3月 15
4027