[ADD] orm: add the possibility to export in raw format instead of all string
lp bug: https://launchpad.net/bugs/844569 fixed bzr revid: mat@openerp.com-20140331151743-94sk4xd7cr3dzn8m
This commit is contained in:
parent
035b1e8f8e
commit
4074a01041
|
@ -1100,7 +1100,7 @@ class BaseModel(object):
|
|||
self._rec_name = 'name'
|
||||
|
||||
|
||||
def __export_row(self, cr, uid, row, fields, context=None):
|
||||
def __export_row(self, cr, uid, row, fields, raw_data=False, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
|
@ -1193,8 +1193,7 @@ class BaseModel(object):
|
|||
break
|
||||
|
||||
for row2 in r:
|
||||
lines2 = row2._model.__export_row(cr, uid, row2, fields2,
|
||||
context)
|
||||
lines2 = row2._model.__export_row(cr, uid, row2, fields2, context=context)
|
||||
if first:
|
||||
for fpos2 in range(len(fields)):
|
||||
if lines2 and lines2[0][fpos2]:
|
||||
|
@ -1220,10 +1219,17 @@ class BaseModel(object):
|
|||
if isinstance(r, browse_record):
|
||||
r = self.pool[r._table_name].name_get(cr, uid, [r.id], context=context)
|
||||
r = r and r[0] and r[0][1] or ''
|
||||
data[fpos] = tools.ustr(r or '')
|
||||
if not raw_data or cols and cols._type in ('integer', 'boolean', 'float'):
|
||||
data[fpos] = r
|
||||
elif not raw_data or cols and cols._type == 'date':
|
||||
data[fpos] = datetime.datetime.strptime(r, tools.DEFAULT_SERVER_DATE_FORMAT)
|
||||
elif not raw_data or cols and cols._type == 'datetime':
|
||||
data[fpos] = datetime.datetime.strptime(r, tools.DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
else:
|
||||
data[fpos] = tools.ustr(r or '')
|
||||
return [data] + lines
|
||||
|
||||
def export_data(self, cr, uid, ids, fields_to_export, context=None):
|
||||
def export_data(self, cr, uid, ids, fields_to_export, raw_data=False, context=None):
|
||||
"""
|
||||
Export fields for selected objects
|
||||
|
||||
|
@ -1231,6 +1237,7 @@ class BaseModel(object):
|
|||
:param uid: current user id
|
||||
:param ids: list of ids
|
||||
:param fields_to_export: list of fields
|
||||
:param raw_data: True to return value in fields type, False for string values
|
||||
:param context: context arguments, like lang, time zone
|
||||
:rtype: dictionary with a *datas* matrix
|
||||
|
||||
|
@ -1245,7 +1252,7 @@ class BaseModel(object):
|
|||
fields_to_export = map(fix_import_export_id_paths, fields_to_export)
|
||||
datas = []
|
||||
for row in self.browse(cr, uid, ids, context):
|
||||
datas += self.__export_row(cr, uid, row, fields_to_export, context)
|
||||
datas += self.__export_row(cr, uid, row, fields_to_export, raw_data=raw_data, context=context)
|
||||
return {'datas': datas}
|
||||
|
||||
def import_data(self, cr, uid, fields, datas, mode='init', current_module='', noupdate=False, context=None, filename=None):
|
||||
|
|
Loading…
Reference in New Issue