From 52a8ed3c0c72b21baf589bc9b91a030d9da661a8 Mon Sep 17 00:00:00 2001 From: Adrian Torres Date: Fri, 21 Sep 2018 13:59:47 +0200 Subject: [PATCH] [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. --- odoo/fields.py | 2 +- odoo/models.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/odoo/fields.py b/odoo/fields.py index ea232738109..deee1492315 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -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')) diff --git a/odoo/models.py b/odoo/models.py index 86fc7590d3f..48e17c487e3 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -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