Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

python - How to pass context from wizard to view. Odoo 13

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',
    }
question from:https://stackoverflow.com/questions/65903659/how-to-pass-context-from-wizard-to-view-odoo-13

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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},

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...