Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
3636 Zobrazení

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
Zrušit
Autor Nejlepší odpověď

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
Zrušit
Nejlepší odpověď

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

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
kvě 24
2565
1
lis 22
4903
2
kvě 18
9810
2
čvc 17
6752
5
čvc 15
6052