From 354b9e8ed2ae1b103a728eacf40838fcd0e6a86a Mon Sep 17 00:00:00 2001 From: Pierre-Yves Dufays Date: Mon, 31 Jan 2022 14:08:28 +0000 Subject: [PATCH] [IMP] web, base: export field res_partner.name by default in import-compatible mode Purpose: Include the name of the partners so that: - it can easily be updated - it is easier for users to recognize who is who To generalize this modification, a new attribute has been added to the model field descriptor (odoo/fields.py): default_export_compatible. Setting this value to True on a field of a model will force that field to be included by default in the exportation when "import-compatible export" is selected. Specification: If the user goes: Contacts > List view > Select Records > Action Export > I want to update data The field name is selected by default The fields selected by default for export are the columns of the list so that what is exported by default is what the user sees on the screen. The display name is one of the column but is not importable. When the option "I want to update data" is selected, only field that are compatible for importation are selected and then display name is no longer selected. With this modification, the name is selected instead. Technical: - a new attribute "default_export_compatible" has been added in odoo/fields - the controller /web/export/get_fields that lists the fields available for exportation has been modified to add a default_export attribute on each returned field. This new attribute is set to True when import_compat is True and default_export_compatible is True on a given field. The client uses that information to force by default the field for exportation. Task 2734222 closes odoo/odoo#83697 Signed-off-by: Thibault Delavallee (tde) --- addons/web/controllers/main.py | 3 ++- addons/web/static/src/legacy/js/widgets/data_export.js | 4 ++++ odoo/addons/base/models/res_partner.py | 2 +- odoo/fields.py | 5 +++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 6a418b54661..34497de6b28 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1632,7 +1632,8 @@ class Export(http.Controller): 'value': val, 'children': False, 'field_type': field.get('type'), 'required': field.get('required'), - 'relation_field': field.get('relation_field')} + 'relation_field': field.get('relation_field'), + 'default_export': import_compat and field.get('default_export_compatible')} records.append(record) if len(id.split('/')) < 3 and 'relation' in field: diff --git a/addons/web/static/src/legacy/js/widgets/data_export.js b/addons/web/static/src/legacy/js/widgets/data_export.js index f26e9357c40..24a9a039a59 100644 --- a/addons/web/static/src/legacy/js/widgets/data_export.js +++ b/addons/web/static/src/legacy/js/widgets/data_export.js @@ -397,10 +397,14 @@ var DataExport = Dialog.extend({ self._onShowData(records); self.$('.o_fields_list').empty(); + const forceDefaultExportFields = records.filter(r => r.default_export).map(r => r.id); + _.chain(self.$fieldsList.find('.o_export_field')) .map(function (field) { return $(field).data('field_id'); }) + .union(forceDefaultExportFields) .union(self.defaultExportFields) .intersection(compatibleFields) + .uniq() .each(function (field) { var record = _.find(records, function (rec) { return rec.id === field; diff --git a/odoo/addons/base/models/res_partner.py b/odoo/addons/base/models/res_partner.py index 4bebc87d92e..f0a3434f715 100644 --- a/odoo/addons/base/models/res_partner.py +++ b/odoo/addons/base/models/res_partner.py @@ -150,7 +150,7 @@ class Partner(models.Model): values['lang'] = values.get('lang') or parent.lang or self.env.lang return values - name = fields.Char(index=True) + name = fields.Char(index=True, default_export_compatible=True) display_name = fields.Char(compute='_compute_display_name', recursive=True, store=True, index=True) date = fields.Date(index=True) title = fields.Many2one('res.partner.title') diff --git a/odoo/fields.py b/odoo/fields.py index a20a566188c..e55c39c57cb 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -231,6 +231,8 @@ class Field(MetaField('DummyField', (object,), {})): :param str related: sequence of field names + :param bool default_export_compatible: whether the field must be exported by default in an import-compatible export + .. seealso:: :ref:`Advanced fields/Related fields ` """ @@ -290,6 +292,8 @@ class Field(MetaField('DummyField', (object,), {})): group_expand = None # name of method to expand groups in read_group() prefetch = True # whether the field is prefetched + default_export_compatible = False # whether the field must be exported by default in an import-compatible export + def __init__(self, string=Default, **kwargs): kwargs['string'] = string self._sequence = next(_global_seq) @@ -812,6 +816,7 @@ class Field(MetaField('DummyField', (object,), {})): _description_groups = property(attrgetter('groups')) _description_change_default = property(attrgetter('change_default')) _description_group_operator = property(attrgetter('group_operator')) + _description_default_export_compatible = property(attrgetter('default_export_compatible')) def _description_depends(self, env): return env.registry.field_depends[self]