Skip to Content
Menu
This question has been flagged
2535 Views

Hi,

I want import public_categ_id contaning camma character in product.template from csv file?

but my code not working.

please hekp me, thanks.


    file = fields.Binary('File to import'required=True)

    @api.multi
    def import_file(self):

        file = StringIO.StringIO(base64.decodestring(self.file))
        reader = csv.reader(filedelimiter=',')
        csv.field_size_limit(sys.maxsize)
        skip_header = True
        for row in reader:
            if skip_header:
                skip_header = False
                continue
            product = row[0]
            public_categ_ids = row[1]
            product_obj = self.env['product.template']
            product_id = product_obj.search([('id''=', product)])
            product_public_obj = self.env['product.public.category']
            public_categ_id = product_public_obj.search([('id''=', public_categ_ids)])

            if product_id and public_categ_id:
                product_id.write('public_categ_ids':  (60, [list of public_categ_ids]),)
            elif not product_id :
                raise Warning("Could not find the product '%s'" % product)
Avatar
Discard