简体   繁体   中英

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:

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

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

res['product_template_ids'] = [(6, 0, self.env.context.get('active_ids', False))]

and if it's giving ID ie 23 then use:

blank_list = []
blank_list.append(self.env.context.get('active_ids', False))
res['product_template_ids'] = [(6, 0, blank_list)]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM