This question has been flagged
5 Replies
30856 Views

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.

Avatar
Discard

'context': {'default_dst_path': dst_path}

default key is essential.

Best Answer

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.

Avatar
Discard
Best Answer

Hi,

Update the line like this,

    'context': {'default_dst_path': dst_path}


Thanks

Avatar
Discard
Best Answer

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

Avatar
Discard
Author Best Answer

That was too easy, thank you :)

Avatar
Discard