Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată

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.
Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
mar. 18
6589
2
iun. 24
10483
0
apr. 22
3350
3
sept. 21
25424
1
mai 17
8168