Skip to Content
Menu
This question has been flagged
2 Replies
2104 Views

Hi,

Would appreciate assistance in this.

Objective
  • Filter a list of possible departments based on the current user_id
Setup
  • There are 3 models illustrated below
class RiskUnit
...
department_lines = one2Many('riskunit.memberlines', 'department_id')


class RiskUnitMemberLines

..

user_id = many2One('res.users', 'User')
department_id = many2One('risk.unit', 'department')

class OperationalRisk

...

department_id = many2One('risk.unit', string = 'Department')

In the form view field for Operational risk, I tried to filter the available departments based on the user.id but was unsuccessful.  Appreciate assistance on this

I tried the following in the views.xml file

field name="department_id" domain="[( 'department_lines.user_id' ,'=' , 'user.id' )]"

&

field name="department_id" domain="[( 'department_lines.user_id' ,'in' , 'user.id' )]"

but both returned an empty set of departments





Avatar
Discard
Author Best Answer

Thank you so much Tomamaso - it works (I struggled the whole evening yesterday )

For the reference of others, here was the solution I used to manage access

Requirements
  1. Create a list of risk units (i.e departments) and users can be added to the risk units
  2. No constraint on the risk units users can be added to. Some can be added to one, while others could be added to multiple
  3. Users should only be able to view the risks associated with the risk units they were added to
General Solution

Create a risk unit ('risk.unit') master table

Create a risk unit user lines ('risk.unit.lines') table which references the risk unit master table

Add users to the risk unit lines table

To apply domain force to restrict visibility of departments (security.xml):  

 [( 'department_id.department_lines.user_id' ,'=' , user.id )]

To apply domain to restrict the options in drop down

<fieldname="department_id"domain="[( 'department_lines.user_id' ,'=' , uid )]"/>


Enhancements 
  • Create a default department / risk unit option so that will be sorted on top in the case of users being assigned multiple departments / risk unit
  • Create child units for example a department like risk management may have subunits like liquidity risk team 
  • Have a way to present a list with tree view at the start of the app of available departments and users select the department, which is then applied throughout the rest of the user journey


Avatar
Discard
Best Answer

have you tried uid instead of 'user.id' ?

Avatar
Discard
Related Posts Replies Views Activity
1
May 24
1310
1
Nov 22
3301
2
May 18
8877
2
Jul 17
5421
5
Jul 15
5021