跳至內容
選單
此問題已被標幟

Hello everybody


I'm using Odoo Community v15 and I need to restrict access to certain contacts based on the following requirements:

  • Some Sales agents will only see a subset of the contacts.
  • Those agents will have full access to the contacts assigned to them. However, for other contacts, only the fields for name and VAT will be visible.


The first point is easy enough, I've created a group and an accompanying record rule, but I'm stuck on the second one. I've considered the following options:

  • Override `get_formview_id` to return a different view in each case. This doesn't seem to work: the overriden function is never called. What's more, each record in the recordset could have a different access level (i.e. using next record button).
  • Use a QWeb view, since they are more flexible but I don't think it's possible to use them as a `form` view.
  • Intercept the base view loading (either in `get_fields_view` or `load_views`) to add a `group` attribute or remove fields as needed. This seems 'dirty' to me and could lead to layout issues.
  • Change the record rules and create a "new app" for contacts: The one from Odoo will show the records that the user has access to, while the other will show the rest. This works, but isn't user friendly.


So, for now, I've settled on the following:

I've created a new minimal view for the model, with a low priority and assigned to my user group, with only the fields that I need to display if the record is restricted. View resolution works (as long as I access the record with a url and not through a menu: web#id=xxxx&model=res.partner&view_type=form) for both the restricted and unrestricted users, but at this point the user either views all fields or the restricted ones depending only on their group, and not the record itself.


Now my idea is to change `contacts.action_contacts` to return the appropiate view, but I can't find how, as it seems that only server actions allow for code execution while window actions do not. I cannot add a second form view to the action either, as there is a database constraint in place that prevents it. And besides, as with `get_formview_id` I'm not 100% sure if the views are loaded on a record or model basis.


I'm going about this completely the wrong way? What is the simplest way of archive this? Your guidance in walking me through this would be greatly appreciated.





頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
3
11月 24
183
3
6月 25
5779
2
1月 24
1005
2
8月 23
2437
2
5月 23
2650