Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2892 Представления

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.
Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
мар. 18
6627
2
июн. 24
10529
0
апр. 22
3369
3
сент. 21
25445
1
мая 17
8174