Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
5 Odpowiedzi
35294 Widoki

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.

Awatar
Odrzuć

'context': {'default_dst_path': dst_path}

default key is essential.

Najlepsza odpowiedź

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.

Awatar
Odrzuć
Najlepsza odpowiedź

Hi,

Update the line like this,

    'context': {'default_dst_path': dst_path}


Thanks

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Autor Najlepsza odpowiedź

That was too easy, thank you :)

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
paź 23
5551
0
sie 17
3486
0
lis 17
3775
2
paź 23
6447
2
sty 23
2529