[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) <tde@openerp.com>
This commit is contained in:
Pierre-Yves Dufays
2022-02-28 16:33:50 +00:00
parent 424e46bcfe
commit 354b9e8ed2
4 changed files with 12 additions and 2 deletions
+2 -1
View File
@@ -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:
@@ -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;
+1 -1
View File
@@ -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')
+5
View File
@@ -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 <reference/fields/related>`
"""
@@ -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]