Merge lp:~openerp-dev/openerp-web/trunk-export-excell-raw-mat into lp:openerp-web

Proposed by Martin Trigaux (OpenERP)
Status: Merged
Merged at revision: 3963
Proposed branch: lp:~openerp-dev/openerp-web/trunk-export-excell-raw-mat
Merge into: lp:openerp-web
Diff against target: 54 lines (+14/-4)
1 file modified
addons/web/controllers/main.py (+14/-4)
To merge this branch: bzr merge lp:~openerp-dev/openerp-web/trunk-export-excell-raw-mat
Reviewer Review Type Date Requested Status
OpenERP R&D Web Team Pending
Review via email: mp+213605@code.launchpad.net

Description of the change

Require first to merge lp:~openerp-dev/openobject-server/trunk-export-excell-raw-mat

Allow excel export to use raw data instead of all string. Numbers and dates will be considered as such by the program.

To post a comment you must log in.
3963. By Martin Trigaux (OpenERP)

[FIX] default is False, style format is different than DEFAULT_SERVER_DATE{TIME}_FORMAT, datetime is instance of date

3964. By Martin Trigaux (OpenERP)

[IMP] remove useless import

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/web/controllers/main.py'
2--- addons/web/controllers/main.py 2014-03-12 18:17:24 +0000
3+++ addons/web/controllers/main.py 2014-04-01 12:31:17 +0000
4@@ -1679,6 +1679,8 @@
5 for k, v in self.fields_info(model, export_fields).iteritems())
6
7 class ExportFormat(object):
8+ raw_data = False
9+
10 @property
11 def content_type(self):
12 """ Provides the format's content type """
13@@ -1711,7 +1713,7 @@
14 ids = ids or Model.search(domain, 0, False, False, request.context)
15
16 field_names = map(operator.itemgetter('name'), fields)
17- import_data = Model.export_data(ids, field_names, request.context).get('datas',[])
18+ import_data = Model.export_data(ids, field_names, self.raw_data, context=request.context).get('datas',[])
19
20 if import_compat:
21 columns_headers = field_names
22@@ -1764,6 +1766,8 @@
23 return data
24
25 class ExcelExport(ExportFormat, http.Controller):
26+ # Excel needs raw data to correctly handle numbers and date values
27+ raw_data = True
28
29 @http.route('/web/export/xls', type='http', auth="user")
30 @serialize_exception
31@@ -1785,14 +1789,20 @@
32 worksheet.write(0, i, fieldname)
33 worksheet.col(i).width = 8000 # around 220 pixels
34
35- style = xlwt.easyxf('align: wrap yes')
36+ base_style = xlwt.easyxf('align: wrap yes')
37+ date_style = xlwt.easyxf('align: wrap yes', num_format_str='YYYY-MM-DD')
38+ datetime_style = xlwt.easyxf('align: wrap yes', num_format_str='YYYY-MM-DD HH:mm:SS')
39
40 for row_index, row in enumerate(rows):
41 for cell_index, cell_value in enumerate(row):
42+ cell_style = base_style
43 if isinstance(cell_value, basestring):
44 cell_value = re.sub("\r", " ", cell_value)
45- if cell_value is False: cell_value = None
46- worksheet.write(row_index + 1, cell_index, cell_value, style)
47+ elif isinstance(cell_value, datetime.datetime):
48+ cell_style = datetime_style
49+ elif isinstance(cell_value, datetime.date):
50+ cell_style = date_style
51+ worksheet.write(row_index + 1, cell_index, cell_value, cell_style)
52
53 fp = StringIO()
54 workbook.save(fp)