2
votes

I have this field below

name = fields.Text("Input text here")

And I want to pass its value to the wizard when I click a button. Here's the code:

@api.multi
def open_wizard(self):
return {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'customer.wizard',
'target': 'new',
'type': 'ir.actions.act_window',
'context': {'current_id': self.id}
 }

And here is my XML. But it still didn't work as I expected.

For the button:

<button name="open_wizard" string="Submit" type="object" class="oe_highlight" context="
{'name': name}"/>

For the wizard itself. I want the value to be on the 'Resi' field:

<record id="view_test_report_wizard" model="ir.ui.view">
 <field name="name">Customer Wizard</field>
 <field name="model">customer.wizard</field>
 <field name="arch" type="xml">
 <form string="Choose The Details">
 <group>
 <tree>
 <group>
 <field string="Resi" name="name" context="{'name' : name}"/>
 <field name="tanggal"/>
 <field name="kotaasal"/>
 <field name="kotatujuan"/>
 <field name="id_customer"/>
 </group>
 </tree>
 </group>
 <footer>
 <button string="Back" class="oe_link" special="cancel"/>
 </footer>
</form>
</field>
</record>

Do you have any solution? Thank you

2

2 Answers

2
votes

you can try this way

wiz = self.env['customer.wizard'].create({'name': self.name})

@api.multi
def open_wizard(self):
return {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'customer.wizard',
'res_id': wiz.id,
'target': 'new',
'type': 'ir.actions.act_window',
}

or you can pass the value in the context

'context': {
   'default_name': self.name,'default_tanggal': self.tanggal
   'default_kotaasal': self.kotaasal,'default_kotatujuan': self.kotatujuan
   ,'default_id_customer': self.id_customer.id
}
1
votes

Just update the context on method open_wizard like the following:

'context': {'default_name': self.name}

That will (virtually) create the wizard with the value of self.name.