diff options
| author | Raphael Collet <rco@odoo.com> | 2019-02-04 14:52:16 +0000 |
|---|---|---|
| committer | Martin Trigaux <mat@odoo.com> | 2019-08-21 14:36:19 +0000 |
| commit | 1d2bccd0dbd2770e0625a26b66a8b48c954b2c86 (patch) | |
| tree | 5b72f9432c10fc2b351a91eeecd89d3ded8f499c /odoo/fields.py | |
| parent | 4cd093a0013752ddb140fe0f0f8928bc001543f6 (diff) | |
[IMP] fields: stricter rules on selection fields overridings
One cannot override the attribute `selection`, and list selections can only be
extended with `selection_add`.
Adapt the bad extensions to be consistent with the new warnings
closes odoo/odoo#35663
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
Diffstat (limited to 'odoo/fields.py')
| -rw-r--r-- | odoo/fields.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/odoo/fields.py b/odoo/fields.py index 44cbc97d9d4..3a6824433cc 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -2048,6 +2048,11 @@ class Selection(Field): if 'selection' in field.args: selection = field.args['selection'] if isinstance(selection, list): + if ( + values is not None + and values != [kv[0] for kv in selection] + ): + _logger.warning("%s: selection=%r overrides existing selection; use selection_add instead", self, selection) values = [kv[0] for kv in selection] labels.update(selection) else: @@ -2055,8 +2060,10 @@ class Selection(Field): if 'selection_add' in field.args: selection_add = field.args['selection_add'] - assert isinstance(selection_add, list) - assert values is not None + assert isinstance(selection_add, list), \ + "%s: selection_add=%r must be a list" % (self, selection_add) + assert values is not None, \ + "%s: selection_add=%r on non-list selection %r" % (self, selection_add, self.selection) values = merge_sequences(values, [kv[0] for kv in selection_add]) labels.update(kv for kv in selection_add if len(kv) == 2) |
