Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
3648 Ansichten

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
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
0
Sept. 17
5383
6
Sept. 22
67306
4
Juni 20
6547
0
Jan. 24
8652
0
Juni 23
2922