跳至內容
選單
此問題已被標幟
2 回覆
17599 瀏覽次數

When i run my code i got the error 'AttributeError: 'list' object has no attribute 'get''

    @api.onchange('custom_product_category_ids')

    def _get_selection(self):

        values = []

        prod_categ_ids = self.env['custom.product.category'].search([['id','=', self.custom_product_category_ids.id],])

        print(prod_categ_ids)

        for product_categ in prod_categ_ids:

            print(product_categ.id)

            print('pass')

            product_obj = self.env['custom.product.category'].browse(product_categ.id)

            values.append([str(product_obj.id), str(product_obj.categ_name)])

            print(values)

        return values



What is the problem ?


頭像
捨棄
最佳答案

Hi,

Please update this line

prod_categ_ids = self.env['custom.product.category'].search([['id','=', self.custom_product_category_ids.id],])

to

prod_categ_ids = self.env['custom.product.category'].search([('id', '=', self.custom_product_category_ids.id)])


and see whether it solves the issue or not.


Thanks

頭像
捨棄
最佳答案

Please correct this line.

prod_categ_ids = self.env['custom.product.category'].search([('id', '=', self.custom_product_category_ids.id)])

頭像
捨棄