summaryrefslogtreecommitdiff
path: root/addons/web/controllers
diff options
context:
space:
mode:
authorXavier Morel <xmo@odoo.com>2020-10-05 10:57:40 +0000
committerXavier Morel <xmo@odoo.com>2020-12-08 09:11:19 +0000
commitc5bf36fc526543ef93fb92967fcaa2eed6f68657 (patch)
tree1b220b5bdbd6c50af9ebb6e992b29d52e181d00b /addons/web/controllers
parent7c8c5a9cd716d35783734493cbb15b194e7b787c (diff)
[FIX] web: export should ignore requests for xid on views
5c4544fb2943e63fc1e0f5ae1e7e250a5a2b2cf1 reordered some of the operations at the export toplevel, and in doing so moved the filtering of the xid out of the `fields` list *after* that fields list has been used to know what fields to export. Meaning the fields list isn't filtered anymore, and requesting the xid on a view would blow up due to a latter assertion checking against that. Fix the filter, although a better solution might be to strip out the field upstream (in the fields list provided to the export wizard) such that users wouldn't even attempt to perform this export. An other possibility (possibly combined with the previous) could be to only strip out the export of the xid based on the absence of an ``id`` field on the model, though that's somewhat risky: technically views have no reason to be stable so a "record" could disappear or move around without the ORM being aware, leading to dangling xids. Fixes #46674 closes odoo/odoo#62993 X-original-commit: adc25bcf67438675bc9b0d55975ce733d58b4fb5 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
Diffstat (limited to 'addons/web/controllers')
-rw-r--r--addons/web/controllers/main.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py
index b35141af215..1a57bf87b24 100644
--- a/addons/web/controllers/main.py
+++ b/addons/web/controllers/main.py
@@ -1906,13 +1906,16 @@ class ExportFormat(object):
model, fields, ids, domain, import_compat = \
operator.itemgetter('model', 'fields', 'ids', 'domain', 'import_compat')(params)
+ Model = request.env[model].with_context(**params.get('context', {}))
+ if not Model._is_an_ordinary_table():
+ fields = [field for field in fields if field['name'] != 'id']
+
field_names = [f['name'] for f in fields]
if import_compat:
columns_headers = field_names
else:
columns_headers = [val['label'].strip() for val in fields]
- Model = request.env[model].with_context(**params.get('context', {}))
groupby = params.get('groupby')
if not import_compat and groupby:
groupby_type = [Model._fields[x.split(':')[0]].type for x in groupby]
@@ -1930,11 +1933,9 @@ class ExportFormat(object):
Model = Model.with_context(import_compat=import_compat)
records = Model.browse(ids) if ids else Model.search(domain, offset=0, limit=False, order=False)
- if not Model._is_an_ordinary_table():
- fields = [field for field in fields if field['name'] != 'id']
-
export_data = records.export_data(field_names).get('datas',[])
response_data = self.from_data(columns_headers, export_data)
+
return request.make_response(response_data,
headers=[('Content-Disposition',
content_disposition(self.filename(model))),