Skip to Content
Menu
Dette spørgsmål er blevet anmeldt

In Odoo 17, I have a sublevel_id field in the sale.order.line table (this is a Many2one field to a configuration table of mine). My requirement is that any record in sale.order.line where [('sublevel_id.level', 'in', ['L5.1', 'L7.2'])] should have all fields on the form view set to readonly. Currently, my approach is: in sale.order.line, I created a field code = fields.Char(related='sublevel_id.level'). Then, on the form view of sale.order.line, I set readonly for the fields. However, since I have too many fields, I don't want to repeat this for every single one. Therefore, I want to override and modify the get_view method because I believe modifying this method would be more beneficial for my case.

Initially, when I tested the get_view method by setting readonly based on any record ID, it worked correctly. My code is as follows:



@api.model def _get_view(self, view_id=None, view_type='form', **options): arch, view = super()._get_view(view_id, view_type, **options) if view_type == "form": for node in arch.xpath("//field"): node.set("readonly", "id == 75") return arch, view
 
But when I tested it with my condition, the method failed. Specifically, it made all records readonly, without checking my condition: 

@api.model def _get_view(self, view_id=None, view_type='form', **options): arch, view = super()._get_view(view_id, view_type, **options) if view_type == 'form': for node in arch.xpath("//field"): node.set('readonly', "[('sublevel_id.level', 'in', ['L5.1', 'L7.2'])]") return arch, view 

I’m not sure where I went wrong and would really appreciate if someone could help me resolve this issue. I want to make the entire form view readonly based on the value of the field by modifying the get_view method.
Avatar
Kassér
Related Posts Besvarelser Visninger Aktivitet
1
mar. 18
6587
2
jun. 24
10479
0
apr. 22
3348
3
sep. 21
25423
1
maj 17
8167