İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
7482 Görünümler

How to get wizard id in onchange method? Do you know some trick to do this? I searched for examples in standard modules but without answer.

class some_wizard(osv.osv_memory):    
     _columns = {
        'some_string': fields.char('Some string', size=256),
    }

def default_get(self, cr, uid, fields, context=None):
    ret = super(some_wizard,self).default_get(cr, uid, fields, context=context)
    print 'default_get', ret, context
    # 'default_get'
    # ret: []
    # context: {'lang': 'en_US', 'tz': 'Europe/Brussels', 'uid': 1}
    return ret

def onchange_some_string(self, cr, uid, ids, some_string=None, context=None):
    print ids, context
    # context : {'lang': 'en_US', 'tz': 'Europe/Brussels', 'uid': 1}
    # ids: []
    return {}

<record id="" model="ir.ui.view">
            <field name="name"></field>
            <field name="model"></field>
            <field name="arch" type="xml">
                <form string="some_string" version="7.0">
                    <group>
                        <field name="some_string" on_change="onchange_some_string(some_string,context)" />
                    </group>
                    <footer>
                        or
                        <button string="Cancel" class="oe_link" special="cancel" />
                    </footer>
                </form>
            </field>
        </record>
Avatar
Vazgeç
En İyi Yanıt

You can't get the wizard ID from an onchange event if the wizard record doesn't exist yet. The wizard won't exist in the database until you click a button, either to complete the wizard or move to the next screen.

The trick to get around this issue is to create the wizard record before opening the view for it. To do that, use an object button instead of an action button and create a function that generates the wizard record and returns a dictionary action to open it on that newly created id. For your view XML, just:

<button type="object" string="Start Wizard" name="start_wizard"/>

The function in your source object (not the wizard object)

def start_wizard(self, cr, uid, ids, context=None):
    if context is None: context = {}
    active_rec = self.browse(cr, uid, ids[0])
    # Pass in any values here that you want to be pre-defined on the wizard popup
    values = {}
    wizard_id = self.pool['some.wizard'].create(cr, uid, values)
    return {
        'name': 'Some Wizard',
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'some.wizard',
        'res_id': wizard_id,
        'type': 'ir.actions.act_window',
        'target': 'new',
        'context': context,
    }

When you get to the onchange function in the wizard, you'll be able to use the id.

Avatar
Vazgeç
Üretici

Thanks for fast answer. It solves a problem.

İlgili Gönderiler Cevaplar Görünümler Aktivite
3
Kas 17
20790
4
Ağu 20
18193
0
Ara 15
3845
1
Ara 22
3382
What is wizard ? Çözüldü
3
Kas 23
32439