[FIX] base: lighten default values validation in ir.values
Rev acd8c4de18 prevents the creation of default values for fields that
are not defined. This is too restrictive because of the following
points:
- one may want to create default values for fields that are yet to be
defined
- "fake" default fields used in res.config that do not point to real
fields
The initial scenario this revision was trying to fix is the creation of
wrong default values through studio. This scenario is still fixed, as it
concerns the last `except` branch.
The tests have been updated to reflect these changes.
This commit is contained in:
@@ -7,6 +7,10 @@ from odoo import api, fields, models, tools, _
|
||||
from odoo.exceptions import AccessError, MissingError, ValidationError
|
||||
from odoo.tools import pickle
|
||||
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
EXCLUDED_FIELDS = set(('code',
|
||||
'report_sxw_content', 'report_rml_content', 'report_sxw', 'report_rml',
|
||||
'report_sxw_content_data', 'report_rml_content_data', 'search_view', ))
|
||||
@@ -224,7 +228,7 @@ class IrValues(models.Model):
|
||||
field = self.env[model]._fields[field_name]
|
||||
field.convert_to_cache(value, self.browse())
|
||||
except KeyError:
|
||||
raise ValidationError(_("Invalid field %s.%s") % (model, field_name))
|
||||
_logger.warning("Invalid field %s.%s", model, field_name)
|
||||
except Exception:
|
||||
raise ValidationError(_("Invalid value for %s.%s: %s") % (model, field_name, value))
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import tools
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
@@ -41,11 +42,12 @@ class TestIrValues(TransactionCase):
|
||||
self.assertTrue(d, "At least one value should be retrieved for this model.")
|
||||
self.assertEqual(d[2], '007', "Can't retrieve the created default value.")
|
||||
|
||||
# create invalid defaults
|
||||
with self.assertRaises(ValidationError):
|
||||
# create valid but unusable defaults, a ValidationError should not be thrown
|
||||
with tools.mute_logger('odoo.addons.base.ir.ir_values'):
|
||||
ir_values.set_default('unknown_model', 'unknown_field', 42)
|
||||
with self.assertRaises(ValidationError):
|
||||
ir_values.set_default('res.partner', 'unknown_field', 42)
|
||||
|
||||
# create invalid defaults
|
||||
with self.assertRaises(ValidationError):
|
||||
ir_values.set_default('res.partner', 'lang', 'some_LANG')
|
||||
with self.assertRaises(ValidationError):
|
||||
|
||||
Reference in New Issue
Block a user