콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
5 답글
35302 화면

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
5552
0
8월 17
3490
0
11월 17
3784
2
10월 23
6461
2
1월 23
2530