Help

3

Run a wizard from python code or as a return of a function

Avatar
Jose F

I need run a wizard from python code or as a return of a python function. I need that when finish a production order skip automatically one wizard but does nothing, only print the wizard_id. Any idea? It's possible?

class mrp_production_workcenter_line(osv.osv):

    _inherit = 'mrp.production.workcenter.line'

    def show_wizard(self, cr, uid, ids):

        qc_id = self.pool.get('mrp.production.workcenter.line').browse(cr,uid,ids[0]).qc_id.id
        context={
                 'qc_id':qc_id,
                 'operation_id':ids[0]
                 }       
        wizard_id = self.pool.get("kms.qc.name.wiz").create(cr,uid,{}, context=dict(context, active_ids=ids))

        print 'wizard_id : ', wizard_id

        return {
            'name':_("Quality Control"),
            'view_mode': 'form',
            'view_type': 'form',
            'view_id': False,
            #'model': 'kms.qc.name.wiz',
            'res_model': 'kms.qc.name.wiz',
            'res_id':wizard_id,
            'type': 'ir.actions.act_window',
            'nodestroy': True,
            'target': 'new',
            'domain': '[]',
            'context': dict(context, active_ids=ids)
        }


    def action_done(self, cr, uid, ids):
        """ Sets state to done, writes finish date and calculates delay.
        @return: True
        """
        super(mrp_production_workcenter_line,self).action_done(cr, uid, ids)
        return self.show_wizard(cr,uid,ids)


mrp_production_workcenter_line()
1 Comment
Avatar
Discard
Avatar
Anabela Damas
-

Did you find the answer?

3 Answers
6
Avatar
Parth Gajjar
Best Answer

Do this with Proper Return

  #first fatch wizard view id 
  dummy, view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'your_model', 'your_wizard_view_id') #in model name replace . with _ Example sale.order become sale_order


  return {
        'name':_("Display Name"),#Name You want to display on wizard
        'view_mode': 'form',
        'view_id': view_id
        'view_type': 'form',
        'res_model': 'object name',# With . Example sale.order
        'type': 'ir.actions.act_window',
        'target': 'new',
        'domain': '[if you need]',
        'context': {'if you need'}
    }

Hope this will help

2 Comments
Avatar
Discard
Avatar
Jose F
-

Thanks but does nothing. If I put a button on the tree of mrp -> mrp.production.workcenter.line.tree and I pass in the context the qc_id and click them, the wizard displays correctly but I can't get it to display automatically when the operation switches to "done". I don't understand why not it show and no show any error.

Avatar
Voathnak Lim
-

can you post the view in xml please!

0
Avatar
Omar OUHARI
Best Answer

It's possible to return a wizard in create method.

@api.model

def create(self, vals):

   if condition:

        return action_wizard


Thanks.

Avatar
Discard
0
Avatar
Jose F
Best Answer

Thanks but does nothing. If I put a button on the tree of mrp -> mrp.production.workcenter.line.tree and I pass in the context the qc_id and click them, the wizard displays correctly but I can't get it to display automatically when the operation switches to "done". I don't understand why not it show and no show any error.

Avatar
Discard