@@ -861,25 +861,20 @@ def get_view(self, view_id=None, view_type="form", **options):
861861 node .append (new_node )
862862 _merge_view_fields (all_models , new_models )
863863 excepted_fields = self ._get_all_validation_exceptions ()
864- readonly_fields = (
865- self .env ["ir.model.fields" ]
866- .sudo ()
867- .search ([("model" , "=" , self ._name ), ("readonly" , "=" , True )])
868- .mapped ("name" )
869- )
864+ all_fields = self .fields_get (attributes = ("readonly" ,))
870865 for node in doc .xpath ("//field[@name][not(ancestor::field)]" ):
871- if node .attrib .get ("name" ) in excepted_fields :
872- continue
873- if node .attrib .get ("name" ) in readonly_fields and not node .attrib .get (
874- "readonly"
875- ):
876- # Readonly field with readonly not set become editable
877- # Happens for computed fields
866+ field_name = node .attrib .get ("name" )
867+ if field_name in excepted_fields :
878868 continue
879869 new_r_modifier = self ._get_tier_validation_readonly_domain ()
880870 old_r_modifier = node .attrib .get ("readonly" )
881871 if old_r_modifier :
882872 new_r_modifier = f"({ old_r_modifier } ) or ({ new_r_modifier } )"
873+ elif all_fields .get (field_name , {}).get ("readonly" ):
874+ # don't set dynamic readonly attribute for fields
875+ # marked readonly in the ORM (ie computed fields)
876+ # if the view doesn't set one
877+ continue
883878 node .attrib ["readonly" ] = new_r_modifier
884879 res ["arch" ] = etree .tostring (doc )
885880 res ["models" ] = frozendict (all_models )
0 commit comments