Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
3641 Weergaven

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
Annuleer
Auteur Beste antwoord

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
Annuleer
Beste antwoord

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

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
mei 24
2573
1
nov. 22
4915
2
mei 18
9818
2
jul. 17
6758
5
jul. 15
6059