Odoo Help

2

0
1 Answer
0
Avatar

Ludo - 21South Netherlands

--Ludo - 21South--
2548
| 3 2 7
Zwijndrecht, Netherlands
--Ludo - 21South--

Developer

Ludo - 21South Netherlands
3/4/15, 10:40 AM

Odoo already contains a feature to export records to CSV files. When you select one or more records from a tree view, the "More" button should appear on the top of the screen containing the option "Export".

Perhaps you could use the method that is available from that functionality by simply calling it with your ids and fields to be exported. Would save you some time writing a new method for it. Furthermore, you would have at least some basic error-handling.

Not quite sure by heart where it is located though.

1 Comment
Michael Thomas United States
3/6/15, 3:24 PM

In addons\web\controllers\main I find this function. I'm just trying to seperate out what I need in my method from the functionality of the export csv view. Code: class CSVExport(ExportFormat, http.Controller): @http.route('/web/export/csv', type='http', auth="user") @serialize_exception def index(self, data, token): return self.base(data, token) @property def content_type(self): return 'text/csv;charset=utf8' def filename(self, base): return base + '.csv' def from_data(self, fields, rows): fp = StringIO() writer = csv.writer(fp, quoting=csv.QUOTE_ALL) writer.writerow([name.encode('utf-8') for name in fields]) for data in rows: row = [] for d in data: if isinstance(d, basestring): d = d.replace('\n',' ').replace('\t',' ') try: d = d.encode('utf-8') except UnicodeError: pass if d is False: d = None row.append(d) writer.writerow(row) fp.seek(0) data = fp.read() fp.close() return data

Ask a Question
Writer
Keep Informed
3 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now