Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
3484 Zobrazení

All the line generated are in one line and even though I used \n \t 

Here's the code:

        rows = cur.fetchall()

        file.write("emp id,bank account id,salary\n")

        rows_count = 0

        total_salary = 0

        for row in rows:

            file.write('"%s\t",' % row[0])

            file.write("%s\t," % row[1])

            file.write("%s\n" % row[2])

            rows_count += 1

            total_salary += row[2]

        file.write("Total Accounts,")

        file.write("%s\t" % rows_count)

        file.write("Total Salary,")

        file.write("%s\t" % total_salary)


with open(name, 'r') as f_read:

            file_data = f_read.read()

            print 'file_data', file_data  #here the output is right, there is new line created

        values = {

            'name': name,

            'datas_fname': name,

            'res_model': 'ir.ui.view',

            'res_id': False,

            'type': 'binary',

            'public': True,

            'datas': file_data.encode('utf8').encode('base64'),  #Is the problem in here? 

        }

        attachment_id = self.env['ir.attachment'].sudo().create(values)

        # Prepare your download URL

        download_url = '/web/content/' + str(attachment_id.id) + '?download=True'

        base_url = self.env['ir.config_parameter'].get_param('web.base.url')

        return {

            "type": "ir.actions.act_url",

            "url": str(base_url) + str(download_url),

            "target": "new",

        }


What should I do to make the added data in the loop is in new line?

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
0
zář 17
5194
6
zář 22
66850
4
čvn 20
6386
0
led 24
8488
0
čvn 23
2742