如何在odoo中的onchange方法中传递列表值,以列出attrubite

时间:2019-04-01 11:31:27

标签: odoo-12

请给我这个Python类:

class class4(models.Model):
    _inherit = 'sale.order.line'
    categorie = fields.Many2one('module.categorie')
    list1 = []
    # item = fields.Many2one('module.item', domain=[('id','=',[1,2])])
    item = fields.Many2one('module.item', domain=[('id','=',list1)])
    items = fields.Char()

    @api.onchange('categorie')
    def onchange_method(self):
        print(self.categorie.name,'changed !')
        res = {}
        items_list = []
        self.list1 = []
        records = self.env['module.categorieitem'].search([('name','=',self.categorie.id)])
        # for record in records:
        #     print(record.item.name)
        #     items_list.append(record.item.name)
        for record in records:
            print(record.item.id)
            items_list.append(record.item.id)
        self.items = items_list
        self.list1 = items_list
        print('list1: ',self.list1)
        res['domain'] = {'item': [('id', 'in', items_list)]}
        return res

如何设置list1 = items_list的值并将其传递到domain属性中,以便在刷新页面而不是按变更方法时保持对项的过滤器

0 个答案:

没有答案