[FIX] fields: do not infer a related field to be required
Forcing a related field to be required causes some issues. Having such a field in a one2many relation may block the creation of records in the field, as the main record does not exist yet, and the field has no value. It may also cause trouble if the field is stored: being required constrains the corresponding column to be NOT NULL. Inserting a row will fail, because related fields are currently determined *after* the row insertion.
This commit is contained in:
@@ -494,12 +494,10 @@ class Field(object):
|
||||
|
||||
# determine the chain of fields, and make sure they are all set up
|
||||
recs = env[self.model_name]
|
||||
fields = []
|
||||
for name in self.related:
|
||||
field = recs._fields[name]
|
||||
field.setup(env)
|
||||
recs = recs[name]
|
||||
fields.append(field)
|
||||
|
||||
self.related_field = field
|
||||
|
||||
@@ -529,10 +527,6 @@ class Field(object):
|
||||
if not self.states and self.inherited:
|
||||
self.states = field.states
|
||||
|
||||
# special case for required: check if all fields are required
|
||||
if not self.store and not self.required:
|
||||
self.required = all(field.required for field in fields)
|
||||
|
||||
def _compute_related(self, records):
|
||||
""" Compute the related field `self` on `records`. """
|
||||
# when related_sudo, bypass access rights checks when reading values
|
||||
|
||||
Reference in New Issue
Block a user