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
=== modified file 'addons/web/controllers/main.py'
--- addons/web/controllers/main.py 2014-03-12 18:17:24 +0000
+++ addons/web/controllers/main.py 2014-04-01 12:31:17 +0000
@@ -1679,6 +1679,8 @@
1679 for k, v in self.fields_info(model, export_fields).iteritems())1679 for k, v in self.fields_info(model, export_fields).iteritems())
16801680
1681class ExportFormat(object):1681class ExportFormat(object):
1682 raw_data = False
1683
1682 @property1684 @property
1683 def content_type(self):1685 def content_type(self):
1684 """ Provides the format's content type """1686 """ Provides the format's content type """
@@ -1711,7 +1713,7 @@
1711 ids = ids or Model.search(domain, 0, False, False, request.context)1713 ids = ids or Model.search(domain, 0, False, False, request.context)
17121714
1713 field_names = map(operator.itemgetter('name'), fields)1715 field_names = map(operator.itemgetter('name'), fields)
1714 import_data = Model.export_data(ids, field_names, request.context).get('datas',[])1716 import_data = Model.export_data(ids, field_names, self.raw_data, context=request.context).get('datas',[])
17151717
1716 if import_compat:1718 if import_compat:
1717 columns_headers = field_names1719 columns_headers = field_names
@@ -1764,6 +1766,8 @@
1764 return data1766 return data
17651767
1766class ExcelExport(ExportFormat, http.Controller):1768class ExcelExport(ExportFormat, http.Controller):
1769 # Excel needs raw data to correctly handle numbers and date values
1770 raw_data = True
17671771
1768 @http.route('/web/export/xls', type='http', auth="user")1772 @http.route('/web/export/xls', type='http', auth="user")
1769 @serialize_exception1773 @serialize_exception
@@ -1785,14 +1789,20 @@
1785 worksheet.write(0, i, fieldname)1789 worksheet.write(0, i, fieldname)
1786 worksheet.col(i).width = 8000 # around 220 pixels1790 worksheet.col(i).width = 8000 # around 220 pixels
17871791
1788 style = xlwt.easyxf('align: wrap yes')1792 base_style = xlwt.easyxf('align: wrap yes')
1793 date_style = xlwt.easyxf('align: wrap yes', num_format_str='YYYY-MM-DD')
1794 datetime_style = xlwt.easyxf('align: wrap yes', num_format_str='YYYY-MM-DD HH:mm:SS')
17891795
1790 for row_index, row in enumerate(rows):1796 for row_index, row in enumerate(rows):
1791 for cell_index, cell_value in enumerate(row):1797 for cell_index, cell_value in enumerate(row):
1798 cell_style = base_style
1792 if isinstance(cell_value, basestring):1799 if isinstance(cell_value, basestring):
1793 cell_value = re.sub("\r", " ", cell_value)1800 cell_value = re.sub("\r", " ", cell_value)
1794 if cell_value is False: cell_value = None1801 elif isinstance(cell_value, datetime.datetime):
1795 worksheet.write(row_index + 1, cell_index, cell_value, style)1802 cell_style = datetime_style
1803 elif isinstance(cell_value, datetime.date):
1804 cell_style = date_style
1805 worksheet.write(row_index + 1, cell_index, cell_value, cell_style)
17961806
1797 fp = StringIO()1807 fp = StringIO()
1798 workbook.save(fp)1808 workbook.save(fp)