0
votes

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!

1
Pass the value through the context in create_field. 'context': {'current_id': self.id, 'default_name': self.name},Kenly
Did you succeed to pass the value from the field to the wizard?Kenly
Hi Kenly. Thank you for your support. I'd tried with your code, but I got the error with hr.employee after clicking the button. The error like this: -->> psycopg2.DataError: invalid input syntax for integer: "hr.employee(20,)" LINE 1: ...te" FROM "hr_employee" WHERE "hr_employee".id IN ('hr.employ... ^Leon Nguyen
Check this answer it will help you, is work also in 13.0. stackoverflow.com/questions/62529650/…Dipen Shah
The name field is a Many2one field so try to pass its id like following:'context': {'current_id': self.id, 'default_name': self.name.id},Kenly

1 Answers

1
votes

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