首页 > 解决方案 > 如何将上下文从向导传递到视图。奥多 13

问题描述

在向导中,我添加了一个字段product_id和按钮。选择产品并单击按钮时,我想获得stock.quant产品的树形视图。如何在上下文中传递价值?

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

标签: pythonxmlodoo

解决方案


self表示当前记录集。我们可以通过self.product_id

例如:

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

推荐阅读