[英]How to get current record id in wizard. Odoo14
我在模型“product.template”的操作中添加了一个向导,我想在向导中获取“active_ids”,我尝试使用以下代码:
class Wizard(models.TransientModel):
_name = "product.wizard"
product_template_ids = fields.Many2many('product.template')
@api.model
def default_get(self, fields):
res = super(Wizard, self).default_get(fields)
res['product_template_ids'] = self.env.context.get('active_ids', False)
return res
但是,我收到了这个错误:raise exception.with_traceback(None) from new_cause TypeError: 'int' object is not subscriptable
怎么了 ? 请问有什么帮助吗?
谢谢。
试试这个:
首先检查你用这个 self.env.context.get('active_ids', False) 得到了什么,如果它在列表中给出了 id,即 [23] 然后使用 many2many 填充操作即
res['product_template_ids'] = [(6, 0, self.env.context.get('active_ids', False))]
如果它给出 ID 即 23 然后使用:
blank_list = []
blank_list.append(self.env.context.get('active_ids', False))
res['product_template_ids'] = [(6, 0, blank_list)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.