Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
3698 Vizualizări

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





Imagine profil
Abandonează
Autor Cel mai bun răspuns

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


Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
mai 24
2613
1
nov. 22
4978
2
mai 18
9844
2
iul. 17
6805
5
iul. 15
6074