odoo10同一模型的不一样视图不一样群组权限控制

先描述下需求:session

一个模型定义两个calendar视图,其中A视图G1群组能够CRUD操做,可是不显示特殊字段spec_field,对于B视图G1群组只能查看,G2群组只能修改其中的特殊字段spec_fieldapp

因为odoo10中的calendar视图、tree视图的点击事件走的方法并不相同,因此须要本身处理calendar视图中form视图的加载过程;ide

我重写了formview的load_record()方法,代码以下:this

 1 load_record: function (record) {
 2             var self = this;
 3             this._super.apply(this, arguments);
 4             if (self.model == 'esw.working.hours.assign') {
 5 
 6                 //管理员只容许查看填报,将编辑按钮隐藏掉
 7                 self.session.user_has_group('esw_calendar.esw_working_hours_group_view').then(function (has_group) {
 8                     if (has_group && self.ViewManager.action &&
 9                             self.ViewManager.action.xml_id == 'esw_calendar.open_esw_working_hours_fill_in_calendar'){
10                         self.$buttons.find('.o_form_button_edit').hide();
11                     }
12                 })
13 
14                 //对于从open_esw_working_hours_tree这个calendar视图打开的formview作填报判断,已填报的工时不容许编辑
15                 if (self.ViewManager.action &&
16                         self.ViewManager.action.xml_id == 'esw_calendar.open_esw_working_hours_tree' &&
17                         self.$el.find('input[name=is_filled_in]').length>0 &&
18                         self.$el.find('input[name=is_filled_in]')[0].checked){
19                     self.$buttons.find('.o_form_button_edit').hide();
20                 }else if (self.$buttons) {
21                     self.$buttons.find('.o_form_button_edit').show();
22                 }
23         }
24 },

 

不知是否还有更简单有效的方法,若是有,你们能够留言告诉下,谢谢spa

因为时间问题,写的比较简单,有问题下边留言code

但愿能够帮助有须要的人,共同进步.......................................................orm

相关文章
相关标签/搜索