跳至內容
選單
此問題已被標幟
5 回覆
35278 瀏覽次數

I'm working with Odoo 10.

I'm calling a wizard from python code and want to populate a field in the wizard with a value, calculated in the method before calling the wizard.

The wizard is opening, but the field is empty.

How do I populate a field in a wizard with a value from context?

Code from wizard calling method:

return {    
    'name': _("Ordner erstellen"),
    'type': 'ir.actions.act_window',
    'view_type': 'form',
    'view_mode': 'form',
    'res_model': 'gilligkeller.crm.create_folder',
    'view_id': viewid,
    'target': 'new',
    'context': {'src_path': src_path, 'dst_path': dst_path}
}


Code from wizard.py:

class create_folder(models.TransientModel):    
    _name = 'gilligkeller.crm.create_folder'
   
    dst_path = fields.Char(string='Zielpfad')
   
    @api.model
    def default_get():
        


I tried using the default_get() methon in my wizard but couldn't get it working.

頭像
捨棄

'context': {'default_dst_path': dst_path}

default key is essential.

最佳答案

You need to pass 'default_' prefix in context with field name.

Ex:

'context': {'default_src_path': src_path, 'default_dst_path': dst_path}

This will set the default value when wizard will open.

頭像
捨棄
最佳答案

Hi,

Update the line like this,

    'context': {'default_dst_path': dst_path}


Thanks

頭像
捨棄
最佳答案

this may help you to understand  more how to pass values using context in wizard
     Explanation from  '" odoo development Cookbook "'

Using the context to compute default values
There is a feature of the web client we can use to save some typing. When an action is
executed, the context is updated with some values that can be used by wizards:

active_model  : This is the name of the model related to the action. This is generally the
model being displayed on screen   

active_id : This indicates that a single record is active, and provides the ID of that
record

active_ids : If several records were selected, this will be a list with the IDs (this
happens when several items are selected in a tree view when the action
is triggered. In a form view, you get [active_id])

active_domain : An additional domain on which the wizard will operate

These values can be used to compute default values of the model, or even directly in the
method called by the button

頭像
捨棄
作者 最佳答案

That was too easy, thank you :)

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
10月 23
5551
0
8月 17
3476
0
11月 17
3773
2
10月 23
6446
2
1月 23
2528