How to get a return value from a wizard?

Asked by Martin Collins

I'm trying to port an old-style wizard to osv_memory in 6.0 so I can use yaml tests on it.
I find I have to create a wizard just to have a Yes/No dialog. But how do I get the yes/no result?
I successfully get the wizard to pop-up from my main wizard but the main wizard carries on without waiting.
Here's (one version of) my dialog:

class verify_ticket(osv.osv_memory):
    _name = 'citrus.verify.ticket'
    _description = 'Verify Ticket'

    _columns = {'result': fields.char('Result', size=4)}

    def button_accept_ticket(self, cr, uid, ids, context={}):
        context['result'] = 'pass'
        return {'context': context}

    def button_reject_ticket(self, cr, uid, ids, context={}):
        context['result'] = 'fail'
        return {'context': context}

verify_ticket()

And I call it via this function:

    def _verify(self, cr, uid, ids, context={}):
        # call a new wizard to let the user decide
        context['active_ids'] = ids
        context['default_result'] = 'fail'
        wizard_id = self.pool.get("citrus.verify.ticket").create(cr, uid, {}, context)
        return {'name': "Verify Ticket",
                'type': 'ir.actions.act_window',
                'res_model': 'citrus.verify.ticket',
                'res_id': wizard_id,
                'view_id': False,
                'view_type': 'form',
                'view_mode': 'form',
                'nodestroy': True, # don't dump the original wizard
                'target': 'new', # open the new one as a popup
                'domain': '[]',
                'context': context,
               }

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Martin Collins
Solved:
Last query:
Last reply:
Revision history for this message
Numérigraphe (numerigraphe) said :
#1

Attention: your wizard cannot return anything to _verify.
Actually the client calls verify(), which returns an action to the
client. Then the client executes the action (i.e. opens the wizard
popup). When you press a button the client calls the button_...()
method, which returns something to the client.
So probably your button_...() functions should do more. I don't see what
an openerp client can do with only a context.
Either they have to change some data (write(), create()...), or they
have to return an action that the client can execute (open a view, print
a report ...)
Does it help?
Lionel Sausin.

Revision history for this message
Martin Collins (mkc-steadfast) said :
#2

Um, not much. I want to affect some internal state (ie. not in the _columns) by user interaction. Maybe I'll have to rejig things and put all state in the _columns. That's going to be inconvenient.
Is there a good example of a multi-wizard osv_memory object anywhere?

Revision history for this message
Serpent Consulting Services (serpent-consulting-services) said :
#3

Martin,

Did you mean you want 'YES' and 'NO' button on your wizard and based on the click you need to read the response?

I prefer you add two buttons which call the same method _verify.
On both the buttons, you can pass different context and based on the context you can proceed into _verify.

Hope this helps.

Thanks.

Revision history for this message
Martin Collins (mkc-steadfast) said :
#4

I didn't see your response until just now, when I came back to post my solution which is a little different.
I only need the 'YES' or 'NO' buttons sometimes, so they should pop up.
You have to call (if that's the right word) wizards from top-level functions, apparently.
I have added a function to my main wizard, which I call from the button functions on my sub-wizard passing 'pass' or 'fail' as a parameter. This function then proceeds accordingly.
So my main wizard has:

def button_validate(self, cr, uid, ids, context={}):
        result = self._check_schedule(cr, uid, ids, context)
        if result == 'verify':
            return self._verify(cr, uid, ids, context) # pop-up the 'YES' or 'NO' wizard
        return True

and the new function:

def do_result(self, cr, uid, ids, result):
        if result == 'pass':
            self._accept_ticket(cr, uid, ids, context)
        return True

and my 'YES' or 'NO' sub-wizard looks like this:

class verify_ticket(osv.osv_memory):
    _name = 'citrus.verify.ticket'
    _description = 'Verify Ticket'

    def return_value(self, cr, uid, ids, value):
        st_obj = self.pool.get('citrus.scan.tickets')
        st = st_obj.browse(cr, uid, ids)[0]
        st.do_result(value)
        return True

    def button_accept_ticket(self, cr, uid, ids, context={}):
        self.return_value(cr, uid, ids, 'pass')
        return {'type': 'ir.actions.act_window_close'}

    def button_reject_ticket(self, cr, uid, ids, context={}):
        self.return_value(cr, uid, ids, 'fail')
        return {'type': 'ir.actions.act_window_close'}

Seems to work OK. It's not what I would call obvious but it shouldn't have been such a struggle either.
Thanks guys for your hints.