Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
17589 Visualizzazioni

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 ?


Avatar
Abbandona
Risposta migliore

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

Avatar
Abbandona
Risposta migliore

Please correct this line.

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

Avatar
Abbandona