diff options
| author | Martin Trigaux <mat@odoo.com> | 2019-01-25 15:04:42 +0000 |
|---|---|---|
| committer | Martin Trigaux <mat@odoo.com> | 2019-08-19 11:44:34 +0000 |
| commit | 7593b887dff4fcd474ca72aead6825481b419d86 (patch) | |
| tree | 28c5445d1440701de5c7534e1d8accef222798d8 /odoo/fields.py | |
| parent | a248171d96de3ad6d8e22c855886dfae61e145e2 (diff) | |
[REF] fields: use ir.model.fields.selection
The selection values of a selection field are now stored in database in the
model ir.model.fields.selection
This will allow to have a modular approche on selections and each selection
is now linked to the module that declared it.
Previously to this change, the selections were linked to the field, meaning
uninstalling a module had no impact on the selections stored on database.
With this change, the selections will now be translated in the correct module
(having an external id) and the records having a used selection will now be
reset to null.
closes odoo/odoo#30228
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
Co-authored-by: Raphaƫl Collet <rco@odoo.com>
Diffstat (limited to 'odoo/fields.py')
| -rw-r--r-- | odoo/fields.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/odoo/fields.py b/odoo/fields.py index b8c964aaa79..daa28dff6e1 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -1980,6 +1980,25 @@ class Selection(Field): selection_add = field.args['selection_add'] self.selection = list(OrderedDict(self.selection + selection_add).items()) + def _selection_modules(self, model): + """ Return a mapping from selection values to modules defining each value. """ + if not isinstance(self.selection, list): + return {} + value_modules = defaultdict(set) + for field in reversed(resolve_mro(model, self.name, self._can_setup_from)): + module = field.args.get('_module') + if not module: + continue + if 'selection' in field.args: + value_modules.clear() + if isinstance(field.args['selection'], list): + for value, label in field.args['selection']: + value_modules[value].add(module) + if 'selection_add' in field.args: + for value, label in field.args['selection_add']: + value_modules[value].add(module) + return value_modules + def _description_selection(self, env): """ return the selection list (pairs (value, label)); labels are translated according to context language @@ -1992,10 +2011,7 @@ class Selection(Field): # translate selection labels if env.lang: - name = "%s,%s" % (self.model_name, self.name) - translate = partial( - env['ir.translation']._get_source, name, 'selection', env.lang) - return [(value, translate(label) if label else label) for value, label in selection] + return env['ir.translation'].get_field_selection(self.model_name, self.name) else: return selection |
