【问题标题】:How to get current record id in wizard. Odoo14如何在向导中获取当前记录 ID。 Odoo14
【发布时间】:2021-06-18 09:55:08
【问题描述】:

我在模型“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' 对象不可下标

怎么了?有什么帮助吗?

谢谢。

【问题讨论】:

    标签: javascript python xml odoo


    【解决方案1】:

    试试这个:

    首先检查你用这个 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)]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-17
      • 2020-04-14
      • 2012-06-24
      • 2011-08-08
      • 1970-01-01
      • 2015-08-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多