summaryrefslogtreecommitdiff
path: root/addons/web/controllers/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/controllers/main.py')
-rw-r--r--addons/web/controllers/main.py33
1 files changed, 19 insertions, 14 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py
index cd0f2ff0873..bf27842d55e 100644
--- a/addons/web/controllers/main.py
+++ b/addons/web/controllers/main.py
@@ -1238,8 +1238,8 @@ class Export(http.Controller):
:rtype: [(str, str)]
"""
return [
- {'tag': 'csv', 'label': 'CSV'},
{'tag': 'xls', 'label': 'Excel', 'error': None if xlwt else "XLWT 1.3.0 required"},
+ {'tag': 'csv', 'label': 'CSV'},
]
def fields_get(self, model):
@@ -1250,24 +1250,29 @@ class Export(http.Controller):
@http.route('/web/export/get_fields', type='json', auth="user")
def get_fields(self, model, prefix='', parent_name= '',
import_compat=True, parent_field_type=None,
- exclude=None):
+ parent_field=None, exclude=None):
- if import_compat and parent_field_type == "many2one":
- fields = {}
+ if import_compat and parent_field_type in ['many2one', 'many2many']:
+ fields = self.fields_get(model)
+ fields = {k: v for k, v in fields.items() if k in ['id', 'name']}
else:
fields = self.fields_get(model)
- if import_compat:
- fields.pop('id', None)
- else:
+ if not import_compat:
fields['.id'] = fields.pop('id', {'string': 'ID'})
+ else:
+ fields['id']['string'] = _('External ID')
+
+ if parent_field:
+ parent_field['string'] = _('External ID')
+ fields['id'] = parent_field
fields_sequence = sorted(fields.items(),
- key=lambda field: odoo.tools.ustr(field[1].get('string', '')))
+ key=lambda field: (field[0] not in ['id', '.id', 'display_name', 'name'], odoo.tools.ustr(field[1].get('string', ''))))
records = []
for field_name, field in fields_sequence:
- if import_compat:
+ if import_compat and not field_name == 'id':
if exclude and field_name in exclude:
continue
if field.get('readonly'):
@@ -1279,6 +1284,9 @@ class Export(http.Controller):
continue
id = prefix + (prefix and '/'or '') + field_name
+ if field_name == 'name' and import_compat and parent_field_type in ['many2one', 'many2many']:
+ # Add name field when expand m2o and m2m fields in import-compatible mode
+ id = prefix
name = parent_name + (parent_name and '/' or '') + field['string']
record = {'id': id, 'string': name,
'value': id, 'children': False,
@@ -1290,11 +1298,8 @@ class Export(http.Controller):
if len(name.split('/')) < 3 and 'relation' in field:
ref = field.pop('relation')
record['value'] += '/id'
- record['params'] = {'model': ref, 'prefix': id, 'name': name}
-
- if not import_compat or field['type'] == 'one2many':
- # m2m field in import_compat is childless
- record['children'] = True
+ record['params'] = {'model': ref, 'prefix': id, 'name': name, 'parent_field': field}
+ record['children'] = True
return records