Leon Nguyen
Leon Nguyen

Reputation: 197

How to pass value from field to a wizard in Odoo 13?

Im using two models for two form views. I have this field below with model 1

name = fields.Many2one('hr.employee', string="USERNAME", required=True)

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

def create_field(self):

   return {
       'name': self.name,
       'view_mode': 'form',
       'res_model': 'dieu.chinh',
       'view_id': False,
       'res_id': wiz.id,
       'res_id' : self.id,
       'context': {'current_id': self.id},
       'target': 'current',
       'type': 'ir.actions.act_window',
   }

The button in XML file:

button type="object" string="SUBMIT" name= "create_field" class="oe_highlight"/>

After clicking the button, it can open the expected form view with model 2, but still not show the value which was selected in the previous form.

So... How to pass value from field to a wizard in Odoo 13?

Please help!

Thank you!

Upvotes: 0

Views: 2177

Answers (1)

kamalpreet
kamalpreet

Reputation: 101

Try this:

 def create_field(self):
    form_view = self.env.ref("your_wizard_form_view_external_id")
    
    return{
       'name': 'Wizard Name',
       'views': [
            (form_view.id, 'form'),
            ],
       'res_model': 'dieu.chinh',
       'target': 'new',
       'type': 'ir.actions.act_window',
       'context': {
             'default_wizard_field_name': self.name.id,  # for passing Many2One field context value in Wizard form view
            },
       }

'default_wizard_field_name': self.name.name # for passing Char field context value in Wizard form view

Upvotes: 2

Related Questions