[IMP] fields: make related fields readonly by default
With this commit, any *explicitly* related fields will be `readonly=True`
by default.
*Implicitly* related fields (i.e. _inherits fields) however will keep the
source field's `readonly` attribute.
The rationales behind this patch are:
* Enforce good practices, as the most common use-case for
related fields is the same as for compute fields: to read data.
* Avoid errors where some user saves a form view which contains
a related field that the user doesn't have write access to.
This commit is contained in:
+1
-1
@@ -421,6 +421,7 @@ class Field(MetaField('DummyField', (object,), {})):
|
||||
# by default, related fields are not stored and not copied
|
||||
attrs['store'] = attrs.get('store', False)
|
||||
attrs['copy'] = attrs.get('copy', False)
|
||||
attrs['readonly'] = attrs.get('readonly', True)
|
||||
if attrs.get('company_dependent'):
|
||||
# by default, company-dependent fields are not stored and not copied
|
||||
attrs['store'] = False
|
||||
@@ -621,7 +622,6 @@ class Field(MetaField('DummyField', (object,), {})):
|
||||
_related_comodel_name = property(attrgetter('comodel_name'))
|
||||
_related_string = property(attrgetter('string'))
|
||||
_related_help = property(attrgetter('help'))
|
||||
_related_readonly = property(attrgetter('readonly'))
|
||||
_related_groups = property(attrgetter('groups'))
|
||||
_related_group_operator = property(attrgetter('group_operator'))
|
||||
|
||||
|
||||
@@ -2480,6 +2480,7 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})):
|
||||
related=(parent_field, name),
|
||||
related_sudo=False,
|
||||
copy=field.copy,
|
||||
readonly=field.readonly,
|
||||
)
|
||||
|
||||
# add inherited fields that are not redefined locally
|
||||
|
||||
Reference in New Issue
Block a user