How to pass context from wizard to view. Odoo 13

Viewed 1183

In the wizard I added a field product_id, and button. When choosing the product and clicking on button I want to get the stock.quant tree view of the product. How to pass value in context ?

class Wizard(models.TransientModel):
    _name = 'wizard.wizard'

product_id = fields.Many2one('product.product', string="Product")

 @api.model
 def my_button(self):
    return {
        'name': _('Products'),
        'view_type': 'tree',
        'view_mode': 'list',
        'res_model': 'stock.quant',
        'context': {},
        'type': 'ir.actions.act_window',
        'target': 'new',
    }
1 Answers

self represent current recordset. We can pass value with self.product_id

For example:

"context": {"default_product_id": self.product_id.id, 
            "search_default_product_id": self.product_id.id},
Related