[英]How to get current record id in wizard. Odoo14
I added a wizard in action of model 'product.template', I want to get 'active_ids' in wizard, I trying with this code:我在模型“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
But , I got this error : raise exception.with_traceback(None) from new_cause TypeError: 'int' object is not subscriptable但是,我收到了这个错误:raise exception.with_traceback(None) from new_cause TypeError: 'int' object is not subscriptable
What's wrong ?怎么了 ? Any help please?
请问有什么帮助吗?
Thanks.谢谢。
Try this:试试这个:
First check what you are getting with this self.env.context.get('active_ids', False), if it gives id inside list ie [23] then use many2many filling operation ie首先检查你用这个 self.env.context.get('active_ids', False) 得到了什么,如果它在列表中给出了 id,即 [23] 然后使用 many2many 填充操作即
res['product_template_ids'] = [(6, 0, self.env.context.get('active_ids', False))]
and if it's giving ID ie 23 then use:如果它给出 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.