zl程序教程

您现在的位置是:首页 >  后端

当前栏目

odoo14 与 odoo13 多对多的赋值不同 Python TypeError:‘int‘ object is not subscriptable

Python not is 不同 object 赋值 int TypeError
2023-09-11 14:20:47 时间
@api.model
def default_get(self, field_names):
    try:
        defaults = super().default_get(field_names)
        act_ids = self.env.context['active_ids']
        getids=[]
        for item in act_ids:
            yp = self.env['dmssp.dmssp'].sudo().search([('id', '=', item), ('pzhr', '=', self.env.user.id)])
            if len(yp)>0:
                # print(len(yp))
                if yp.state == 'shq':
                    getids.append(item)
        if len(getids)>0:
            defaults['xs']=True
        defaults['jcxm_ids'] = getids
以上代码在13中没问题,在14中就出错了
Python TypeError:'int' object is not subscriptable
改下给值方式就可以了
@api.model
def default_get(self, fields):
    try:
        defaults = super().default_get(fields)
        print(defaults)
        act_ids = self.env.context['active_ids']
        print(act_ids)
        defaults['jcxm_ids'] = [(6, 0, act_ids)]
        return defaults
    except:
        raise UserError('选择有误,其它异常')